TaskInventoryItem.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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.Generic;
  29. using System.Xml;
  30. using System.Xml.Schema;
  31. using System.Xml.Serialization;
  32. using libsecondlife;
  33. using System;
  34. namespace OpenSim.Framework
  35. {
  36. /// <summary>
  37. /// A dictionary for task inventory.
  38. ///
  39. /// This class is not thread safe. Callers must synchronize on Dictionary methods.
  40. /// </summary>
  41. public class TaskInventoryDictionary : Dictionary<LLUUID, TaskInventoryItem>,
  42. ICloneable, IXmlSerializable
  43. {
  44. private static XmlSerializer tiiSerializer = new XmlSerializer(typeof(TaskInventoryItem));
  45. // The alternative of simply serializing the list doesn't appear to work on mono, since
  46. // we get a
  47. //
  48. // System.TypeInitializationException: An exception was thrown by the type initializer for OpenSim.Framework.TaskInventoryDictionary ---> System.ArgumentOutOfRangeException: < 0
  49. // Parameter name: length
  50. // at System.String.Substring (Int32 startIndex, Int32 length) [0x00088] in /build/buildd/mono-1.2.4/mcs/class/corlib/System/String.cs:381
  51. // 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
  52. // ...
  53. // private static XmlSerializer tiiSerializer
  54. // = new XmlSerializer(typeof(Dictionary<LLUUID, TaskInventoryItem>.ValueCollection));
  55. // see IXmlSerializable
  56. public XmlSchema GetSchema()
  57. {
  58. return null;
  59. }
  60. // see IXmlSerializable
  61. public void ReadXml(XmlReader reader)
  62. {
  63. reader.Read();
  64. while (tiiSerializer.CanDeserialize(reader))
  65. {
  66. TaskInventoryItem item = (TaskInventoryItem)tiiSerializer.Deserialize(reader);
  67. Add(item.ItemID, item);
  68. }
  69. // reader.Read();
  70. // while (reader.Name.Equals("TaskInventoryItem"))
  71. // {
  72. // TaskInventoryItem item = (TaskInventoryItem)tiiSerializer.Deserialize(reader);
  73. // Add(item.ItemID, item);
  74. // }
  75. // ICollection<TaskInventoryItem> items
  76. // = (ICollection<TaskInventoryItem>)tiiSerializer.Deserialize(reader);
  77. //
  78. // foreach (TaskInventoryItem item in items)
  79. // {
  80. // Add(item.ItemID, item);
  81. // }
  82. }
  83. // see IXmlSerializable
  84. public void WriteXml(XmlWriter writer)
  85. {
  86. lock (this)
  87. {
  88. foreach (TaskInventoryItem item in Values)
  89. {
  90. tiiSerializer.Serialize(writer, item);
  91. }
  92. }
  93. //tiiSerializer.Serialize(writer, Values);
  94. }
  95. // see ICloneable
  96. public Object Clone()
  97. {
  98. TaskInventoryDictionary clone = new TaskInventoryDictionary();
  99. lock (this)
  100. {
  101. foreach (LLUUID uuid in Keys)
  102. {
  103. clone.Add(uuid, (TaskInventoryItem)this[uuid].Clone());
  104. }
  105. }
  106. return clone;
  107. }
  108. }
  109. /// <summary>
  110. /// Represents an item in a task inventory
  111. /// </summary>
  112. public class TaskInventoryItem : ICloneable
  113. {
  114. /// <summary>
  115. /// XXX This should really be factored out into some constants class.
  116. /// </summary>
  117. private const uint FULL_MASK_PERMISSIONS_GENERAL = 2147483647;
  118. /// <summary>
  119. /// Inventory types
  120. /// </summary>
  121. public static string[] InvTypes = new string[]
  122. {
  123. "texture",
  124. "sound",
  125. String.Empty,
  126. String.Empty,
  127. String.Empty,
  128. String.Empty,
  129. String.Empty,
  130. String.Empty,
  131. String.Empty,
  132. String.Empty,
  133. "lsl_text",
  134. String.Empty
  135. };
  136. /// <summary>
  137. /// Asset types
  138. /// </summary>
  139. public static string[] Types = new string[]
  140. {
  141. "texture",
  142. "sound",
  143. String.Empty,
  144. String.Empty,
  145. String.Empty,
  146. String.Empty,
  147. String.Empty,
  148. String.Empty,
  149. String.Empty,
  150. String.Empty,
  151. "lsltext",
  152. String.Empty
  153. };
  154. public LLUUID ItemID = LLUUID.Zero;
  155. public LLUUID ParentID = LLUUID.Zero; //parent folder id
  156. public uint BaseMask = FULL_MASK_PERMISSIONS_GENERAL;
  157. public uint OwnerMask = FULL_MASK_PERMISSIONS_GENERAL;
  158. public uint GroupMask = FULL_MASK_PERMISSIONS_GENERAL;
  159. public uint EveryoneMask = FULL_MASK_PERMISSIONS_GENERAL;
  160. public uint NextOwnerMask = FULL_MASK_PERMISSIONS_GENERAL;
  161. public LLUUID CreatorID = LLUUID.Zero;
  162. public LLUUID OwnerID = LLUUID.Zero;
  163. public LLUUID LastOwnerID = LLUUID.Zero;
  164. public LLUUID GroupID = LLUUID.Zero;
  165. public LLUUID AssetID = LLUUID.Zero;
  166. public int Type = 0;
  167. public int InvType = 0;
  168. public uint Flags = 0;
  169. public string Name = String.Empty;
  170. public string Description = String.Empty;
  171. public uint CreationDate = 0;
  172. public LLUUID ParentPartID = LLUUID.Zero;
  173. /// <summary>
  174. /// Reset the LLUUIDs for this item.
  175. /// </summary>
  176. /// <param name="partID">The new part ID to which this item belongs</param>
  177. public void ResetIDs(LLUUID partID)
  178. {
  179. ItemID = LLUUID.Random();
  180. ParentPartID = partID;
  181. }
  182. // See ICloneable
  183. public Object Clone()
  184. {
  185. return MemberwiseClone();
  186. }
  187. }
  188. }