From 3d2ef508716cedac642ae92a11c9bc98c62004c2 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Fri, 10 Jul 2009 17:31:57 +0000 Subject: [PATCH] * Catch an ObjectDisposedException for the AckTimer * Added item embedding support to createnotecard, which is currently not working. Any help getting this working would be appreciated git-svn-id: http://libopenmetaverse.googlecode.com/svn/libopenmetaverse/trunk@2963 52acb1d6-8a22-11de-b505-999d5b087335 --- OpenMetaverse/Simulator.cs | 5 +- .../Inventory/CreateNotecardCommand.cs | 81 ++++++++++++++----- 2 files changed, 62 insertions(+), 24 deletions(-) diff --git a/OpenMetaverse/Simulator.cs b/OpenMetaverse/Simulator.cs index d8d54fef..e8936521 100644 --- a/OpenMetaverse/Simulator.cs +++ b/OpenMetaverse/Simulator.cs @@ -1070,9 +1070,8 @@ namespace OpenMetaverse ResendUnacked(); // Start the ACK handling functions again after NETWORK_TICK_INTERVAL milliseconds - Timer timer = AckTimer; - if (timer != null) - timer.Change(Settings.NETWORK_TICK_INTERVAL, Timeout.Infinite); + try { AckTimer.Change(Settings.NETWORK_TICK_INTERVAL, Timeout.Infinite); } + catch (ObjectDisposedException) { } } private void StatsTimer_Elapsed(object obj) diff --git a/Programs/examples/TestClient/Commands/Inventory/CreateNotecardCommand.cs b/Programs/examples/TestClient/Commands/Inventory/CreateNotecardCommand.cs index ba06a7ee..5425a13c 100644 --- a/Programs/examples/TestClient/Commands/Inventory/CreateNotecardCommand.cs +++ b/Programs/examples/TestClient/Commands/Inventory/CreateNotecardCommand.cs @@ -10,48 +10,64 @@ namespace OpenMetaverse.TestClient { public class CreateNotecardCommand : Command { - const int NOTECARD_CREATE_TIMEOUT = 10 * 1000; - const int NOTECARD_FETCH_TIMEOUT = 10 * 1000; + const int NOTECARD_CREATE_TIMEOUT = 1000 * 10; + const int NOTECARD_FETCH_TIMEOUT = 1000 * 10; + const int INVENTORY_FETCH_TIMEOUT = 1000 * 10; public CreateNotecardCommand(TestClient testClient) { Name = "createnotecard"; - Description = "Creates a notecard from a local text file."; + Description = "Creates a notecard from a local text file and optionally embed an inventory item. Usage: createnotecard filename.txt [itemid]"; Category = CommandCategory.Inventory; } public override string Execute(string[] args, UUID fromAgentID) { - if (args.Length < 1) - return "Usage: createnotecard filename.txt"; - - UUID notecardItemID = UUID.Zero, notecardAssetID = UUID.Zero; + UUID embedItemID = UUID.Zero, notecardItemID = UUID.Zero, notecardAssetID = UUID.Zero; + string filename, fileData; bool success = false; string message = String.Empty; AutoResetEvent notecardEvent = new AutoResetEvent(false); - #region File Loading + if (args.Length == 1) + { + filename = args[0]; + } + else if (args.Length == 2) + { + filename = args[0]; + UUID.TryParse(args[1], out embedItemID); + } + else + { + return "Usage: createnotecard filename.txt"; + } - string file = String.Empty; - for (int ct = 0; ct < args.Length; ct++) - file = file + args[ct] + " "; - file = file.TrimEnd(); + if (!File.Exists(filename)) + return "File \"" + filename + "\" does not exist"; - if (!File.Exists(file)) - return String.Format("Filename '{0}' does not exist", file); - - StreamReader reader = new StreamReader(file); - string body = reader.ReadToEnd(); - - #endregion File Loading + try { fileData = File.ReadAllText(filename); } + catch (Exception ex) { return "Failed to open " + filename + ": " + ex.Message; } // Notecard creation AssetNotecard notecard = new AssetNotecard(); - notecard.BodyText = body; + notecard.BodyText = fileData; + + // Item embedding + if (embedItemID != UUID.Zero) + { + // Try to fetch the inventory item + InventoryItem item = FetchItem(embedItemID); + if (item != null) + notecard.EmbeddedItems = new List { item }; + else + return "Failed to fetch inventory item " + embedItemID; + } + notecard.Encode(); Client.Inventory.RequestCreateItem(Client.Inventory.FindFolderForType(AssetType.Notecard), - file, file + " created by OpenMetaverse TestClient " + DateTime.Now, AssetType.Notecard, + filename, filename + " created by OpenMetaverse TestClient " + DateTime.Now, AssetType.Notecard, UUID.Random(), InventoryType.Notecard, PermissionMask.All, delegate(bool createSuccess, InventoryItem item) { @@ -86,6 +102,29 @@ namespace OpenMetaverse.TestClient return "Notecard creation failed: " + message; } + InventoryItem FetchItem(UUID itemID) + { + InventoryItem fetchItem = null; + AutoResetEvent fetchItemEvent = new AutoResetEvent(false); + + InventoryManager.ItemReceivedCallback itemReceivedCallback = + delegate(InventoryItem item) + { + fetchItem = item; + fetchItemEvent.Set(); + }; + + Client.Inventory.OnItemReceived += itemReceivedCallback; + + Client.Inventory.RequestFetchInventory(itemID, Client.Self.AgentID); + + fetchItemEvent.WaitOne(INVENTORY_FETCH_TIMEOUT, false); + + Client.Inventory.OnItemReceived -= itemReceivedCallback; + + return fetchItem; + } + string DownloadNotecard(UUID itemID, UUID assetID) { UUID transferID = UUID.Zero;