AssetBase.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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 OpenSimulator 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.Xml.Serialization;
  29. using OpenMetaverse;
  30. namespace OpenSim.Framework
  31. {
  32. [Serializable]
  33. public class AssetBase
  34. {
  35. private byte[] m_data;
  36. private AssetMetadata m_metadata;
  37. public AssetBase()
  38. {
  39. m_metadata = new AssetMetadata();
  40. }
  41. public AssetBase(UUID assetId, string name)
  42. {
  43. m_metadata = new AssetMetadata();
  44. m_metadata.FullID = assetId;
  45. m_metadata.Name = name;
  46. }
  47. public bool ContainsReferences
  48. {
  49. get
  50. {
  51. return
  52. IsTextualAsset && (
  53. Type != (sbyte)AssetType.Notecard
  54. && Type != (sbyte)AssetType.CallingCard
  55. && Type != (sbyte)AssetType.LSLText
  56. && Type != (sbyte)AssetType.Landmark);
  57. }
  58. }
  59. public bool IsTextualAsset
  60. {
  61. get
  62. {
  63. return !IsBinaryAsset;
  64. }
  65. }
  66. public bool IsBinaryAsset
  67. {
  68. get
  69. {
  70. return
  71. (Type == (sbyte) AssetType.Animation ||
  72. Type == (sbyte)AssetType.Gesture ||
  73. Type == (sbyte)AssetType.Simstate ||
  74. Type == (sbyte)AssetType.Unknown ||
  75. Type == (sbyte)AssetType.Object ||
  76. Type == (sbyte)AssetType.Sound ||
  77. Type == (sbyte)AssetType.SoundWAV ||
  78. Type == (sbyte)AssetType.Texture ||
  79. Type == (sbyte)AssetType.TextureTGA ||
  80. Type == (sbyte)AssetType.Folder ||
  81. Type == (sbyte)AssetType.RootFolder ||
  82. Type == (sbyte)AssetType.LostAndFoundFolder ||
  83. Type == (sbyte)AssetType.SnapshotFolder ||
  84. Type == (sbyte)AssetType.TrashFolder ||
  85. Type == (sbyte)AssetType.ImageJPEG ||
  86. Type == (sbyte) AssetType.ImageTGA ||
  87. Type == (sbyte) AssetType.LSLBytecode);
  88. }
  89. }
  90. public virtual byte[] Data
  91. {
  92. get { return m_data; }
  93. set { m_data = value; }
  94. }
  95. public UUID FullID
  96. {
  97. get { return m_metadata.FullID; }
  98. set { m_metadata.FullID = value; }
  99. }
  100. public string ID
  101. {
  102. get { return m_metadata.ID; }
  103. set { m_metadata.ID = value; }
  104. }
  105. public string Name
  106. {
  107. get { return m_metadata.Name; }
  108. set { m_metadata.Name = value; }
  109. }
  110. public string Description
  111. {
  112. get { return m_metadata.Description; }
  113. set { m_metadata.Description = value; }
  114. }
  115. public sbyte Type
  116. {
  117. get { return m_metadata.Type; }
  118. set { m_metadata.Type = value; }
  119. }
  120. public bool Local
  121. {
  122. get { return m_metadata.Local; }
  123. set { m_metadata.Local = value; }
  124. }
  125. public bool Temporary
  126. {
  127. get { return m_metadata.Temporary; }
  128. set { m_metadata.Temporary = value; }
  129. }
  130. [XmlIgnore]
  131. public AssetMetadata Metadata
  132. {
  133. get { return m_metadata; }
  134. set { m_metadata = value; }
  135. }
  136. public override string ToString()
  137. {
  138. return FullID.ToString();
  139. }
  140. }
  141. [Serializable]
  142. public class AssetMetadata
  143. {
  144. private UUID m_fullid;
  145. // m_id added as a dirty hack to transition from FullID to ID
  146. private string m_id;
  147. private string m_name = String.Empty;
  148. private string m_description = String.Empty;
  149. private DateTime m_creation_date;
  150. private sbyte m_type;
  151. private string m_content_type;
  152. private byte[] m_sha1;
  153. private bool m_local = false;
  154. private bool m_temporary = false;
  155. //private Dictionary<string, Uri> m_methods = new Dictionary<string, Uri>();
  156. //private OSDMap m_extra_data;
  157. public UUID FullID
  158. {
  159. get { return m_fullid; }
  160. set { m_fullid = value; m_id = m_fullid.ToString(); }
  161. }
  162. public string ID
  163. {
  164. //get { return m_fullid.ToString(); }
  165. //set { m_fullid = new UUID(value); }
  166. get { return m_id; }
  167. set
  168. {
  169. UUID uuid = UUID.Zero;
  170. if (UUID.TryParse(value, out uuid))
  171. {
  172. m_fullid = uuid;
  173. m_id = m_fullid.ToString();
  174. }
  175. else
  176. m_id = value;
  177. }
  178. }
  179. public string Name
  180. {
  181. get { return m_name; }
  182. set { m_name = value; }
  183. }
  184. public string Description
  185. {
  186. get { return m_description; }
  187. set { m_description = value; }
  188. }
  189. public DateTime CreationDate
  190. {
  191. get { return m_creation_date; }
  192. set { m_creation_date = value; }
  193. }
  194. public sbyte Type
  195. {
  196. get { return m_type; }
  197. set { m_type = value; }
  198. }
  199. public string ContentType
  200. {
  201. get { return m_content_type; }
  202. set { m_content_type = value; }
  203. }
  204. public byte[] SHA1
  205. {
  206. get { return m_sha1; }
  207. set { m_sha1 = value; }
  208. }
  209. public bool Local
  210. {
  211. get { return m_local; }
  212. set { m_local = value; }
  213. }
  214. public bool Temporary
  215. {
  216. get { return m_temporary; }
  217. set { m_temporary = value; }
  218. }
  219. //public Dictionary<string, Uri> Methods
  220. //{
  221. // get { return m_methods; }
  222. // set { m_methods = value; }
  223. //}
  224. //public OSDMap ExtraData
  225. //{
  226. // get { return m_extra_data; }
  227. // set { m_extra_data = value; }
  228. //}
  229. }
  230. }