From 3bb3630a362440c8016bfed043d36068215041b2 Mon Sep 17 00:00:00 2001 From: Latif Khalifa Date: Wed, 17 Mar 2010 14:00:36 +0000 Subject: [PATCH] Converted AssetManager to the new event model. git-svn-id: http://libopenmetaverse.googlecode.com/svn/libopenmetaverse/trunk@3286 52acb1d6-8a22-11de-b505-999d5b087335 --- OpenMetaverse/AssetManager.cs | 331 +++++++++++++----- OpenMetaverse/InventoryManager.cs | 14 +- Programs/PrimWorkshop/frmBrowser.cs | 39 +-- .../Commands/Estate/DownloadTerrainCommand.cs | 35 +- .../Estate/UploadRawTerrainCommand.cs | 13 +- .../Commands/Inventory/XferCommand.cs | 14 +- 6 files changed, 294 insertions(+), 152 deletions(-) diff --git a/OpenMetaverse/AssetManager.cs b/OpenMetaverse/AssetManager.cs index ab6bc4da..44f4ee4f 100644 --- a/OpenMetaverse/AssetManager.cs +++ b/OpenMetaverse/AssetManager.cs @@ -282,7 +282,7 @@ namespace OpenMetaverse Priority = priority; DiscardLevel = discardLevel; } - + } #endregion Transfer Classes @@ -295,61 +295,147 @@ namespace OpenMetaverse const int TRANSFER_HEADER_TIMEOUT = 1000 * 15; #region Delegates - /// - /// + /// Callback used for various asset download requests /// - /// - /// + /// Transfer information + /// Downloaded asset, null on fail public delegate void AssetReceivedCallback(AssetDownload transfer, Asset asset); /// - /// + /// Callback used upon competition of baked texture upload /// - /// - public delegate void XferReceivedCallback(XferDownload xfer); - /// - /// - /// - /// - public delegate void AssetUploadedCallback(AssetUpload upload); - /// - /// - /// - /// + /// Asset UUID of the newly uploaded baked texture public delegate void BakedTextureUploadedCallback(UUID newAssetID); - /// - /// - /// - /// - public delegate void UploadProgressCallback(AssetUpload upload); - /// - /// Callback fired when an InitiateDownload packet is received - /// - /// The filename on the simulator - /// The name of the file the viewer requested - public delegate void InitiateDownloadCallback(string simFilename, string viewerFilename); - /// - /// Fired when a texture is in the process of being downloaded by the TexturePipeline class - /// - /// The asset textures - /// The total number of bytes received - /// The total number of bytes expected - public delegate void ImageReceiveProgressCallback(UUID imageID, int recieved, int total); - + #endregion Delegates #region Events - /// - public event XferReceivedCallback OnXferReceived; - /// - public event AssetUploadedCallback OnAssetUploaded; - /// - public event UploadProgressCallback OnUploadProgress; + #region XferReceived + /// The event subscribers. null if no subcribers + private EventHandler m_XferReceivedEvent; + + /// Raises the XferReceived event + /// A XferReceivedEventArgs object containing the + /// data returned from the simulator + protected virtual void OnXferReceived(XferReceivedEventArgs e) + { + EventHandler handler = m_XferReceivedEvent; + if (handler != null) + handler(this, e); + } + + /// Thread sync lock object + private readonly object m_XferReceivedLock = new object(); + + /// Raised when the simulator responds sends + public event EventHandler XferReceived + { + add { lock (m_XferReceivedLock) { m_XferReceivedEvent += value; } } + remove { lock (m_XferReceivedLock) { m_XferReceivedEvent -= value; } } + } + #endregion + + #region AssetUploaded + /// The event subscribers. null if no subcribers + private EventHandler m_AssetUploadedEvent; + + /// Raises the AssetUploaded event + /// A AssetUploadedEventArgs object containing the + /// data returned from the simulator + protected virtual void OnAssetUploaded(AssetUploadEventArgs e) + { + EventHandler handler = m_AssetUploadedEvent; + if (handler != null) + handler(this, e); + } + + /// Thread sync lock object + private readonly object m_AssetUploadedLock = new object(); + + /// Raised during upload completes + public event EventHandler AssetUploaded + { + add { lock (m_AssetUploadedLock) { m_AssetUploadedEvent += value; } } + remove { lock (m_AssetUploadedLock) { m_AssetUploadedEvent -= value; } } + } + #endregion + + #region UploadProgress + /// The event subscribers. null if no subcribers + private EventHandler m_UploadProgressEvent; + + /// Raises the UploadProgress event + /// A UploadProgressEventArgs object containing the + /// data returned from the simulator + protected virtual void OnUploadProgress(AssetUploadEventArgs e) + { + EventHandler handler = m_UploadProgressEvent; + if (handler != null) + handler(this, e); + } + + /// Thread sync lock object + private readonly object m_UploadProgressLock = new object(); + + /// Raised during upload with progres update + public event EventHandler UploadProgress + { + add { lock (m_UploadProgressLock) { m_UploadProgressEvent += value; } } + remove { lock (m_UploadProgressLock) { m_UploadProgressEvent -= value; } } + } + #endregion UploadProgress + + #region InitiateDownload + /// The event subscribers. null if no subcribers + private EventHandler m_InitiateDownloadEvent; + + /// Raises the InitiateDownload event + /// A InitiateDownloadEventArgs object containing the + /// data returned from the simulator + protected virtual void OnInitiateDownload(InitiateDownloadEventArgs e) + { + EventHandler handler = m_InitiateDownloadEvent; + if (handler != null) + handler(this, e); + } + + /// Thread sync lock object + private readonly object m_InitiateDownloadLock = new object(); + /// Fired when the simulator sends an InitiateDownloadPacket, used to download terrain .raw files - public event InitiateDownloadCallback OnInitiateDownload; - /// Fired when during texture downloads to indicate the progress of the download - public event ImageReceiveProgressCallback OnImageRecieveProgress; + public event EventHandler InitiateDownload + { + add { lock (m_InitiateDownloadLock) { m_InitiateDownloadEvent += value; } } + remove { lock (m_InitiateDownloadLock) { m_InitiateDownloadEvent -= value; } } + } + #endregion InitiateDownload + + #region ImageReceiveProgress + /// The event subscribers. null if no subcribers + private EventHandler m_ImageReceiveProgressEvent; + + /// Raises the ImageReceiveProgress event + /// A ImageReceiveProgressEventArgs object containing the + /// data returned from the simulator + protected virtual void OnImageReceiveProgress(ImageReceiveProgressEventArgs e) + { + EventHandler handler = m_ImageReceiveProgressEvent; + if (handler != null) + handler(this, e); + } + + /// Thread sync lock object + private readonly object m_ImageReceiveProgressLock = new object(); + + /// Fired when a texture is in the process of being downloaded by the TexturePipeline class + public event EventHandler ImageReceiveProgress + { + add { lock (m_ImageReceiveProgressLock) { m_ImageReceiveProgressEvent += value; } } + remove { lock (m_ImageReceiveProgressLock) { m_ImageReceiveProgressEvent -= value; } } + } + #endregion ImageReceiveProgress + #endregion Events /// Texture download cache @@ -364,7 +450,7 @@ namespace OpenMetaverse private AssetUpload PendingUpload; private object PendingUploadLock = new object(); private volatile bool WaitingForUploadConfirm = false; - + /// /// Default constructor /// @@ -392,7 +478,7 @@ namespace OpenMetaverse Client.Network.RegisterCallback(PacketType.InitiateDownload, InitiateDownloadPacketHandler); } - + /// /// Request an asset download /// @@ -557,7 +643,7 @@ namespace OpenMetaverse try { callback(transfer, asset); } catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); } - + return; } @@ -600,7 +686,7 @@ namespace OpenMetaverse /// An AssetUpload object containing the data to upload to the simulator internal void SetPendingAssetUploadData(AssetUpload assetData) { - lock(PendingUploadLock) + lock (PendingUploadLock) PendingUpload = assetData; } @@ -622,7 +708,7 @@ namespace OpenMetaverse asset.AssetID = assetID; return transferID; } - + /// /// Request an asset be uploaded to the simulator /// @@ -649,10 +735,10 @@ namespace OpenMetaverse /// The of the transfer, can be used to correlate the upload with /// events being fired public UUID RequestUpload(out UUID assetID, AssetType type, byte[] data, bool storeLocal) - { - return RequestUpload(out assetID, type, data, storeLocal, UUID.Random()); - } - + { + return RequestUpload(out assetID, type, data, storeLocal, UUID.Random()); + } + /// /// Initiate an asset upload /// @@ -673,8 +759,8 @@ namespace OpenMetaverse upload.AssetID = assetID; upload.Size = data.Length; upload.XferID = 0; - upload.ID = transactionID; - + upload.ID = transactionID; + // Build and send the upload packet AssetUploadRequestPacket request = new AssetUploadRequestPacket(); request.AssetBlock.StoreLocal = storeLocal; @@ -688,8 +774,8 @@ namespace OpenMetaverse String.Format("Beginning asset upload [Single Packet], ID: {0}, AssetID: {1}, Size: {2}", upload.ID.ToString(), upload.AssetID.ToString(), upload.Size), Helpers.LogLevel.Info, Client); - Transfers[upload.ID]=upload; - + Transfers[upload.ID] = upload; + // The whole asset will fit in this packet, makes things easy request.AssetBlock.AssetData = data; upload.Transferred = data.Length; @@ -798,17 +884,17 @@ namespace OpenMetaverse UUID transactionID = UUID.Random(); BakedTextureUploadedCallback uploadCallback = (BakedTextureUploadedCallback)o; AutoResetEvent uploadEvent = new AutoResetEvent(false); - AssetUploadedCallback udpCallback = - delegate(AssetUpload upload) + EventHandler udpCallback = + delegate(object sender, AssetUploadEventArgs e) { - if (upload.ID == transactionID) + if (e.Upload.ID == transactionID) { uploadEvent.Set(); - uploadCallback(upload.Success ? upload.AssetID : UUID.Zero); + uploadCallback(e.Upload.Success ? e.Upload.AssetID : UUID.Zero); } }; - OnAssetUploaded += udpCallback; + AssetUploaded += udpCallback; UUID assetID; bool success; @@ -823,7 +909,7 @@ namespace OpenMetaverse success = false; } - OnAssetUploaded -= udpCallback; + AssetUploaded -= udpCallback; if (!success) uploadCallback(UUID.Zero); @@ -902,9 +988,9 @@ namespace OpenMetaverse /// } /// /// - public void RequestImage(UUID textureID, ImageType imageType, float priority, int discardLevel, + public void RequestImage(UUID textureID, ImageType imageType, float priority, int discardLevel, uint packetStart, TextureDownloadCallback callback, bool progress) - { + { Texture.RequestTexture(textureID, imageType, priority, discardLevel, packetStart, callback, progress); } @@ -968,11 +1054,8 @@ namespace OpenMetaverse /// the total number of bytes expected internal void FireImageProgressEvent(UUID texureID, int transferredBytes, int totalBytes) { - if (OnImageRecieveProgress != null) - { - try { OnImageRecieveProgress(texureID, transferredBytes, totalBytes); } - catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); } - } + try { OnImageReceiveProgress(new ImageReceiveProgressEventArgs(texureID, transferredBytes, totalBytes)); } + catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); } } #region Helpers @@ -1266,13 +1349,13 @@ namespace OpenMetaverse /// The EventArgs object containing the packet data protected void InitiateDownloadPacketHandler(object sender, PacketReceivedEventArgs e) { - if (OnInitiateDownload != null) + InitiateDownloadPacket request = (InitiateDownloadPacket)e.Packet; + try { - InitiateDownloadPacket request = (InitiateDownloadPacket)e.Packet; - try { OnInitiateDownload(Utils.BytesToString(request.FileData.SimFilename), - Utils.BytesToString(request.FileData.ViewerFilename)); } - catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); } - } + OnInitiateDownload(new InitiateDownloadEventArgs(Utils.BytesToString(request.FileData.SimFilename), + Utils.BytesToString(request.FileData.ViewerFilename))); + } + catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); } } /// Process an incoming packet and raise the appropriate events @@ -1320,11 +1403,8 @@ namespace OpenMetaverse //Client.DebugLog(String.Format("ACK for upload {0} of asset type {1} ({2}/{3})", // upload.AssetID.ToString(), upload.Type, upload.Transferred, upload.Size)); - if (OnUploadProgress != null) - { - try { OnUploadProgress(upload); } - catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); } - } + try { OnUploadProgress(new AssetUploadEventArgs(upload)); } + catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); } if (upload.Transferred < upload.Size) SendNextUploadPacket(upload); @@ -1342,7 +1422,7 @@ namespace OpenMetaverse // will never be called so we need to set this here as well WaitingForUploadConfirm = false; - if (OnAssetUploaded != null) + if (m_AssetUploadedEvent != null) { bool found = false; KeyValuePair foundTransfer = new KeyValuePair(); @@ -1372,7 +1452,7 @@ namespace OpenMetaverse { lock (Transfers) Transfers.Remove(foundTransfer.Key); - try { OnAssetUploaded((AssetUpload)foundTransfer.Value); } + try { OnAssetUploaded(new AssetUploadEventArgs((AssetUpload)foundTransfer.Value)); } catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); } } else @@ -1459,11 +1539,8 @@ namespace OpenMetaverse download.Success = true; lock (Transfers) Transfers.Remove(download.ID); - if (OnXferReceived != null) - { - try { OnXferReceived(download); } - catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); } - } + try { OnXferReceived(new XferReceivedEventArgs(download)); } + catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); } } } } @@ -1489,16 +1566,88 @@ namespace OpenMetaverse } } - if (download != null && OnXferReceived != null) + if (download != null && m_XferReceivedEvent != null) { download.Success = false; download.Error = (TransferError)abort.XferID.Result; - try { OnXferReceived(download); } + try { OnXferReceived(new XferReceivedEventArgs(download)); } catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); } } } #endregion Xfer Callbacks } + #region EventArg classes + // Provides data for XferReceived event + public class XferReceivedEventArgs : EventArgs + { + private readonly XferDownload m_Xfer; + + /// Xfer data + public XferDownload Xfer { get { return m_Xfer; } } + + public XferReceivedEventArgs(XferDownload xfer) + { + this.m_Xfer = xfer; + } + } + + // Provides data for AssetUploaded event + public class AssetUploadEventArgs : EventArgs + { + private readonly AssetUpload m_Upload; + + /// Upload data + public AssetUpload Upload { get { return m_Upload; } } + + public AssetUploadEventArgs(AssetUpload upload) + { + this.m_Upload = upload; + } + } + + // Provides data for InitiateDownloaded event + public class InitiateDownloadEventArgs : EventArgs + { + private readonly string m_SimFileName; + private readonly string m_ViewerFileName; + + /// Filename used on the simulator + public string SimFileName { get { return m_SimFileName; } } + + /// Filename used by the client + public string ViewerFileName { get { return m_ViewerFileName; } } + + public InitiateDownloadEventArgs(string simFilename, string viewerFilename) + { + this.m_SimFileName = simFilename; + this.m_ViewerFileName = viewerFilename; + } + } + + // Provides data for ImageReceiveProgress event + public class ImageReceiveProgressEventArgs : EventArgs + { + private readonly UUID m_ImageID; + private readonly int m_Received; + private readonly int m_Total; + + /// UUID of the image that is in progress + public UUID ImageID { get { return m_ImageID; } } + + /// Number of bytes received so far + public int Received { get { return m_Received; } } + + /// Image size in bytes + public int Total { get { return m_Total; } } + + public ImageReceiveProgressEventArgs(UUID imageID, int received, int total) + { + this.m_ImageID = imageID; + this.m_Received = received; + this.m_Total = total; + } + } + #endregion } diff --git a/OpenMetaverse/InventoryManager.cs b/OpenMetaverse/InventoryManager.cs index 428753a3..6fa41ffc 100644 --- a/OpenMetaverse/InventoryManager.cs +++ b/OpenMetaverse/InventoryManager.cs @@ -2839,24 +2839,24 @@ namespace OpenMetaverse ulong xferID = 0; AutoResetEvent taskDownloadEvent = new AutoResetEvent(false); - AssetManager.XferReceivedCallback xferCallback = - delegate(XferDownload xfer) + EventHandler xferCallback = + delegate(object sender, XferReceivedEventArgs e) { - if (xfer.XferID == xferID) + if (e.Xfer.XferID == xferID) { - assetData = xfer.AssetData; + assetData = e.Xfer.AssetData; taskDownloadEvent.Set(); } }; - Client.Assets.OnXferReceived += xferCallback; + Client.Assets.XferReceived += 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; + Client.Assets.XferReceived -= xferCallback; String taskList = Utils.BytesToString(assetData); return ParseTaskInventory(taskList); @@ -2864,7 +2864,7 @@ namespace OpenMetaverse else { Logger.Log("Timed out waiting for task inventory download for " + filename, Helpers.LogLevel.Warning, Client); - Client.Assets.OnXferReceived -= xferCallback; + Client.Assets.XferReceived -= xferCallback; return null; } } diff --git a/Programs/PrimWorkshop/frmBrowser.cs b/Programs/PrimWorkshop/frmBrowser.cs index 63022938..bfb97ef8 100644 --- a/Programs/PrimWorkshop/frmBrowser.cs +++ b/Programs/PrimWorkshop/frmBrowser.cs @@ -160,12 +160,11 @@ namespace PrimWorkshop Client.Network.LoginProgress += Network_OnLogin; Client.Network.Disconnected += Network_OnDisconnected; Client.Network.SimChanged += Network_OnCurrentSimChanged; - Client.Network.EventQueueRunning += Network_OnEventQueueRunning; + Client.Network.EventQueueRunning += Network_OnEventQueueRunning; Client.Objects.ObjectUpdate += Objects_OnNewPrim; Client.Terrain.LandPatchReceived += new EventHandler(Terrain_LandPatchReceived); Client.Parcels.SimParcelsDownloaded += new EventHandler(Parcels_SimParcelsDownloaded); - - Client.Assets.OnImageRecieveProgress += new AssetManager.ImageReceiveProgressCallback(Assets_OnImageRecieveProgress); + Client.Assets.ImageReceiveProgress += new EventHandler(Assets_ImageReceiveProgress); // Initialize the camera object InitCamera(); @@ -317,7 +316,7 @@ namespace PrimWorkshop // Build a list of primitives (parent+children) to export List primList = new List(); primList.Add(parent.Prim); - + lock (RenderPrimList) { foreach (RenderablePrim render in RenderPrimList.Values) @@ -351,7 +350,7 @@ namespace PrimWorkshop List textureList = new List(); prims = 0; textures = 0; - + // Write the LLSD to the hard drive in XML format string output = OSDParser.SerializeLLSDXmlString(Helpers.PrimListToOSD(primList)); try @@ -992,7 +991,7 @@ namespace PrimWorkshop // Texture for this face if (teFace.TextureID != UUID.Zero && teFace.TextureID != Primitive.TextureEntry.WHITE_TEXTURE) - { + { lock (Textures) { if (!Textures.ContainsKey(teFace.TextureID)) @@ -1058,7 +1057,7 @@ namespace PrimWorkshop private void Network_OnCurrentSimChanged(object sender, SimChangedEventArgs e) { Console.WriteLine("CurrentSim set to " + Client.Network.CurrentSim + ", downloading parcel information"); - + BeginInvoke((MethodInvoker)delegate() { txtSim.Text = Client.Network.CurrentSim.Name; }); //InitHeightmap(); @@ -1261,7 +1260,7 @@ namespace PrimWorkshop Gl.glDisable(Gl.GL_BLEND); Gl.glEnable(Gl.GL_DEPTH_TEST); -StartRender: + StartRender: foreach (RenderablePrim render in RenderPrimList.Values) { @@ -1398,7 +1397,7 @@ StartRender: Gl.glPopMatrix(); } ); - + Gl.glColor3f(1f, 1f, 1f); } } @@ -1410,7 +1409,7 @@ StartRender: bool alpha = false; ManagedImage imgData = null; byte[] raw = null; - + bool success = (state == TextureRequestState.Finished); UUID id = asset.AssetID; @@ -1497,21 +1496,21 @@ StartRender: Console.WriteLine(ex); } } - - private void Assets_OnImageRecieveProgress(UUID imageID, int recieved, int total) + + private void Assets_ImageReceiveProgress(object sender, ImageReceiveProgressEventArgs e) { lock (DownloadList) { GlacialComponents.Controls.GLItem item; - if (DownloadList.TryGetValue(imageID, out item)) + if (DownloadList.TryGetValue(e.ImageID, out item)) { // Update an existing item BeginInvoke( (MethodInvoker)delegate() { ProgressBar prog = (ProgressBar)item.SubItems[1].Control; - if (total >= recieved) - prog.Value = (int)Math.Round((((double)recieved / (double)total) * 100.0d)); + if (e.Total >= e.Received) + prog.Value = (int)Math.Round((((double)e.Received / (double)e.Total) * 100.0d)); }); } else @@ -1520,17 +1519,17 @@ StartRender: ProgressBar prog = new ProgressBar(); prog.Minimum = 0; prog.Maximum = 100; - if (total >= recieved) - prog.Value = (int)Math.Round((((double)recieved / (double)total) * 100.0d)); + if (e.Total >= e.Received) + prog.Value = (int)Math.Round((((double)e.Received / (double)e.Total) * 100.0d)); else prog.Value = 0; // List item item = new GlacialComponents.Controls.GLItem(); - item.SubItems[0].Text = imageID.ToString(); + item.SubItems[0].Text = e.ImageID.ToString(); item.SubItems[1].Control = prog; - DownloadList[imageID] = item; + DownloadList[e.ImageID] = item; BeginInvoke( (MethodInvoker)delegate() @@ -1673,7 +1672,7 @@ StartRender: { if (Pivoting) { - float a,x,y,z; + float a, x, y, z; Control control = (Control)sender; Point mouse = control.PointToScreen(new Point(e.X, e.Y)); diff --git a/Programs/examples/TestClient/Commands/Estate/DownloadTerrainCommand.cs b/Programs/examples/TestClient/Commands/Estate/DownloadTerrainCommand.cs index e594bb36..019e2105 100644 --- a/Programs/examples/TestClient/Commands/Estate/DownloadTerrainCommand.cs +++ b/Programs/examples/TestClient/Commands/Estate/DownloadTerrainCommand.cs @@ -17,7 +17,7 @@ namespace OpenMetaverse.TestClient /// Create a Synchronization event object /// private static AutoResetEvent xferTimeout = new AutoResetEvent(false); - + /// A string we use to report the result of the request with. 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 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(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 parameters = new List(); @@ -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(Assets_XferReceived); // return the result return result.ToString(); @@ -84,23 +85,21 @@ namespace OpenMetaverse.TestClient /// /// Handle the reply to the OnXferReceived event /// - /// - 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(); - } } } diff --git a/Programs/examples/TestClient/Commands/Estate/UploadRawTerrainCommand.cs b/Programs/examples/TestClient/Commands/Estate/UploadRawTerrainCommand.cs index 904c0c63..7a0be306 100644 --- a/Programs/examples/TestClient/Commands/Estate/UploadRawTerrainCommand.cs +++ b/Programs/examples/TestClient/Commands/Estate/UploadRawTerrainCommand.cs @@ -33,8 +33,7 @@ namespace OpenMetaverse.TestClient // Setup callbacks for upload request reply and progress indicator // so we can detect when the upload is complete - Client.Assets.OnUploadProgress += new AssetManager.UploadProgressCallback(Assets_OnUploadProgress); - + Client.Assets.UploadProgress += new EventHandler(Assets_UploadProgress); byte[] fileData = File.ReadAllBytes(fileName); Client.Estate.UploadTerrain(fileData, fileName); @@ -57,17 +56,13 @@ namespace OpenMetaverse.TestClient /// private void Cleanup() { - Client.Assets.OnUploadProgress -= new AssetManager.UploadProgressCallback(Assets_OnUploadProgress); + Client.Assets.UploadProgress -= new EventHandler(Assets_UploadProgress); } - /// - /// - /// - /// - void Assets_OnUploadProgress(AssetUpload upload) + void Assets_UploadProgress(object sender, AssetUploadEventArgs e) { - if (upload.Transferred == upload.Size) + if (e.Upload.Transferred == e.Upload.Size) { WaitForUploadComplete.Set(); } diff --git a/Programs/examples/TestClient/Commands/Inventory/XferCommand.cs b/Programs/examples/TestClient/Commands/Inventory/XferCommand.cs index c5d0a55d..50292758 100644 --- a/Programs/examples/TestClient/Commands/Inventory/XferCommand.cs +++ b/Programs/examples/TestClient/Commands/Inventory/XferCommand.cs @@ -52,25 +52,25 @@ namespace OpenMetaverse.TestClient ulong xferID = 0; byte[] data = null; - AssetManager.XferReceivedCallback xferCallback = - delegate(XferDownload xfer) + EventHandler xferCallback = + delegate(object sender, XferReceivedEventArgs e) { - if (xfer.XferID == xferID) + if (e.Xfer.XferID == xferID) { - if (xfer.Success) - data = xfer.AssetData; + if (e.Xfer.Success) + data = e.Xfer.AssetData; xferEvent.Set(); } }; - Client.Assets.OnXferReceived += xferCallback; + Client.Assets.XferReceived += xferCallback; filename = assetID + ".asset"; xferID = Client.Assets.RequestAssetXfer(filename, false, true, assetID, type, false); xferEvent.WaitOne(FETCH_ASSET_TIMEOUT, false); - Client.Assets.OnXferReceived -= xferCallback; + Client.Assets.XferReceived -= xferCallback; return data; }