TaskInventoryItem.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using System.Xml;
  31. using System.Xml.Schema;
  32. using System.Xml.Serialization;
  33. using libsecondlife;
  34. using log4net;
  35. namespace OpenSim.Framework
  36. {
  37. /// <summary>
  38. /// A dictionary for task inventory.
  39. ///
  40. /// This class is not thread safe. Callers must synchronize on Dictionary methods.
  41. /// </summary>
  42. public class TaskInventoryDictionary : Dictionary<LLUUID, TaskInventoryItem>,
  43. ICloneable, IXmlSerializable
  44. {
  45. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  46. private static XmlSerializer tiiSerializer = new XmlSerializer(typeof (TaskInventoryItem));
  47. #region ICloneable Members
  48. public Object Clone()
  49. {
  50. TaskInventoryDictionary clone = new TaskInventoryDictionary();
  51. lock (this)
  52. {
  53. foreach (LLUUID uuid in Keys)
  54. {
  55. clone.Add(uuid, (TaskInventoryItem) this[uuid].Clone());
  56. }
  57. }
  58. return clone;
  59. }
  60. #endregion
  61. // The alternative of simply serializing the list doesn't appear to work on mono, since
  62. // we get a
  63. //
  64. // System.TypeInitializationException: An exception was thrown by the type initializer for OpenSim.Framework.TaskInventoryDictionary ---> System.ArgumentOutOfRangeException: < 0
  65. // Parameter name: length
  66. // at System.String.Substring (Int32 startIndex, Int32 length) [0x00088] in /build/buildd/mono-1.2.4/mcs/class/corlib/System/String.cs:381
  67. // at System.Xml.Serialization.TypeTranslator.GetTypeData (System.Type runtimeType, System.String xmlDataType) [0x001f6] in /build/buildd/mono-1.2.4/mcs/class/System.XML/System.Xml.Serialization/TypeTranslator.cs:217
  68. // ...
  69. // private static XmlSerializer tiiSerializer
  70. // = new XmlSerializer(typeof(Dictionary<LLUUID, TaskInventoryItem>.ValueCollection));
  71. // see IXmlSerializable
  72. #region IXmlSerializable Members
  73. public XmlSchema GetSchema()
  74. {
  75. return null;
  76. }
  77. // see IXmlSerializable
  78. public void ReadXml(XmlReader reader)
  79. {
  80. m_log.DebugFormat("[TASK INVENTORY]: ReadXml current node before actions, {0}", reader.Name);
  81. if (!reader.IsEmptyElement)
  82. {
  83. reader.Read();
  84. while (tiiSerializer.CanDeserialize(reader))
  85. {
  86. TaskInventoryItem item = (TaskInventoryItem) tiiSerializer.Deserialize(reader);
  87. Add(item.ItemID, item);
  88. m_log.DebugFormat("[TASK INVENTORY]: Instanted prim item {0}, {1} from xml", item.Name, item.ItemID);
  89. }
  90. m_log.DebugFormat("[TASK INVENTORY]: Instantiated {0} prim items in total from xml", Count);
  91. }
  92. else
  93. {
  94. m_log.DebugFormat("[TASK INVENTORY]: Skipping empty element {0}", reader.Name);
  95. }
  96. // For some .net implementations, this last read is necessary so that we advance beyond the end tag
  97. // of the element wrapping this object so that the rest of the serialization can complete normally.
  98. reader.Read();
  99. m_log.DebugFormat("[TASK INVENTORY]: ReadXml current node after actions, {0}", reader.Name);
  100. }
  101. // see IXmlSerializable
  102. public void WriteXml(XmlWriter writer)
  103. {
  104. lock (this)
  105. {
  106. foreach (TaskInventoryItem item in Values)
  107. {
  108. tiiSerializer.Serialize(writer, item);
  109. }
  110. }
  111. //tiiSerializer.Serialize(writer, Values);
  112. }
  113. #endregion
  114. // see ICloneable
  115. }
  116. /// <summary>
  117. /// Represents an item in a task inventory
  118. /// </summary>
  119. public class TaskInventoryItem : ICloneable
  120. {
  121. /// <summary>
  122. /// XXX This should really be factored out into some constants class.
  123. /// </summary>
  124. private const uint FULL_MASK_PERMISSIONS_GENERAL = 2147483647;
  125. /// <summary>
  126. /// Inventory types
  127. /// </summary>
  128. public static string[] InvTypes = new string[]
  129. {
  130. "texture",
  131. "sound",
  132. "calling_card",
  133. "landmark",
  134. String.Empty,
  135. String.Empty,
  136. "object",
  137. "notecard",
  138. String.Empty,
  139. String.Empty,
  140. "lsl_text",
  141. String.Empty,
  142. String.Empty,
  143. "bodypart",
  144. String.Empty,
  145. "snapshot",
  146. String.Empty,
  147. String.Empty,
  148. "wearable",
  149. "animation",
  150. "gesture"
  151. };
  152. /// <summary>
  153. /// Asset types
  154. /// </summary>
  155. public static string[] Types = new string[]
  156. {
  157. "texture",
  158. "sound",
  159. "callcard",
  160. "landmark",
  161. "clothing", // Deprecated
  162. "clothing",
  163. "object",
  164. "notecard",
  165. "category",
  166. "root",
  167. "lsltext",
  168. "lslbyte",
  169. "txtr_tga",
  170. "bodypart",
  171. "trash",
  172. "snapshot",
  173. "lstndfnd",
  174. "snd_wav",
  175. "img_tga",
  176. "jpeg",
  177. "animatn",
  178. "gesture"
  179. };
  180. public LLUUID AssetID = LLUUID.Zero;
  181. public uint BaseMask = FULL_MASK_PERMISSIONS_GENERAL;
  182. public uint CreationDate = 0;
  183. public LLUUID CreatorID = LLUUID.Zero;
  184. public string Description = String.Empty;
  185. public uint EveryoneMask = FULL_MASK_PERMISSIONS_GENERAL;
  186. public uint Flags = 0;
  187. public LLUUID GroupID = LLUUID.Zero;
  188. public uint GroupMask = FULL_MASK_PERMISSIONS_GENERAL;
  189. public int InvType = 0;
  190. public LLUUID ItemID = LLUUID.Zero;
  191. public LLUUID LastOwnerID = LLUUID.Zero;
  192. public string Name = String.Empty;
  193. public uint NextOwnerMask = FULL_MASK_PERMISSIONS_GENERAL;
  194. public LLUUID OwnerID = LLUUID.Zero;
  195. public uint OwnerMask = FULL_MASK_PERMISSIONS_GENERAL;
  196. public LLUUID ParentID = LLUUID.Zero; //parent folder id
  197. public LLUUID ParentPartID = LLUUID.Zero;
  198. public LLUUID PermsGranter;
  199. public int PermsMask;
  200. public int Type = 0;
  201. // See ICloneable
  202. #region ICloneable Members
  203. public Object Clone()
  204. {
  205. return MemberwiseClone();
  206. }
  207. #endregion
  208. /// <summary>
  209. /// Reset the LLUUIDs for this item.
  210. /// </summary>
  211. /// <param name="partID">The new part ID to which this item belongs</param>
  212. public void ResetIDs(LLUUID partID)
  213. {
  214. ItemID = LLUUID.Random();
  215. ParentPartID = partID;
  216. }
  217. }
  218. }