2009-10-07 20:13:33 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
namespace OpenMetaverse.TestClient.Commands
|
|
|
|
|
|
{
|
|
|
|
|
|
class SearchClassifiedsCommand : Command
|
|
|
|
|
|
{
|
2009-10-16 02:53:53 +00:00
|
|
|
|
System.Threading.AutoResetEvent waitQuery = new System.Threading.AutoResetEvent(false);
|
2009-10-07 20:13:33 +00:00
|
|
|
|
|
|
|
|
|
|
public SearchClassifiedsCommand(TestClient testClient)
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "searchclassifieds";
|
|
|
|
|
|
Description = "Searches Classified Ads. Usage: searchclassifieds [search text]";
|
|
|
|
|
|
Category = CommandCategory.Other;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override string Execute(string[] args, UUID fromAgentID)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (args.Length < 1)
|
|
|
|
|
|
return "Usage: searchclassifieds [search text]";
|
|
|
|
|
|
|
|
|
|
|
|
string searchText = string.Empty;
|
|
|
|
|
|
for (int i = 0; i < args.Length; i++)
|
|
|
|
|
|
searchText += args[i] + " ";
|
|
|
|
|
|
searchText = searchText.TrimEnd();
|
|
|
|
|
|
waitQuery.Reset();
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder result = new StringBuilder();
|
2009-10-10 06:38:07 +00:00
|
|
|
|
|
|
|
|
|
|
EventHandler<DirClassifiedsReplyEventArgs> callback = delegate(object sender, DirClassifiedsReplyEventArgs e)
|
2009-10-07 20:13:33 +00:00
|
|
|
|
{
|
|
|
|
|
|
result.AppendFormat("Your search string '{0}' returned {1} classified ads" + System.Environment.NewLine,
|
2009-10-10 06:38:07 +00:00
|
|
|
|
searchText, e.Classifieds.Count);
|
|
|
|
|
|
foreach (DirectoryManager.Classified ad in e.Classifieds)
|
2009-10-07 20:13:33 +00:00
|
|
|
|
{
|
|
|
|
|
|
result.AppendLine(ad.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// classifieds are sent 16 ads at a time
|
2009-10-10 06:38:07 +00:00
|
|
|
|
if (e.Classifieds.Count < 16)
|
2009-10-07 20:13:33 +00:00
|
|
|
|
{
|
|
|
|
|
|
waitQuery.Set();
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2009-10-10 06:38:07 +00:00
|
|
|
|
Client.Directory.DirClassifiedsReply += callback;
|
2009-10-07 20:13:33 +00:00
|
|
|
|
|
|
|
|
|
|
UUID searchID = Client.Directory.StartClassifiedSearch(searchText, DirectoryManager.ClassifiedCategories.Any, DirectoryManager.ClassifiedQueryFlags.Mature | DirectoryManager.ClassifiedQueryFlags.PG);
|
|
|
|
|
|
|
|
|
|
|
|
if (!waitQuery.WaitOne(20000, false) && Client.Network.Connected)
|
|
|
|
|
|
{
|
|
|
|
|
|
result.AppendLine("Timeout waiting for simulator to respond to query.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-10-10 06:38:07 +00:00
|
|
|
|
Client.Directory.DirClassifiedsReply -= callback;
|
2009-10-07 20:13:33 +00:00
|
|
|
|
|
|
|
|
|
|
return result.ToString();
|
2009-10-10 06:38:07 +00:00
|
|
|
|
}
|
2009-10-07 20:13:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|