public List<InventoryBase> GetTaskInventory(UUID objectID, uint objectLocalID, int timeoutMS)
{
string filename = null;
AutoResetEvent taskReplyEvent = new AutoResetEvent(false);
TaskInventoryReplyCallback callback =
delegate(UUID itemID, short serial, string assetFilename)
{
if (itemID == objectID)
{
filename = assetFilename;
taskReplyEvent.Set();
}
};
OnTaskInventoryReply += callback;
RequestTaskInventory(objectLocalID);
if (taskReplyEvent.WaitOne(timeoutMS, false))
{
OnTaskInventoryReply -= callback;
if (!String.IsNullOrEmpty(filename))
{
byte[] assetData = null;
ulong xferID = 0;
AutoResetEvent taskDownloadEvent = new AutoResetEvent(false);
AssetManager.XferReceivedCallback xferCallback =
delegate(XferDownload xfer)
{
if (xfer.XferID == xferID)
{
assetData = xfer.AssetData;
taskDownloadEvent.Set();
}
};
_Client.Assets.OnXferReceived += xferCallback;
// Start the actual asset xfer
xferID = _Client.Assets.RequestAssetXfer(filename, true, false, UUID.Zero, AssetType.Unknown, true);
if (taskDownloadEvent.WaitOne(timeoutMS, false))
{
_Client.Assets.OnXferReceived -= xferCallback;
string taskList = Utils.BytesToString(assetData);
return ParseTaskInventory(taskList);
}
else
{
Logger.Log("Timed out waiting for task inventory download for " + filename, Helpers.LogLevel.Warning, _Client);
_Client.Assets.OnXferReceived -= xferCallback;
return null;
}
}
else
{
Logger.DebugLog("Task is empty for " + objectLocalID, _Client);
return null;
}
}
else
{
Logger.Log("Timed out waiting for task inventory reply for " + objectLocalID, Helpers.LogLevel.Warning, _Client);
OnTaskInventoryReply -= callback;
return null;
}
}