From 8d8b4a314f1b7baa657885f490ab6aef9cecfc3b Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Tue, 22 Apr 2008 20:47:54 +0000 Subject: * Add DeleteAllContents() method to InventoryFolderImpl - not yet used but will be soon * Add locking to InventoryFolderImpl class - need more though. --- .../Communications/Cache/InventoryFolderImpl.cs | 148 +++++++++++++++------ 1 file changed, 109 insertions(+), 39 deletions(-) (limited to 'OpenSim/Framework/Communications') diff --git a/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs index 091a6a3..daf9ab5 100644 --- a/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs +++ b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs @@ -57,99 +57,169 @@ namespace OpenSim.Framework.Communications.Cache { } - // Methods public InventoryFolderImpl CreateNewSubFolder(LLUUID folderID, string folderName, ushort type) { - if (!SubFolders.ContainsKey(folderID)) + lock (SubFolders) { - InventoryFolderImpl subFold = new InventoryFolderImpl(); - subFold.Name = folderName; - subFold.ID = folderID; - subFold.Type = (short) type; - subFold.ParentID = this.ID; - subFold.Owner = Owner; - SubFolders.Add(subFold.ID, subFold); - return subFold; + if (!SubFolders.ContainsKey(folderID)) + { + InventoryFolderImpl subFold = new InventoryFolderImpl(); + subFold.Name = folderName; + subFold.ID = folderID; + subFold.Type = (short) type; + subFold.ParentID = this.ID; + subFold.Owner = Owner; + SubFolders.Add(subFold.ID, subFold); + return subFold; + } } + return null; } + + /// + /// Delete all the folders and items in this folder. + /// + /// TODO: This method is not used yet, but will be shortly + /// + public void DeleteAllContents() + { + foreach (InventoryFolderImpl folder in SubFolders.Values) + { + folder.DeleteAllContents(); + } + + SubFolders.Clear(); + Items.Clear(); + } + /// + /// Does this folder contain the given item? + /// + /// + /// public InventoryItemBase HasItem(LLUUID itemID) { InventoryItemBase base2 = null; - if (Items.ContainsKey(itemID)) + + lock (Items) { - return Items[itemID]; + if (Items.ContainsKey(itemID)) + { + return Items[itemID]; + } } - foreach (InventoryFolderImpl folder in SubFolders.Values) + + lock (SubFolders) { - base2 = folder.HasItem(itemID); - if (base2 != null) + foreach (InventoryFolderImpl folder in SubFolders.Values) { - break; + base2 = folder.HasItem(itemID); + if (base2 != null) + { + break; + } } } + return base2; } + /// + /// Delete an item from the folder. + /// + /// + /// public bool DeleteItem(LLUUID itemID) { bool found = false; - if (Items.ContainsKey(itemID)) + + lock (Items) { - Items.Remove(itemID); - return true; + if (Items.ContainsKey(itemID)) + { + Items.Remove(itemID); + return true; + } } - foreach (InventoryFolderImpl folder in SubFolders.Values) + + lock (SubFolders) { - found = folder.DeleteItem(itemID); - if (found == true) + foreach (InventoryFolderImpl folder in SubFolders.Values) { - break; + found = folder.DeleteItem(itemID); + if (found == true) + { + break; + } } } return found; } - + /// + /// Does this folder contain the given subfolder? + /// + /// public InventoryFolderImpl HasSubFolder(LLUUID folderID) - { + { InventoryFolderImpl returnFolder = null; - if (SubFolders.ContainsKey(folderID)) - { - returnFolder = SubFolders[folderID]; - } - else + + lock (SubFolders) { - foreach (InventoryFolderImpl folder in SubFolders.Values) + if (SubFolders.ContainsKey(folderID)) { - returnFolder = folder.HasSubFolder(folderID); - if (returnFolder != null) + returnFolder = SubFolders[folderID]; + } + else + { + foreach (InventoryFolderImpl folder in SubFolders.Values) { - break; + returnFolder = folder.HasSubFolder(folderID); + if (returnFolder != null) + { + break; + } } } } + return returnFolder; } + /// + /// Return the list of items in this folder + /// public List RequestListOfItems() { List itemList = new List(); - foreach (InventoryItemBase item in Items.Values) + + lock (Items) { - itemList.Add(item); + foreach (InventoryItemBase item in Items.Values) + { + itemList.Add(item); + } } + return itemList; } + /// + /// Return the list of folders in this folder + /// public List RequestListOfFolders() - { + { List folderList = new List(); - foreach (InventoryFolderBase folder in SubFolders.Values) + + lock (SubFolders) { - folderList.Add(folder); + foreach (InventoryFolderBase folder in SubFolders.Values) + { + folderList.Add(folder); + } } + return folderList; } } -- cgit v1.1