InventoryItemBase.cs 10 KB

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