* Many other code cleanups and example updates * BREAKING - this is a major shift in the way events are internally handled. git-svn-id: http://libopenmetaverse.googlecode.com/svn/libopenmetaverse/trunk@3145 52acb1d6-8a22-11de-b505-999d5b087335
62 lines
2.3 KiB
C#
62 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace OpenMetaverse.TestClient.Commands
|
|
{
|
|
class SearchClassifiedsCommand : Command
|
|
{
|
|
System.Threading.AutoResetEvent waitQuery = new System.Threading.AutoResetEvent(false);
|
|
|
|
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();
|
|
|
|
EventHandler<DirClassifiedsReplyEventArgs> callback = delegate(object sender, DirClassifiedsReplyEventArgs e)
|
|
{
|
|
result.AppendFormat("Your search string '{0}' returned {1} classified ads" + System.Environment.NewLine,
|
|
searchText, e.Classifieds.Count);
|
|
foreach (DirectoryManager.Classified ad in e.Classifieds)
|
|
{
|
|
result.AppendLine(ad.ToString());
|
|
}
|
|
|
|
// classifieds are sent 16 ads at a time
|
|
if (e.Classifieds.Count < 16)
|
|
{
|
|
waitQuery.Set();
|
|
}
|
|
};
|
|
|
|
Client.Directory.DirClassifiedsReply += callback;
|
|
|
|
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.");
|
|
}
|
|
|
|
Client.Directory.DirClassifiedsReply -= callback;
|
|
|
|
return result.ToString();
|
|
}
|
|
}
|
|
}
|