InventoryItemBase.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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;
  28. using System.Collections.Generic;
  29. using System.Xml.Serialization;
  30. using libsecondlife;
  31. namespace OpenSim.Framework
  32. {
  33. /// <summary>
  34. /// Inventory Item - contains all the properties associated with an individual inventory piece.
  35. /// </summary>
  36. public class InventoryItemBase
  37. {
  38. /// <summary>
  39. /// A UUID containing the ID for the inventory item itself
  40. /// </summary>
  41. public LLUUID inventoryID;
  42. /// <summary>
  43. /// The UUID of the associated asset on the asset server
  44. /// </summary>
  45. public LLUUID assetID;
  46. /// <summary>
  47. /// This is an enumerated value determining the type of asset (eg Notecard, Sound, Object, etc)
  48. /// </summary>
  49. public int assetType;
  50. /// <summary>
  51. /// The type of inventory item. (Can be slightly different to the asset type
  52. /// </summary>
  53. public int invType;
  54. /// <summary>
  55. /// The folder this item is contained in
  56. /// </summary>
  57. public LLUUID parentFolderID;
  58. /// <summary>
  59. /// The owner of this inventory item
  60. /// </summary>
  61. public LLUUID avatarID;
  62. /// <summary>
  63. /// The creator of this item
  64. /// </summary>
  65. public LLUUID creatorsID;
  66. /// <summary>
  67. /// The name of the inventory item (must be less than 64 characters)
  68. /// </summary>
  69. public string inventoryName;
  70. /// <summary>
  71. /// The description of the inventory item (must be less than 64 characters)
  72. /// </summary>
  73. public string inventoryDescription;
  74. /// <summary>
  75. /// A mask containing the permissions for the next owner (cannot be enforced)
  76. /// </summary>
  77. public uint inventoryNextPermissions;
  78. /// <summary>
  79. /// A mask containing permissions for the current owner (cannot be enforced)
  80. /// </summary>
  81. public uint inventoryCurrentPermissions;
  82. /// <summary>
  83. ///
  84. /// </summary>
  85. public uint inventoryBasePermissions;
  86. /// <summary>
  87. ///
  88. /// </summary>
  89. public uint inventoryEveryOnePermissions;
  90. }
  91. /// <summary>
  92. /// A Class for folders which contain users inventory
  93. /// </summary>
  94. public class InventoryFolderBase
  95. {
  96. /// <summary>
  97. /// The name of the folder (64 characters or less)
  98. /// </summary>
  99. public string name;
  100. /// <summary>
  101. /// The agent who's inventory this is contained by
  102. /// </summary>
  103. public LLUUID agentID;
  104. /// <summary>
  105. /// The folder this folder is contained in
  106. /// </summary>
  107. public LLUUID parentID;
  108. /// <summary>
  109. /// The UUID for this folder
  110. /// </summary>
  111. public LLUUID folderID;
  112. /// <summary>
  113. /// Type of items normally stored in this folder
  114. /// </summary>
  115. public short type;
  116. /// <summary>
  117. ///
  118. /// </summary>
  119. public ushort version;
  120. }
  121. /// <summary>
  122. /// An interface for accessing inventory data from a storage server
  123. /// </summary>
  124. public interface IInventoryData
  125. {
  126. /// <summary>
  127. /// Initialises the interface
  128. /// </summary>
  129. void Initialise();
  130. /// <summary>
  131. /// Closes the interface
  132. /// </summary>
  133. void Close();
  134. /// <summary>
  135. /// The plugin being loaded
  136. /// </summary>
  137. /// <returns>A string containing the plugin name</returns>
  138. string getName();
  139. /// <summary>
  140. /// The plugins version
  141. /// </summary>
  142. /// <returns>A string containing the plugin version</returns>
  143. string getVersion();
  144. /// <summary>
  145. /// Returns all child folders in the hierarchy from the parent folder and down.
  146. /// Does not return the parent folder itself.
  147. /// </summary>
  148. /// <param name="parentID">The folder to get subfolders for</param>
  149. /// <returns>A list of inventory folders</returns>
  150. List<InventoryFolderBase> getFolderHierarchy(LLUUID parentID);
  151. /// <summary>
  152. /// Returns a list of inventory items contained within the specified folder
  153. /// </summary>
  154. /// <param name="folderID">The UUID of the target folder</param>
  155. /// <returns>A List of InventoryItemBase items</returns>
  156. List<InventoryItemBase> getInventoryInFolder(LLUUID folderID);
  157. /// <summary>
  158. /// Returns a list of the root folders within a users inventory
  159. /// </summary>
  160. /// <param name="user">The user whos inventory is to be searched</param>
  161. /// <returns>A list of folder objects</returns>
  162. List<InventoryFolderBase> getUserRootFolders(LLUUID user);
  163. /// <summary>
  164. /// Returns the users inventory root folder.
  165. /// </summary>
  166. /// <param name="user">The UUID of the user who is having inventory being returned</param>
  167. /// <returns>Root inventory folder, null if no root inventory folder was found</returns>
  168. InventoryFolderBase getUserRootFolder(LLUUID user);
  169. /// <summary>
  170. /// Returns a list of inventory folders contained in the folder 'parentID'
  171. /// </summary>
  172. /// <param name="parentID">The folder to get subfolders for</param>
  173. /// <returns>A list of inventory folders</returns>
  174. List<InventoryFolderBase> getInventoryFolders(LLUUID parentID);
  175. /// <summary>
  176. /// Returns an inventory item by its UUID
  177. /// </summary>
  178. /// <param name="item">The UUID of the item to be returned</param>
  179. /// <returns>A class containing item information</returns>
  180. InventoryItemBase getInventoryItem(LLUUID item);
  181. /// <summary>
  182. /// Returns a specified inventory folder by its UUID
  183. /// </summary>
  184. /// <param name="folder">The UUID of the folder to be returned</param>
  185. /// <returns>A class containing folder information</returns>
  186. InventoryFolderBase getInventoryFolder(LLUUID folder);
  187. /// <summary>
  188. /// Creates a new inventory item based on item
  189. /// </summary>
  190. /// <param name="item">The item to be created</param>
  191. void addInventoryItem(InventoryItemBase item);
  192. /// <summary>
  193. /// Updates an inventory item with item (updates based on ID)
  194. /// </summary>
  195. /// <param name="item">The updated item</param>
  196. void updateInventoryItem(InventoryItemBase item);
  197. /// <summary>
  198. ///
  199. /// </summary>
  200. /// <param name="item"></param>
  201. void deleteInventoryItem(LLUUID item);
  202. /// <summary>
  203. /// Adds a new folder specified by folder
  204. /// </summary>
  205. /// <param name="folder">The inventory folder</param>
  206. void addInventoryFolder(InventoryFolderBase folder);
  207. /// <summary>
  208. /// Updates a folder based on its ID with folder
  209. /// </summary>
  210. /// <param name="folder">The inventory folder</param>
  211. void updateInventoryFolder(InventoryFolderBase folder);
  212. /// <summary>
  213. /// Updates a folder based on its ID with folder
  214. /// </summary>
  215. /// <param name="folder">The inventory folder</param>
  216. void moveInventoryFolder(InventoryFolderBase folder);
  217. /// <summary>
  218. /// Deletes a folder based on its ID with folder
  219. /// </summary>
  220. /// <param name="folder">The id of the folder</param>
  221. void deleteInventoryFolder(LLUUID folder);
  222. }
  223. public class InventoryCollection
  224. {
  225. public List<InventoryFolderBase> Folders;
  226. public List<InventoryItemBase> AllItems;
  227. public LLUUID UserID;
  228. public InventoryCollection()
  229. {
  230. Folders = new List<InventoryFolderBase>();
  231. AllItems = new List<InventoryItemBase>();
  232. }
  233. public InventoryCollection(List<InventoryFolderBase> folders, List<InventoryItemBase> allItems)
  234. {
  235. Folders = folders;
  236. AllItems = allItems;
  237. }
  238. }
  239. /*
  240. * .Net has some issues, serializing a dictionary, so we cannot reuse the InventoryFolder
  241. * class defined in Communications.Framework.Communications.Caches. So we serialize/deserialize
  242. * into this simpler class, and then use that.
  243. */
  244. [XmlRoot(ElementName = "inventory", IsNullable = true)]
  245. public class SerializableInventory
  246. {
  247. [XmlRoot(ElementName = "folder", IsNullable = true)]
  248. public class SerializableFolder : InventoryFolderBase
  249. {
  250. [XmlArray(ElementName = "folders", IsNullable = true)] [XmlArrayItem(ElementName = "folder", IsNullable = true, Type = typeof (SerializableFolder))] public
  251. ArrayList SubFolders;
  252. [XmlArray(ElementName = "items", IsNullable = true)] [XmlArrayItem(ElementName = "item", IsNullable = true, Type = typeof (InventoryItemBase))] public ArrayList
  253. Items;
  254. }
  255. [XmlElement(ElementName = "folder", IsNullable = true)] public SerializableFolder root;
  256. }
  257. }