From 80e267dcfec335c5402922c4eb5587df9603f94d Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Thu, 11 Dec 2008 20:58:11 +0000 Subject: * refactor: Stop exposing InventoryFolderImpl.SubFolders publicly --- .../Communications/Cache/CachedUserInfo.cs | 45 +++++------ .../Communications/Cache/InventoryFolderImpl.cs | 93 ++++++++++++++-------- .../Communications/Cache/LibraryRootFolder.cs | 2 +- .../Tests/Cache/UserProfileCacheServiceTests.cs | 4 +- 4 files changed, 84 insertions(+), 60 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs index d3e715f..d597aad 100644 --- a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs +++ b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs @@ -161,29 +161,27 @@ namespace OpenSim.Framework.Communications.Cache List resolvedFolders = new List(); // Folders we've resolved with this invocation foreach (InventoryFolderImpl folder in receivedFolderDictionary[parentFolder.ID]) { - lock (parentFolder.SubFolders) + if (parentFolder.ContainsChildFolder(folder.ID)) { - if (parentFolder.SubFolders.ContainsKey(folder.ID)) + m_log.WarnFormat( + "[INVENTORY CACHE]: Received folder {0} {1} from inventory service which has already been received", + folder.Name, folder.ID); + } + else + { + if (resolvedFolderDictionary.ContainsKey(folder.ID)) { m_log.WarnFormat( - "[INVENTORY CACHE]: Received folder {0} {1} from inventory service which has already been received", + "[INVENTORY CACHE]: Received folder {0} {1} from inventory service has already been received but with different parent", folder.Name, folder.ID); } else { - if ( resolvedFolderDictionary.ContainsKey( folder.ID ) ) { - m_log.WarnFormat( - "[INVENTORY CACHE]: Received folder {0} {1} from inventory service has already been received but with different parent", - folder.Name, folder.ID); - } - else - { - resolvedFolders.Add(folder); - resolvedFolderDictionary[folder.ID] = folder; - parentFolder.SubFolders.Add(folder.ID, folder); - } - } - } // lock (parentFolder.SubFolders) + resolvedFolders.Add(folder); + resolvedFolderDictionary[folder.ID] = folder; + parentFolder.AddChildFolder(folder); + } + } } // foreach (folder in pendingCategorizationFolders[parentFolder.ID]) receivedFolderDictionary.Remove(parentFolder.ID); @@ -738,20 +736,17 @@ namespace OpenSim.Framework.Communications.Cache } } + /// + /// Find an appropriate folder for the given asset type + /// + /// + /// null if no appropriate folder exists public InventoryFolderImpl FindFolderForType(int type) { if (RootFolder == null) return null; - lock (RootFolder.SubFolders) - { - foreach (InventoryFolderImpl f in RootFolder.SubFolders.Values) - { - if (f.Type == type) - return f; - } - } - return null; + return RootFolder.FindFolderForType(type); } } diff --git a/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs index 933d40a..4c629f4 100644 --- a/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs +++ b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs @@ -48,7 +48,7 @@ namespace OpenSim.Framework.Communications.Cache /// /// Child folders that are contained in this folder /// - public Dictionary SubFolders = new Dictionary(); + protected Dictionary m_childFolders = new Dictionary(); // Constructors public InventoryFolderImpl(InventoryFolderBase folderbase) @@ -74,9 +74,9 @@ namespace OpenSim.Framework.Communications.Cache /// The newly created subfolder. Returns null if the folder already exists public InventoryFolderImpl CreateChildFolder(UUID folderID, string folderName, ushort type) { - lock (SubFolders) + lock (m_childFolders) { - if (!SubFolders.ContainsKey(folderID)) + if (!m_childFolders.ContainsKey(folderID)) { InventoryFolderImpl subFold = new InventoryFolderImpl(); subFold.Name = folderName; @@ -84,7 +84,7 @@ namespace OpenSim.Framework.Communications.Cache subFold.Type = (short) type; subFold.ParentID = this.ID; subFold.Owner = Owner; - SubFolders.Add(subFold.ID, subFold); + m_childFolders.Add(subFold.ID, subFold); return subFold; } @@ -99,14 +99,24 @@ namespace OpenSim.Framework.Communications.Cache /// public void AddChildFolder(InventoryFolderImpl folder) { - lock (SubFolders) + lock (m_childFolders) { folder.ParentID = ID; - SubFolders[folder.ID] = folder; + m_childFolders[folder.ID] = folder; } } /// + /// Does this folder contain the given child folder? + /// + /// + /// + public bool ContainsChildFolder(UUID folderID) + { + return m_childFolders.ContainsKey(folderID); + } + + /// /// Get a child folder /// /// @@ -115,9 +125,9 @@ namespace OpenSim.Framework.Communications.Cache { InventoryFolderImpl folder = null; - lock (SubFolders) + lock (m_childFolders) { - SubFolders.TryGetValue(folderID, out folder); + m_childFolders.TryGetValue(folderID, out folder); } return folder; @@ -134,12 +144,12 @@ namespace OpenSim.Framework.Communications.Cache { InventoryFolderImpl removedFolder = null; - lock (SubFolders) + lock (m_childFolders) { - if (SubFolders.ContainsKey(folderID)) + if (m_childFolders.ContainsKey(folderID)) { - removedFolder = SubFolders[folderID]; - SubFolders.Remove(folderID); + removedFolder = m_childFolders[folderID]; + m_childFolders.Remove(folderID); } } @@ -151,12 +161,12 @@ namespace OpenSim.Framework.Communications.Cache /// public void Purge() { - foreach (InventoryFolderImpl folder in SubFolders.Values) + foreach (InventoryFolderImpl folder in m_childFolders.Values) { folder.Purge(); } - SubFolders.Clear(); + m_childFolders.Clear(); Items.Clear(); } @@ -175,9 +185,9 @@ namespace OpenSim.Framework.Communications.Cache } } - lock (SubFolders) + lock (m_childFolders) { - foreach (InventoryFolderImpl folder in SubFolders.Values) + foreach (InventoryFolderImpl folder in m_childFolders.Values) { InventoryItemBase item = folder.FindItem(itemID); @@ -202,9 +212,9 @@ namespace OpenSim.Framework.Communications.Cache } } - lock (SubFolders) + lock (m_childFolders) { - foreach (InventoryFolderImpl folder in SubFolders.Values) + foreach (InventoryFolderImpl folder in m_childFolders.Values) { InventoryItemBase item = folder.FindAsset(assetID); @@ -236,9 +246,9 @@ namespace OpenSim.Framework.Communications.Cache } } - lock (SubFolders) + lock (m_childFolders) { - foreach (InventoryFolderImpl folder in SubFolders.Values) + foreach (InventoryFolderImpl folder in m_childFolders.Values) { found = folder.DeleteItem(itemID); @@ -262,9 +272,9 @@ namespace OpenSim.Framework.Communications.Cache if (folderID == ID) return this; - lock (SubFolders) + lock (m_childFolders) { - foreach (InventoryFolderImpl folder in SubFolders.Values) + foreach (InventoryFolderImpl folder in m_childFolders.Values) { InventoryFolderImpl returnFolder = folder.FindFolder(folderID); @@ -274,7 +284,26 @@ namespace OpenSim.Framework.Communications.Cache } return null; - } + } + + /// + /// Look through all child subfolders for a folder marked as one for a particular asset type, and return it. + /// + /// + /// Returns null if no such folder is found + public InventoryFolderImpl FindFolderForType(int type) + { + lock (m_childFolders) + { + foreach (InventoryFolderImpl f in m_childFolders.Values) + { + if (f.Type == type) + return f; + } + } + + return null; + } /// /// Find a folder given a PATH_DELIMITOR delimited path starting from this folder @@ -297,9 +326,9 @@ namespace OpenSim.Framework.Communications.Cache string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None); - lock (SubFolders) + lock (m_childFolders) { - foreach (InventoryFolderImpl folder in SubFolders.Values) + foreach (InventoryFolderImpl folder in m_childFolders.Values) { if (folder.Name == components[0]) if (components.Length > 1) @@ -344,9 +373,9 @@ namespace OpenSim.Framework.Communications.Cache } else { - lock (SubFolders) + lock (m_childFolders) { - foreach (InventoryFolderImpl folder in SubFolders.Values) + foreach (InventoryFolderImpl folder in m_childFolders.Values) { if (folder.Name == components[0]) return folder.FindItemByPath(components[1]); @@ -385,9 +414,9 @@ namespace OpenSim.Framework.Communications.Cache { List folderList = new List(); - lock (SubFolders) + lock (m_childFolders) { - foreach (InventoryFolderBase folder in SubFolders.Values) + foreach (InventoryFolderBase folder in m_childFolders.Values) { folderList.Add(folder); } @@ -400,9 +429,9 @@ namespace OpenSim.Framework.Communications.Cache { List folderList = new List(); - lock (SubFolders) + lock (m_childFolders) { - foreach (InventoryFolderImpl folder in SubFolders.Values) + foreach (InventoryFolderImpl folder in m_childFolders.Values) { folderList.Add(folder); } @@ -421,7 +450,7 @@ namespace OpenSim.Framework.Communications.Cache { int total = Items.Count; - foreach (InventoryFolderImpl folder in SubFolders.Values) + foreach (InventoryFolderImpl folder in m_childFolders.Values) { total = total + folder.TotalCount; } diff --git a/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs b/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs index 437e5e4..cf3490b 100644 --- a/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs +++ b/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs @@ -142,7 +142,7 @@ namespace OpenSim.Framework.Communications.Cache InventoryFolderImpl parentFolder = libraryFolders[folderInfo.ParentID]; libraryFolders.Add(folderInfo.ID, folderInfo); - parentFolder.SubFolders.Add(folderInfo.ID, folderInfo); + parentFolder.AddChildFolder(folderInfo); // m_log.InfoFormat("[LIBRARY INVENTORY]: Adding folder {0} ({1})", folderInfo.name, folderInfo.folderID); } diff --git a/OpenSim/Framework/Communications/Tests/Cache/UserProfileCacheServiceTests.cs b/OpenSim/Framework/Communications/Tests/Cache/UserProfileCacheServiceTests.cs index f209fd4..9c07734 100644 --- a/OpenSim/Framework/Communications/Tests/Cache/UserProfileCacheServiceTests.cs +++ b/OpenSim/Framework/Communications/Tests/Cache/UserProfileCacheServiceTests.cs @@ -106,11 +106,11 @@ namespace OpenSim.Framework.Communications.Tests CachedUserInfo userInfo = commsManager.UserProfileCacheService.GetUserDetails(userId); UUID folderId = UUID.Parse("00000000-0000-0000-0000-000000000010"); - Assert.That(userInfo.RootFolder.SubFolders.ContainsKey(folderId), Is.False); + Assert.That(userInfo.RootFolder.ContainsChildFolder(folderId), Is.False); userInfo.CreateFolder("testFolder", folderId, (ushort)AssetType.Animation, userInfo.RootFolder.ID); Assert.That(inventoryDataPlugin.getInventoryFolder(folderId), Is.Not.Null); - Assert.That(userInfo.RootFolder.SubFolders.ContainsKey(folderId), Is.True); + Assert.That(userInfo.RootFolder.ContainsChildFolder(folderId), Is.True); } /// -- cgit v1.1