Converted AssetManager to the new event model.

git-svn-id: http://libopenmetaverse.googlecode.com/svn/libopenmetaverse/trunk@3286 52acb1d6-8a22-11de-b505-999d5b087335
This commit is contained in:
Latif Khalifa
2010-03-17 14:00:36 +00:00
parent 8a52b8fb52
commit 3bb3630a36
6 changed files with 294 additions and 152 deletions

View File

@@ -17,7 +17,7 @@ namespace OpenMetaverse.TestClient
/// Create a Synchronization event object
/// </summary>
private static AutoResetEvent xferTimeout = new AutoResetEvent(false);
/// <summary>A string we use to report the result of the request with.</summary>
private static System.Text.StringBuilder result = new System.Text.StringBuilder();
@@ -44,21 +44,22 @@ namespace OpenMetaverse.TestClient
{
int timeout = 120000; // default the timeout to 2 minutes
fileName = Client.Network.CurrentSim.Name + ".raw";
if(args.Length > 0 && int.TryParse(args[0], out timeout) != true)
if (args.Length > 0 && int.TryParse(args[0], out timeout) != true)
return "Usage: downloadterrain [timeout]";
// Create a delegate which will be fired when the simulator receives our download request
// Starts the actual transfer request
AssetManager.InitiateDownloadCallback initiateDownloadDelegate = delegate(string simFilename, string viewerFileName) {
Client.Assets.RequestAssetXfer(simFilename, false, false, UUID.Zero, AssetType.Unknown, false);
};
EventHandler<InitiateDownloadEventArgs> initiateDownloadDelegate =
delegate(object sender, InitiateDownloadEventArgs e)
{
Client.Assets.RequestAssetXfer(e.SimFileName, false, false, UUID.Zero, AssetType.Unknown, false);
};
// Subscribe to the event that will tell us the status of the download
Client.Assets.OnXferReceived += new AssetManager.XferReceivedCallback(Assets_OnXferReceived);
Client.Assets.XferReceived += new EventHandler<XferReceivedEventArgs>(Assets_XferReceived);
// subscribe to the event which tells us when the simulator has received our request
Client.Assets.OnInitiateDownload += initiateDownloadDelegate;
Client.Assets.InitiateDownload += initiateDownloadDelegate;
// configure request to tell the simulator to send us the file
List<string> parameters = new List<string>();
@@ -74,8 +75,8 @@ namespace OpenMetaverse.TestClient
}
// unsubscribe from events
Client.Assets.OnInitiateDownload -= initiateDownloadDelegate;
Client.Assets.OnXferReceived -= new AssetManager.XferReceivedCallback(Assets_OnXferReceived);
Client.Assets.InitiateDownload -= initiateDownloadDelegate;
Client.Assets.XferReceived -= new EventHandler<XferReceivedEventArgs>(Assets_XferReceived);
// return the result
return result.ToString();
@@ -84,23 +85,21 @@ namespace OpenMetaverse.TestClient
/// <summary>
/// Handle the reply to the OnXferReceived event
/// </summary>
/// <param name="xfer"></param>
private void Assets_OnXferReceived(XferDownload xfer)
private void Assets_XferReceived(object sender, XferReceivedEventArgs e)
{
if (xfer.Success)
if (e.Xfer.Success)
{
// set the result message
result.AppendFormat("Terrain file {0} ({1} bytes) downloaded successfully, written to {2}", xfer.Filename, xfer.Size, fileName);
result.AppendFormat("Terrain file {0} ({1} bytes) downloaded successfully, written to {2}", e.Xfer.Filename, e.Xfer.Size, fileName);
// write the file to disk
FileStream stream = new FileStream(fileName, FileMode.Create);
BinaryWriter w = new BinaryWriter(stream);
w.Write(xfer.AssetData);
w.Write(e.Xfer.AssetData);
w.Close();
// tell the application we've gotten the file
xferTimeout.Set();
}
}
}