From 5b103aab896eef4ca8d538d12728fdc1929e34d1 Mon Sep 17 00:00:00 2001 From: diva Date: Sun, 5 Apr 2009 22:39:19 +0000 Subject: Changed the asynchronous call to get inventory in HG, so that it properly reports problems. OGS1 should also be changed, but I'm leaving it as is for now. RestSessionObjectPosterResponse is fairly broken and should not be used. Minor changes in Get inventory item in HGAssetMapper. --- .../Communications/Hypergrid/HGInventoryService.cs | 68 ++++++++++++++++------ 1 file changed, 49 insertions(+), 19 deletions(-) (limited to 'OpenSim/Region/Communications/Hypergrid/HGInventoryService.cs') diff --git a/OpenSim/Region/Communications/Hypergrid/HGInventoryService.cs b/OpenSim/Region/Communications/Hypergrid/HGInventoryService.cs index a2b2c84..5e3f229 100644 --- a/OpenSim/Region/Communications/Hypergrid/HGInventoryService.cs +++ b/OpenSim/Region/Communications/Hypergrid/HGInventoryService.cs @@ -81,30 +81,22 @@ namespace OpenSim.Region.Communications.Hypergrid { m_RequestingInventory.Add(userID, callback); + string invServer = GetUserInventoryURI(userID); + m_log.InfoFormat( + "[HGrid INVENTORY SERVICE]: Requesting inventory from {0}/GetInventory/ for user {1} ({2})", + /*_inventoryServerUrl*/ invServer, userID, userID.Guid); + try { - string invServer = GetUserInventoryURI(userID); - m_log.InfoFormat( - "[HGrid INVENTORY SERVICE]: Requesting inventory from {0}/GetInventory/ for user {1} ({2})", - /*_inventoryServerUrl*/ invServer, userID, userID.Guid); - - - RestSessionObjectPosterResponse requester - = new RestSessionObjectPosterResponse(); - requester.ResponseCallback = InventoryResponse; - requester.BeginPostObject(invServer + "/GetInventory/", userID.Guid, session_id.ToString(), userID.ToString()); - - //Test(userID.Guid); - - //RestObjectPosterResponse requester - // = new RestObjectPosterResponse(); + //RestSessionObjectPosterResponse requester + // = new RestSessionObjectPosterResponse(); //requester.ResponseCallback = InventoryResponse; - //requester.BeginPostObject(/*_inventoryServerUrl*/ invServer + "/GetInventory/", userID.Guid); + //requester.BeginPostObject(invServer + "/GetInventory/", userID.Guid, session_id.ToString(), userID.ToString()); + GetInventoryDelegate d = GetInventoryAsync; + d.BeginInvoke(invServer, userID, session_id, GetInventoryCompleted, d); - //RestClient cli = new RestClient(invServer + "/GetInventory/" + userID.Guid); - //Stream reply = cli.Request(); } catch (WebException e) { @@ -133,6 +125,44 @@ namespace OpenSim.Region.Communications.Hypergrid } + private delegate InventoryCollection GetInventoryDelegate(string url, UUID userID, UUID sessionID); + + protected InventoryCollection GetInventoryAsync(string url, UUID userID, UUID sessionID) + { + InventoryCollection icol = null; + try + { + icol = SynchronousRestSessionObjectPoster.BeginPostObject("POST", url + "/GetInventory/", + userID.Guid, sessionID.ToString(), userID.ToString()); + + } + catch (Exception e) + { + m_log.Debug("[HGrid]: Exception getting users inventory: " + e.Message); + } + if (icol == null) + { + // Well, let's synthesize one + icol = new InventoryCollection(); + icol.UserID = userID; + icol.Items = new List(); + icol.Folders = new List(); + InventoryFolderBase rootFolder = new InventoryFolderBase(); + rootFolder.ID = UUID.Random(); + rootFolder.Owner = userID; + icol.Folders.Add(rootFolder); + } + + return icol; + } + + private void GetInventoryCompleted(IAsyncResult iar) + { + GetInventoryDelegate icon = (GetInventoryDelegate)iar.AsyncState; + InventoryCollection icol = icon.EndInvoke(iar); + InventoryResponse(icol); + } + /// /// Add a new folder to the user's inventory /// @@ -460,9 +490,9 @@ namespace OpenSim.Region.Communications.Hypergrid m_log.ErrorFormat("[HGrid INVENTORY SERVICE]: Did not get back an inventory containing a root folder for user {0}", userID); } + m_RequestingInventory.Remove(userID); callback(folders, items); - m_RequestingInventory.Remove(userID); } else { -- cgit v1.1