TaskInventoryItem.cs 7.4 KB

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