InventoryFolderImpl.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System.Collections.Generic;
  28. using libsecondlife;
  29. namespace OpenSim.Framework.Communications.Cache
  30. {
  31. public class InventoryFolderImpl : InventoryFolderBase
  32. {
  33. // Fields
  34. public Dictionary<LLUUID, InventoryItemBase> Items = new Dictionary<LLUUID, InventoryItemBase>();
  35. public Dictionary<LLUUID, InventoryFolderImpl> SubFolders = new Dictionary<LLUUID, InventoryFolderImpl>();
  36. // Accessors
  37. public int SubFoldersCount
  38. {
  39. get { return SubFolders.Count; }
  40. }
  41. // Constructors
  42. public InventoryFolderImpl(InventoryFolderBase folderbase)
  43. {
  44. agentID = folderbase.agentID;
  45. folderID = folderbase.folderID;
  46. name = folderbase.name;
  47. parentID = folderbase.parentID;
  48. type = folderbase.type;
  49. version = folderbase.version;
  50. }
  51. public InventoryFolderImpl()
  52. {
  53. }
  54. // Methods
  55. public InventoryFolderImpl CreateNewSubFolder(LLUUID folderID, string folderName, ushort type)
  56. {
  57. if (!SubFolders.ContainsKey(folderID))
  58. {
  59. InventoryFolderImpl subFold = new InventoryFolderImpl();
  60. subFold.name = folderName;
  61. subFold.folderID = folderID;
  62. subFold.type = (short) type;
  63. subFold.parentID = this.folderID;
  64. subFold.agentID = agentID;
  65. SubFolders.Add(subFold.folderID, subFold);
  66. return subFold;
  67. }
  68. return null;
  69. }
  70. public InventoryItemBase HasItem(LLUUID itemID)
  71. {
  72. InventoryItemBase base2 = null;
  73. if (Items.ContainsKey(itemID))
  74. {
  75. return Items[itemID];
  76. }
  77. foreach (InventoryFolderImpl folder in SubFolders.Values)
  78. {
  79. base2 = folder.HasItem(itemID);
  80. if (base2 != null)
  81. {
  82. break;
  83. }
  84. }
  85. return base2;
  86. }
  87. public bool DeleteItem(LLUUID itemID)
  88. {
  89. bool found = false;
  90. if (Items.ContainsKey(itemID))
  91. {
  92. Items.Remove(itemID);
  93. return true;
  94. }
  95. foreach (InventoryFolderImpl folder in SubFolders.Values)
  96. {
  97. found = folder.DeleteItem(itemID);
  98. if (found == true)
  99. {
  100. break;
  101. }
  102. }
  103. return found;
  104. }
  105. public InventoryFolderImpl HasSubFolder(LLUUID folderID)
  106. {
  107. InventoryFolderImpl returnFolder = null;
  108. if (SubFolders.ContainsKey(folderID))
  109. {
  110. returnFolder = SubFolders[folderID];
  111. }
  112. else
  113. {
  114. foreach (InventoryFolderImpl folder in SubFolders.Values)
  115. {
  116. returnFolder = folder.HasSubFolder(folderID);
  117. if (returnFolder != null)
  118. {
  119. break;
  120. }
  121. }
  122. }
  123. return returnFolder;
  124. }
  125. public List<InventoryItemBase> RequestListOfItems()
  126. {
  127. List<InventoryItemBase> itemList = new List<InventoryItemBase>();
  128. foreach (InventoryItemBase item in Items.Values)
  129. {
  130. itemList.Add(item);
  131. }
  132. return itemList;
  133. }
  134. public List<InventoryFolderBase> RequestListOfFolders()
  135. {
  136. List<InventoryFolderBase> folderList = new List<InventoryFolderBase>();
  137. foreach (InventoryFolderBase folder in SubFolders.Values)
  138. {
  139. folderList.Add(folder);
  140. }
  141. return folderList;
  142. }
  143. }
  144. }