From 80609c2b1572d9b946675db486fc46e327171cfa Mon Sep 17 00:00:00 2001 From: MW Date: Sun, 2 Dec 2007 13:59:15 +0000 Subject: Some refactoring , mainly on Inventory code. --- .../Communications/Cache/InventoryFolder.cs | 146 --------------- .../Communications/Cache/InventoryFolderImpl.cs | 146 +++++++++++++++ .../Communications/Cache/LibraryRootFolder.cs | 152 ++++----------- .../Communications/Cache/UserProfileCache.cs | 203 --------------------- .../Cache/UserProfileCacheService.cs | 203 +++++++++++++++++++++ .../Communications/CommunicationsManager.cs | 6 +- OpenSim/Framework/Servers/RestObjectPoster.cs | 93 ---------- .../Framework/Servers/RestObjectPosterResponse.cs | 60 ++++++ .../Servers/SynchronousRestObjectPoster.cs | 48 +++++ 9 files changed, 495 insertions(+), 562 deletions(-) delete mode 100644 OpenSim/Framework/Communications/Cache/InventoryFolder.cs create mode 100644 OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs delete mode 100644 OpenSim/Framework/Communications/Cache/UserProfileCache.cs create mode 100644 OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs create mode 100644 OpenSim/Framework/Servers/RestObjectPosterResponse.cs create mode 100644 OpenSim/Framework/Servers/SynchronousRestObjectPoster.cs (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Communications/Cache/InventoryFolder.cs b/OpenSim/Framework/Communications/Cache/InventoryFolder.cs deleted file mode 100644 index fd029cd..0000000 --- a/OpenSim/Framework/Communications/Cache/InventoryFolder.cs +++ /dev/null @@ -1,146 +0,0 @@ -/* -* Copyright (c) Contributors, http://opensimulator.org/ -* See CONTRIBUTORS.TXT for a full list of copyright holders. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in the -* documentation and/or other materials provided with the distribution. -* * Neither the name of the OpenSim Project nor the -* names of its contributors may be used to endorse or promote products -* derived from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY -* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY -* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* -*/ -using System.Collections.Generic; -using libsecondlife; - -namespace OpenSim.Framework.Communications.Cache -{ - public class InventoryFolderImpl : InventoryFolderBase - { - // Fields - public Dictionary Items = new Dictionary(); - public Dictionary SubFolders = new Dictionary(); - - // Accessors - public int SubFoldersCount - { - get { return SubFolders.Count; } - } - - // Constructors - public InventoryFolderImpl(InventoryFolderBase folderbase) - { - agentID = folderbase.agentID; - folderID = folderbase.folderID; - name = folderbase.name; - parentID = folderbase.parentID; - type = folderbase.type; - version = folderbase.version; - } - - public InventoryFolderImpl() - { - } - - // Methods - public InventoryFolderImpl CreateNewSubFolder(LLUUID folderID, string folderName, ushort type) - { - if (!SubFolders.ContainsKey(folderID)) - { - InventoryFolderImpl subFold = new InventoryFolderImpl(); - subFold.name = folderName; - subFold.folderID = folderID; - subFold.type = (short)type; - subFold.parentID = this.folderID; - subFold.agentID = agentID; - SubFolders.Add(subFold.folderID, subFold); - return subFold; - } - return null; - } - - public InventoryItemBase HasItem(LLUUID itemID) - { - InventoryItemBase base2 = null; - if (Items.ContainsKey(itemID)) - { - return Items[itemID]; - } - foreach (InventoryFolderImpl folder in SubFolders.Values) - { - base2 = folder.HasItem(itemID); - if (base2 != null) - { - break; - } - } - return base2; - } - - public bool DeleteItem(LLUUID itemID) - { - bool found = false; - if (Items.ContainsKey(itemID)) - { - Items.Remove(itemID); - return true; - } - foreach (InventoryFolderImpl folder in SubFolders.Values) - { - found = folder.DeleteItem(itemID); - if (found == true) - { - break; - } - } - return found; - } - - - public InventoryFolderImpl HasSubFolder(LLUUID folderID) - { - InventoryFolderImpl returnFolder = null; - if (SubFolders.ContainsKey(folderID)) - { - returnFolder = SubFolders[folderID]; - } - else - { - foreach (InventoryFolderImpl folder in SubFolders.Values) - { - returnFolder = folder.HasSubFolder(folderID); - if (returnFolder != null) - { - break; - } - } - } - return returnFolder; - } - - public List RequestListOfItems() - { - List itemList = new List(); - foreach (InventoryItemBase item in Items.Values) - { - itemList.Add(item); - } - return itemList; - } - } -} diff --git a/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs new file mode 100644 index 0000000..fd029cd --- /dev/null +++ b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs @@ -0,0 +1,146 @@ +/* +* Copyright (c) Contributors, http://opensimulator.org/ +* See CONTRIBUTORS.TXT for a full list of copyright holders. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of the OpenSim Project nor the +* names of its contributors may be used to endorse or promote products +* derived from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY +* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ +using System.Collections.Generic; +using libsecondlife; + +namespace OpenSim.Framework.Communications.Cache +{ + public class InventoryFolderImpl : InventoryFolderBase + { + // Fields + public Dictionary Items = new Dictionary(); + public Dictionary SubFolders = new Dictionary(); + + // Accessors + public int SubFoldersCount + { + get { return SubFolders.Count; } + } + + // Constructors + public InventoryFolderImpl(InventoryFolderBase folderbase) + { + agentID = folderbase.agentID; + folderID = folderbase.folderID; + name = folderbase.name; + parentID = folderbase.parentID; + type = folderbase.type; + version = folderbase.version; + } + + public InventoryFolderImpl() + { + } + + // Methods + public InventoryFolderImpl CreateNewSubFolder(LLUUID folderID, string folderName, ushort type) + { + if (!SubFolders.ContainsKey(folderID)) + { + InventoryFolderImpl subFold = new InventoryFolderImpl(); + subFold.name = folderName; + subFold.folderID = folderID; + subFold.type = (short)type; + subFold.parentID = this.folderID; + subFold.agentID = agentID; + SubFolders.Add(subFold.folderID, subFold); + return subFold; + } + return null; + } + + public InventoryItemBase HasItem(LLUUID itemID) + { + InventoryItemBase base2 = null; + if (Items.ContainsKey(itemID)) + { + return Items[itemID]; + } + foreach (InventoryFolderImpl folder in SubFolders.Values) + { + base2 = folder.HasItem(itemID); + if (base2 != null) + { + break; + } + } + return base2; + } + + public bool DeleteItem(LLUUID itemID) + { + bool found = false; + if (Items.ContainsKey(itemID)) + { + Items.Remove(itemID); + return true; + } + foreach (InventoryFolderImpl folder in SubFolders.Values) + { + found = folder.DeleteItem(itemID); + if (found == true) + { + break; + } + } + return found; + } + + + public InventoryFolderImpl HasSubFolder(LLUUID folderID) + { + InventoryFolderImpl returnFolder = null; + if (SubFolders.ContainsKey(folderID)) + { + returnFolder = SubFolders[folderID]; + } + else + { + foreach (InventoryFolderImpl folder in SubFolders.Values) + { + returnFolder = folder.HasSubFolder(folderID); + if (returnFolder != null) + { + break; + } + } + } + return returnFolder; + } + + public List RequestListOfItems() + { + List itemList = new List(); + foreach (InventoryItemBase item in Items.Values) + { + itemList.Add(item); + } + return itemList; + } + } +} diff --git a/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs b/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs index 62251bc..33b4281 100644 --- a/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs +++ b/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs @@ -49,8 +49,8 @@ namespace OpenSim.Framework.Communications.Cache folderID = new LLUUID("00000112-000f-0000-0000-000100bba000"); name = "OpenSim Library"; parentID = LLUUID.Zero; - type = (short) -1; - version = (ushort) 1; + type = (short)-1; + version = (ushort)1; InventoryFolderImpl folderInfo = new InventoryFolderImpl(); folderInfo.agentID = libOwner; @@ -67,7 +67,7 @@ namespace OpenSim.Framework.Communications.Cache string filePath = Path.Combine(Util.configDir(), "OpenSimLibrary.xml"); if (File.Exists(filePath)) { - try + try { XmlConfigSource source = new XmlConfigSource(filePath); ReadItemsFromFile(source); @@ -81,143 +81,61 @@ namespace OpenSim.Framework.Communications.Cache private void CreateLibraryItems() { - InventoryItemBase item = new InventoryItemBase(); - item.avatarID = libOwner; - item.creatorsID = libOwner; - item.inventoryID = LLUUID.Random(); - item.assetID = new LLUUID("00000000-0000-0000-9999-000000000002"); - item.inventoryDescription = "Plywood texture"; - item.inventoryName = "Plywood"; - item.assetType = (int) AssetType.Texture; - item.invType = (int) InventoryType.Texture; - item.parentFolderID = m_textureFolder.folderID; - item.inventoryBasePermissions = 0x7FFFFFFF; - item.inventoryEveryOnePermissions = 0x7FFFFFFF; - item.inventoryCurrentPermissions = 0x7FFFFFFF; - item.inventoryNextPermissions = 0x7FFFFFFF; + InventoryItemBase item = CreateItem(LLUUID.Random(), new LLUUID("00000000-0000-0000-9999-000000000002"), "Plywood", "Plywood texture", (int)AssetType.Texture, (int)InventoryType.Texture, m_textureFolder.folderID); m_textureFolder.Items.Add(item.inventoryID, item); - item = new InventoryItemBase(); - item.avatarID = libOwner; - item.creatorsID = libOwner; - item.inventoryID = LLUUID.Random(); - item.assetID = new LLUUID("00000000-0000-0000-9999-000000000003"); - item.inventoryDescription = "Rocks texture"; - item.inventoryName = "Rocks"; - item.assetType = (int) AssetType.Texture; - item.invType = (int) InventoryType.Texture; - item.parentFolderID = m_textureFolder.folderID; - item.inventoryBasePermissions = 0x7FFFFFFF; - item.inventoryEveryOnePermissions = 0x7FFFFFFF; - item.inventoryCurrentPermissions = 0x7FFFFFFF; - item.inventoryNextPermissions = 0x7FFFFFFF; + item = CreateItem(LLUUID.Random(), new LLUUID("00000000-0000-0000-9999-000000000003"), "Rocks", "Rocks texture", (int)AssetType.Texture, (int)InventoryType.Texture, m_textureFolder.folderID); m_textureFolder.Items.Add(item.inventoryID, item); - item = new InventoryItemBase(); - item.avatarID = libOwner; - item.creatorsID = libOwner; - item.inventoryID = LLUUID.Random(); - item.assetID = new LLUUID("00000000-0000-0000-9999-000000000001"); - item.inventoryDescription = "Bricks texture"; - item.inventoryName = "Bricks"; - item.assetType = (int) AssetType.Texture; - item.invType = (int) InventoryType.Texture; - item.parentFolderID = m_textureFolder.folderID; - item.inventoryBasePermissions = 0x7FFFFFFF; - item.inventoryEveryOnePermissions = 0x7FFFFFFF; - item.inventoryCurrentPermissions = 0x7FFFFFFF; - item.inventoryNextPermissions = 0x7FFFFFFF; + item = CreateItem(LLUUID.Random(), new LLUUID("00000000-0000-0000-9999-000000000001"), "Bricks", "Bricks texture", (int)AssetType.Texture, (int)InventoryType.Texture, m_textureFolder.folderID); m_textureFolder.Items.Add(item.inventoryID, item); - item = new InventoryItemBase(); - item.avatarID = libOwner; - item.creatorsID = libOwner; - item.inventoryID = LLUUID.Random(); - item.assetID = new LLUUID("00000000-0000-0000-9999-000000000004"); - item.inventoryDescription = "Granite texture"; - item.inventoryName = "Granite"; - item.assetType = (int) AssetType.Texture; - item.invType = (int) InventoryType.Texture; - item.parentFolderID = m_textureFolder.folderID; - item.inventoryBasePermissions = 0x7FFFFFFF; - item.inventoryEveryOnePermissions = 0x7FFFFFFF; - item.inventoryCurrentPermissions = 0x7FFFFFFF; - item.inventoryNextPermissions = 0x7FFFFFFF; + item = CreateItem(LLUUID.Random(), new LLUUID("00000000-0000-0000-9999-000000000004"), "Granite", "Granite texture", (int)AssetType.Texture, (int)InventoryType.Texture, m_textureFolder.folderID); m_textureFolder.Items.Add(item.inventoryID, item); - item = new InventoryItemBase(); - item.avatarID = libOwner; - item.creatorsID = libOwner; - item.inventoryID = LLUUID.Random(); - item.assetID = new LLUUID("00000000-0000-0000-9999-000000000005"); - item.inventoryDescription = "Hardwood texture"; - item.inventoryName = "Hardwood"; - item.assetType = (int) AssetType.Texture; - item.invType = (int) InventoryType.Texture; - item.parentFolderID = m_textureFolder.folderID; - item.inventoryBasePermissions = 0x7FFFFFFF; - item.inventoryEveryOnePermissions = 0x7FFFFFFF; - item.inventoryCurrentPermissions = 0x7FFFFFFF; - item.inventoryNextPermissions = 0x7FFFFFFF; + item = CreateItem(LLUUID.Random(), new LLUUID("00000000-0000-0000-9999-000000000005"), "Hardwood", "Hardwood texture", (int)AssetType.Texture, (int)InventoryType.Texture, m_textureFolder.folderID); m_textureFolder.Items.Add(item.inventoryID, item); - item = new InventoryItemBase(); - item.avatarID = libOwner; - item.creatorsID = libOwner; - item.inventoryID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfaba9"); - item.assetID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73"); - item.inventoryDescription = "Default Shape"; - item.inventoryName = "Default Shape"; - item.assetType = (int) AssetType.Bodypart; - item.invType = (int) InventoryType.Wearable; - item.parentFolderID = folderID; + item = CreateItem(new LLUUID("66c41e39-38f9-f75a-024e-585989bfaba9"), new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73"), "Default Shape", "Default Shape", (int)AssetType.Bodypart, (int)InventoryType.Wearable, folderID); item.inventoryCurrentPermissions = 0; item.inventoryNextPermissions = 0; Items.Add(item.inventoryID, item); - item = new InventoryItemBase(); - item.avatarID = libOwner; - item.creatorsID = libOwner; - item.inventoryID = new LLUUID("77c41e39-38f9-f75a-024e-585989bfabc9"); - item.assetID = new LLUUID("77c41e39-38f9-f75a-024e-585989bbabbb"); - item.inventoryDescription = "Default Skin"; - item.inventoryName = "Default Skin"; - item.assetType = (int) AssetType.Bodypart; - item.invType = (int) InventoryType.Wearable; - item.parentFolderID = folderID; + item = CreateItem(new LLUUID("77c41e39-38f9-f75a-024e-585989bfabc9"), new LLUUID("77c41e39-38f9-f75a-024e-585989bbabbb"), "Default Skin", "Default Skin", (int)AssetType.Bodypart, (int)InventoryType.Wearable, folderID); item.inventoryCurrentPermissions = 0; item.inventoryNextPermissions = 0; Items.Add(item.inventoryID, item); - item = new InventoryItemBase(); - item.avatarID = libOwner; - item.creatorsID = libOwner; - item.inventoryID = new LLUUID("77c41e39-38f9-f75a-0000-585989bf0000"); - item.assetID = new LLUUID("00000000-38f9-1111-024e-222222111110"); - item.inventoryDescription = "Default Shirt"; - item.inventoryName = "Default Shirt"; - item.assetType = (int) AssetType.Clothing; - item.invType = (int) InventoryType.Wearable; - item.parentFolderID = folderID; + item = CreateItem(new LLUUID("77c41e39-38f9-f75a-0000-585989bf0000"), new LLUUID("00000000-38f9-1111-024e-222222111110"), "Default Shirt", "Default Shirt", (int)AssetType.Clothing, (int)InventoryType.Wearable, folderID); item.inventoryCurrentPermissions = 0; item.inventoryNextPermissions = 0; Items.Add(item.inventoryID, item); - item = new InventoryItemBase(); - item.avatarID = libOwner; - item.creatorsID = libOwner; - item.inventoryID = new LLUUID("77c41e39-38f9-f75a-0000-5859892f1111"); - item.assetID = new LLUUID("00000000-38f9-1111-024e-222222111120"); - item.inventoryDescription = "Default Pants"; - item.inventoryName = "Default Pants"; - item.assetType = (int) AssetType.Clothing; - item.invType = (int) InventoryType.Wearable; - item.parentFolderID = folderID; + item = CreateItem(new LLUUID("77c41e39-38f9-f75a-0000-5859892f1111"), new LLUUID("00000000-38f9-1111-024e-222222111120"), "Default Pants", "Default Pants", (int)AssetType.Clothing, (int)InventoryType.Wearable, folderID); item.inventoryCurrentPermissions = 0; item.inventoryNextPermissions = 0; Items.Add(item.inventoryID, item); } + private InventoryItemBase CreateItem(LLUUID inventoryID, LLUUID assetID, string name, string description, int assetType, int invType, LLUUID parentFolderID) + { + InventoryItemBase item = new InventoryItemBase(); + item.avatarID = libOwner; + item.creatorsID = libOwner; + item.inventoryID = LLUUID.Random(); + item.assetID = assetID; + item.inventoryDescription = description; + item.inventoryName = name; + item.assetType = assetType; + item.invType = invType; + item.parentFolderID = parentFolderID; + item.inventoryBasePermissions = 0x7FFFFFFF; + item.inventoryEveryOnePermissions = 0x7FFFFFFF; + item.inventoryCurrentPermissions = 0x7FFFFFFF; + item.inventoryNextPermissions = 0x7FFFFFFF; + return item; + } + private void ReadItemsFromFile(IConfigSource source) { for (int i = 0; i < source.Configs.Count; i++) @@ -232,10 +150,10 @@ namespace OpenSim.Framework.Communications.Cache item.inventoryName = source.Configs[i].GetString("name", ""); item.assetType = source.Configs[i].GetInt("assetType", 0); item.invType = source.Configs[i].GetInt("inventoryType", 0); - item.inventoryCurrentPermissions = (uint) source.Configs[i].GetLong("currentPermissions", 0x7FFFFFFF); - item.inventoryNextPermissions = (uint) source.Configs[i].GetLong("nextPermissions", 0x7FFFFFFF); - item.inventoryEveryOnePermissions = (uint) source.Configs[i].GetLong("everyonePermissions", 0x7FFFFFFF); - item.inventoryBasePermissions = (uint) source.Configs[i].GetLong("basePermissions", 0x7FFFFFFF); + item.inventoryCurrentPermissions = (uint)source.Configs[i].GetLong("currentPermissions", 0x7FFFFFFF); + item.inventoryNextPermissions = (uint)source.Configs[i].GetLong("nextPermissions", 0x7FFFFFFF); + item.inventoryEveryOnePermissions = (uint)source.Configs[i].GetLong("everyonePermissions", 0x7FFFFFFF); + item.inventoryBasePermissions = (uint)source.Configs[i].GetLong("basePermissions", 0x7FFFFFFF); if (item.assetType == 0) { item.parentFolderID = m_textureFolder.folderID; diff --git a/OpenSim/Framework/Communications/Cache/UserProfileCache.cs b/OpenSim/Framework/Communications/Cache/UserProfileCache.cs deleted file mode 100644 index 3c8ab51..0000000 --- a/OpenSim/Framework/Communications/Cache/UserProfileCache.cs +++ /dev/null @@ -1,203 +0,0 @@ -/* -* Copyright (c) Contributors, http://opensimulator.org/ -* See CONTRIBUTORS.TXT for a full list of copyright holders. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in the -* documentation and/or other materials provided with the distribution. -* * Neither the name of the OpenSim Project nor the -* names of its contributors may be used to endorse or promote products -* derived from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY -* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY -* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* -*/ -using System.Collections.Generic; -using libsecondlife; - -namespace OpenSim.Framework.Communications.Cache -{ - public class UserProfileCache - { - // Fields - private readonly CommunicationsManager m_parent; - private readonly Dictionary m_userProfiles = new Dictionary(); - - public LibraryRootFolder libraryRoot = new LibraryRootFolder(); - - // Methods - public UserProfileCache(CommunicationsManager parent) - { - m_parent = parent; - } - - /// - /// A new user has moved into a region in this instance - /// so get info from servers - /// - /// - public void AddNewUser(LLUUID userID) - { - // Potential fix - Multithreading issue. - lock (m_userProfiles) - { - if (!m_userProfiles.ContainsKey(userID)) - { - CachedUserInfo userInfo = new CachedUserInfo(m_parent); - userInfo.UserProfile = m_parent.UserService.GetUserProfile(userID); - - if (userInfo.UserProfile != null) - { - RequestInventoryForUser(userID, userInfo); - m_userProfiles.Add(userID, userInfo); - } - else - { - System.Console.WriteLine("CACHE", "User profile for user not found"); - } - } - } - } - - public CachedUserInfo GetUserDetails(LLUUID userID) - { - if (m_userProfiles.ContainsKey(userID)) - return m_userProfiles[userID]; - else - return null; - } - - public void HandleCreateInventoryFolder(IClientAPI remoteClient, LLUUID folderID, ushort folderType, - string folderName, LLUUID parentID) - { - CachedUserInfo userProfile; - - if (m_userProfiles.TryGetValue(remoteClient.AgentId, out userProfile)) - { - if (userProfile.RootFolder != null) - { - if (userProfile.RootFolder.folderID == parentID) - { - InventoryFolderImpl createdFolder = - userProfile.RootFolder.CreateNewSubFolder(folderID, folderName, folderType); - - if (createdFolder != null) - { - InventoryFolderBase createdBaseFolder = new InventoryFolderBase(); - createdBaseFolder.agentID = createdFolder.agentID; - createdBaseFolder.folderID = createdFolder.folderID; - createdBaseFolder.name = createdFolder.name; - createdBaseFolder.parentID = createdFolder.parentID; - createdBaseFolder.type = createdFolder.type; - createdBaseFolder.version = createdFolder.version; - m_parent.InventoryService.AddNewInventoryFolder(remoteClient.AgentId, createdBaseFolder); - } - } - else - { - InventoryFolderImpl folder = userProfile.RootFolder.HasSubFolder(parentID); - if (folder != null) - { - folder.CreateNewSubFolder(folderID, folderName, folderType); - } - } - } - } - } - - /// - /// Tell the client about the various child items and folders contained in the requested folder. - /// - /// - /// - /// - /// - /// - /// - public void HandleFecthInventoryDescendents(IClientAPI remoteClient, LLUUID folderID, LLUUID ownerID, - bool fetchFolders, bool fetchItems, int sortOrder) - { - InventoryFolderImpl fold = null; - if (folderID == libraryRoot.folderID) - { - remoteClient.SendInventoryFolderDetails(libraryRoot.agentID, libraryRoot.folderID, - libraryRoot.RequestListOfItems(), libraryRoot.SubFoldersCount); - - return; - } - - if ((fold = libraryRoot.HasSubFolder(folderID)) != null) - { - remoteClient.SendInventoryFolderDetails(libraryRoot.agentID, folderID, fold.RequestListOfItems(), fold.SubFoldersCount); - - return; - } - - CachedUserInfo userProfile; - if (m_userProfiles.TryGetValue(remoteClient.AgentId, out userProfile)) - { - if (userProfile.RootFolder != null) - { - if (userProfile.RootFolder.folderID == folderID) - { - if (fetchItems) - { - remoteClient.SendInventoryFolderDetails(remoteClient.AgentId, folderID, - userProfile.RootFolder.RequestListOfItems(), userProfile.RootFolder.SubFoldersCount); - } - } - else - { - InventoryFolderImpl folder = userProfile.RootFolder.HasSubFolder(folderID); - - if (fetchItems && folder != null) - { - remoteClient.SendInventoryFolderDetails(remoteClient.AgentId, folderID, folder.RequestListOfItems(), folder.SubFoldersCount); - } - } - } - } - } - - public void HandleFetchInventory(IClientAPI remoteClient, LLUUID itemID, LLUUID ownerID) - { - if (ownerID == libraryRoot.agentID) - { - //Console.WriteLine("request info for library item"); - - return; - } - - CachedUserInfo userProfile; - if (m_userProfiles.TryGetValue(remoteClient.AgentId, out userProfile)) - { - if (userProfile.RootFolder != null) - { - InventoryItemBase item = userProfile.RootFolder.HasItem(itemID); - if (item != null) - { - remoteClient.SendInventoryItemDetails(ownerID, item); - } - } - } - } - - private void RequestInventoryForUser(LLUUID userID, CachedUserInfo userInfo) - { - m_parent.InventoryService.RequestInventoryForUser(userID, userInfo.FolderReceive, userInfo.ItemReceive); - } - } -} diff --git a/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs b/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs new file mode 100644 index 0000000..b24d763 --- /dev/null +++ b/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs @@ -0,0 +1,203 @@ +/* +* Copyright (c) Contributors, http://opensimulator.org/ +* See CONTRIBUTORS.TXT for a full list of copyright holders. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of the OpenSim Project nor the +* names of its contributors may be used to endorse or promote products +* derived from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY +* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ +using System.Collections.Generic; +using libsecondlife; + +namespace OpenSim.Framework.Communications.Cache +{ + public class UserProfileCacheService + { + // Fields + private readonly CommunicationsManager m_parent; + private readonly Dictionary m_userProfiles = new Dictionary(); + + public LibraryRootFolder libraryRoot = new LibraryRootFolder(); + + // Methods + public UserProfileCacheService(CommunicationsManager parent) + { + m_parent = parent; + } + + /// + /// A new user has moved into a region in this instance + /// so get info from servers + /// + /// + public void AddNewUser(LLUUID userID) + { + // Potential fix - Multithreading issue. + lock (m_userProfiles) + { + if (!m_userProfiles.ContainsKey(userID)) + { + CachedUserInfo userInfo = new CachedUserInfo(m_parent); + userInfo.UserProfile = m_parent.UserService.GetUserProfile(userID); + + if (userInfo.UserProfile != null) + { + RequestInventoryForUser(userID, userInfo); + m_userProfiles.Add(userID, userInfo); + } + else + { + System.Console.WriteLine("CACHE", "User profile for user not found"); + } + } + } + } + + public CachedUserInfo GetUserDetails(LLUUID userID) + { + if (m_userProfiles.ContainsKey(userID)) + return m_userProfiles[userID]; + else + return null; + } + + public void HandleCreateInventoryFolder(IClientAPI remoteClient, LLUUID folderID, ushort folderType, + string folderName, LLUUID parentID) + { + CachedUserInfo userProfile; + + if (m_userProfiles.TryGetValue(remoteClient.AgentId, out userProfile)) + { + if (userProfile.RootFolder != null) + { + if (userProfile.RootFolder.folderID == parentID) + { + InventoryFolderImpl createdFolder = + userProfile.RootFolder.CreateNewSubFolder(folderID, folderName, folderType); + + if (createdFolder != null) + { + InventoryFolderBase createdBaseFolder = new InventoryFolderBase(); + createdBaseFolder.agentID = createdFolder.agentID; + createdBaseFolder.folderID = createdFolder.folderID; + createdBaseFolder.name = createdFolder.name; + createdBaseFolder.parentID = createdFolder.parentID; + createdBaseFolder.type = createdFolder.type; + createdBaseFolder.version = createdFolder.version; + m_parent.InventoryService.AddNewInventoryFolder(remoteClient.AgentId, createdBaseFolder); + } + } + else + { + InventoryFolderImpl folder = userProfile.RootFolder.HasSubFolder(parentID); + if (folder != null) + { + folder.CreateNewSubFolder(folderID, folderName, folderType); + } + } + } + } + } + + /// + /// Tell the client about the various child items and folders contained in the requested folder. + /// + /// + /// + /// + /// + /// + /// + public void HandleFecthInventoryDescendents(IClientAPI remoteClient, LLUUID folderID, LLUUID ownerID, + bool fetchFolders, bool fetchItems, int sortOrder) + { + InventoryFolderImpl fold = null; + if (folderID == libraryRoot.folderID) + { + remoteClient.SendInventoryFolderDetails(libraryRoot.agentID, libraryRoot.folderID, + libraryRoot.RequestListOfItems(), libraryRoot.SubFoldersCount); + + return; + } + + if ((fold = libraryRoot.HasSubFolder(folderID)) != null) + { + remoteClient.SendInventoryFolderDetails(libraryRoot.agentID, folderID, fold.RequestListOfItems(), fold.SubFoldersCount); + + return; + } + + CachedUserInfo userProfile; + if (m_userProfiles.TryGetValue(remoteClient.AgentId, out userProfile)) + { + if (userProfile.RootFolder != null) + { + if (userProfile.RootFolder.folderID == folderID) + { + if (fetchItems) + { + remoteClient.SendInventoryFolderDetails(remoteClient.AgentId, folderID, + userProfile.RootFolder.RequestListOfItems(), userProfile.RootFolder.SubFoldersCount); + } + } + else + { + InventoryFolderImpl folder = userProfile.RootFolder.HasSubFolder(folderID); + + if (fetchItems && folder != null) + { + remoteClient.SendInventoryFolderDetails(remoteClient.AgentId, folderID, folder.RequestListOfItems(), folder.SubFoldersCount); + } + } + } + } + } + + public void HandleFetchInventory(IClientAPI remoteClient, LLUUID itemID, LLUUID ownerID) + { + if (ownerID == libraryRoot.agentID) + { + //Console.WriteLine("request info for library item"); + + return; + } + + CachedUserInfo userProfile; + if (m_userProfiles.TryGetValue(remoteClient.AgentId, out userProfile)) + { + if (userProfile.RootFolder != null) + { + InventoryItemBase item = userProfile.RootFolder.HasItem(itemID); + if (item != null) + { + remoteClient.SendInventoryItemDetails(ownerID, item); + } + } + } + } + + private void RequestInventoryForUser(LLUUID userID, CachedUserInfo userInfo) + { + m_parent.InventoryService.RequestInventoryForUser(userID, userInfo.FolderReceive, userInfo.ItemReceive); + } + } +} diff --git a/OpenSim/Framework/Communications/CommunicationsManager.cs b/OpenSim/Framework/Communications/CommunicationsManager.cs index a7280aa..d4ddead 100644 --- a/OpenSim/Framework/Communications/CommunicationsManager.cs +++ b/OpenSim/Framework/Communications/CommunicationsManager.cs @@ -64,9 +64,9 @@ namespace OpenSim.Framework.Communications get { return m_interRegion; } } - protected UserProfileCache m_userProfileCache; + protected UserProfileCacheService m_userProfileCache; - public UserProfileCache UserProfileCache + public UserProfileCacheService UserProfileCache { get { return m_userProfileCache; } } @@ -97,7 +97,7 @@ namespace OpenSim.Framework.Communications { m_networkServersInfo = serversInfo; m_assetCache = assetCache; - m_userProfileCache = new UserProfileCache(this); + m_userProfileCache = new UserProfileCacheService(this); m_transactionsManager = new AssetTransactionManager(this, dumpAssetsToFile); } diff --git a/OpenSim/Framework/Servers/RestObjectPoster.cs b/OpenSim/Framework/Servers/RestObjectPoster.cs index 07095f3..9bcfcca 100644 --- a/OpenSim/Framework/Servers/RestObjectPoster.cs +++ b/OpenSim/Framework/Servers/RestObjectPoster.cs @@ -5,14 +5,10 @@ using System.Text; using System.Xml; using System.Xml.Serialization; - namespace OpenSim.Framework.Servers { - public delegate void ReturnResponse(T reponse); - public class RestObjectPoster { - public static void BeginPostObject(string requestUrl, TRequest obj) { Type type = typeof(TRequest); @@ -49,93 +45,4 @@ namespace OpenSim.Framework.Servers } } } - - public class RestObjectPosterResponse - { - public ReturnResponse ReturnResponseVal; - - public void BeginPostObject(string requestUrl, TRequest obj) - { - Type type = typeof(TRequest); - - WebRequest request = WebRequest.Create(requestUrl); - request.Method = "POST"; - request.ContentType = "text/xml"; - - MemoryStream buffer = new MemoryStream(); - - XmlWriterSettings settings = new XmlWriterSettings(); - settings.Encoding = Encoding.UTF8; - - using (XmlWriter writer = XmlWriter.Create(buffer, settings)) - { - XmlSerializer serializer = new XmlSerializer(type); - serializer.Serialize(writer, obj); - writer.Flush(); - } - - int length = (int)buffer.Length; - request.ContentLength = length; - - Stream requestStream = request.GetRequestStream(); - requestStream.Write(buffer.ToArray(), 0, length); - IAsyncResult result = request.BeginGetResponse(AsyncCallback, request); - } - - private void AsyncCallback(IAsyncResult result) - { - WebRequest request = (WebRequest)result.AsyncState; - using (WebResponse resp = request.EndGetResponse(result)) - { - TResponse deserial; - XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); - deserial = (TResponse)deserializer.Deserialize(resp.GetResponseStream()); - - if (deserial != null && ReturnResponseVal != null) - { - ReturnResponseVal(deserial); - } - } - } - } - - public class SyncRestObjectPoster - { - - public static TResponse BeginPostObject(string requestUrl, TRequest obj) - { - Type type = typeof(TRequest); - - WebRequest request = WebRequest.Create(requestUrl); - request.Method = "POST"; - request.ContentType = "text/xml"; - - MemoryStream buffer = new MemoryStream(); - - XmlWriterSettings settings = new XmlWriterSettings(); - settings.Encoding = Encoding.UTF8; - - using (XmlWriter writer = XmlWriter.Create(buffer, settings)) - { - XmlSerializer serializer = new XmlSerializer(type); - serializer.Serialize(writer, obj); - writer.Flush(); - } - - int length = (int)buffer.Length; - request.ContentLength = length; - - Stream requestStream = request.GetRequestStream(); - requestStream.Write(buffer.ToArray(), 0, length); - TResponse deserial = default(TResponse); - using (WebResponse resp = request.GetResponse()) - { - - XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); - deserial = (TResponse)deserializer.Deserialize(resp.GetResponseStream()); - } - return deserial; - } - - } } \ No newline at end of file diff --git a/OpenSim/Framework/Servers/RestObjectPosterResponse.cs b/OpenSim/Framework/Servers/RestObjectPosterResponse.cs new file mode 100644 index 0000000..eeae285 --- /dev/null +++ b/OpenSim/Framework/Servers/RestObjectPosterResponse.cs @@ -0,0 +1,60 @@ +using System; +using System.IO; +using System.Net; +using System.Text; +using System.Xml; +using System.Xml.Serialization; + +namespace OpenSim.Framework.Servers +{ + public delegate void ReturnResponse(T reponse); + + public class RestObjectPosterResponse + { + public ReturnResponse ResponseCallback; + + public void BeginPostObject(string requestUrl, TRequest obj) + { + Type type = typeof(TRequest); + + WebRequest request = WebRequest.Create(requestUrl); + request.Method = "POST"; + request.ContentType = "text/xml"; + + MemoryStream buffer = new MemoryStream(); + + XmlWriterSettings settings = new XmlWriterSettings(); + settings.Encoding = Encoding.UTF8; + + using (XmlWriter writer = XmlWriter.Create(buffer, settings)) + { + XmlSerializer serializer = new XmlSerializer(type); + serializer.Serialize(writer, obj); + writer.Flush(); + } + + int length = (int)buffer.Length; + request.ContentLength = length; + + Stream requestStream = request.GetRequestStream(); + requestStream.Write(buffer.ToArray(), 0, length); + IAsyncResult result = request.BeginGetResponse(AsyncCallback, request); + } + + private void AsyncCallback(IAsyncResult result) + { + WebRequest request = (WebRequest)result.AsyncState; + using (WebResponse resp = request.EndGetResponse(result)) + { + TResponse deserial; + XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); + deserial = (TResponse)deserializer.Deserialize(resp.GetResponseStream()); + + if (deserial != null && ResponseCallback != null) + { + ResponseCallback(deserial); + } + } + } + } +} diff --git a/OpenSim/Framework/Servers/SynchronousRestObjectPoster.cs b/OpenSim/Framework/Servers/SynchronousRestObjectPoster.cs new file mode 100644 index 0000000..dde4c02 --- /dev/null +++ b/OpenSim/Framework/Servers/SynchronousRestObjectPoster.cs @@ -0,0 +1,48 @@ +using System; +using System.IO; +using System.Net; +using System.Text; +using System.Xml; +using System.Xml.Serialization; + +namespace OpenSim.Framework.Servers +{ + public class SynchronousRestObjectPoster + { + public static TResponse BeginPostObject(string requestUrl, TRequest obj) + { + Type type = typeof(TRequest); + + WebRequest request = WebRequest.Create(requestUrl); + request.Method = "POST"; + request.ContentType = "text/xml"; + + MemoryStream buffer = new MemoryStream(); + + XmlWriterSettings settings = new XmlWriterSettings(); + settings.Encoding = Encoding.UTF8; + + using (XmlWriter writer = XmlWriter.Create(buffer, settings)) + { + XmlSerializer serializer = new XmlSerializer(type); + serializer.Serialize(writer, obj); + writer.Flush(); + } + + int length = (int)buffer.Length; + request.ContentLength = length; + + Stream requestStream = request.GetRequestStream(); + requestStream.Write(buffer.ToArray(), 0, length); + TResponse deserial = default(TResponse); + using (WebResponse resp = request.GetResponse()) + { + + XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); + deserial = (TResponse)deserializer.Deserialize(resp.GetResponseStream()); + } + return deserial; + } + + } +} -- cgit v1.1