OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
AssetBase.cs
Go to the documentation of this file.
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 
28 using System;
29 using System.Xml.Serialization;
30 using System.Reflection;
31 using log4net;
32 using OpenMetaverse;
33 
34 namespace OpenSim.Framework
35 {
36  [Flags]
37  public enum AssetFlags : int
38  {
39  Normal = 0, // Immutable asset
40  Maptile = 1, // What it says
41  Rewritable = 2, // Content can be rewritten
42  Collectable = 4 // Can be GC'ed after some time
43  }
44 
48  [Serializable]
49  public class AssetBase
50  {
51  private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52 
53  public static readonly int MAX_ASSET_NAME = 64;
54  public static readonly int MAX_ASSET_DESC = 64;
55 
59  private byte[] m_data;
60 
64  private AssetMetadata m_metadata;
65 
66  private int m_uploadAttempts;
67 
68  // This is needed for .NET serialization!!!
69  // Do NOT "Optimize" away!
70  public AssetBase()
71  {
72  m_metadata = new AssetMetadata();
73  m_metadata.FullID = UUID.Zero;
74  m_metadata.ID = UUID.Zero.ToString();
75  m_metadata.Type = (sbyte)AssetType.Unknown;
76  m_metadata.CreatorID = String.Empty;
77  }
78 
79  public AssetBase(UUID assetID, string name, sbyte assetType, string creatorID)
80  {
81  if (assetType == (sbyte)AssetType.Unknown)
82  {
83  System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(true);
84  m_log.ErrorFormat("[ASSETBASE]: Creating asset '{0}' ({1}) with an unknown asset type\n{2}",
85  name, assetID, trace.ToString());
86  }
87 
88  m_metadata = new AssetMetadata();
89  m_metadata.FullID = assetID;
90  m_metadata.Name = name;
91  m_metadata.Type = assetType;
92  m_metadata.CreatorID = creatorID;
93  }
94 
95  public AssetBase(string assetID, string name, sbyte assetType, string creatorID)
96  {
97  if (assetType == (sbyte)AssetType.Unknown)
98  {
99  System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(true);
100  m_log.ErrorFormat("[ASSETBASE]: Creating asset '{0}' ({1}) with an unknown asset type\n{2}",
101  name, assetID, trace.ToString());
102  }
103 
104  m_metadata = new AssetMetadata();
105  m_metadata.ID = assetID;
106  m_metadata.Name = name;
107  m_metadata.Type = assetType;
108  m_metadata.CreatorID = creatorID;
109  }
110 
111  public bool ContainsReferences
112  {
113  get
114  {
115  return
116  IsTextualAsset && (
117  Type != (sbyte)AssetType.Notecard
118  && Type != (sbyte)AssetType.CallingCard
119  && Type != (sbyte)AssetType.LSLText
120  && Type != (sbyte)AssetType.Landmark);
121  }
122  }
123 
124  public bool IsTextualAsset
125  {
126  get
127  {
128  return !IsBinaryAsset;
129  }
130 
131  }
132 
136  public bool IsBinaryAsset
137  {
138  get
139  {
140  return
141  (Type == (sbyte)AssetType.Animation ||
142  Type == (sbyte)AssetType.Gesture ||
143  Type == (sbyte)AssetType.Simstate ||
144  Type == (sbyte)AssetType.Unknown ||
145  Type == (sbyte)AssetType.Object ||
146  Type == (sbyte)AssetType.Sound ||
147  Type == (sbyte)AssetType.SoundWAV ||
148  Type == (sbyte)AssetType.Texture ||
149  Type == (sbyte)AssetType.TextureTGA ||
150  Type == (sbyte)AssetType.Folder ||
151  Type == (sbyte)AssetType.ImageJPEG ||
152  Type == (sbyte)AssetType.ImageTGA ||
153  Type == (sbyte)AssetType.Mesh ||
154  Type == (sbyte) AssetType.LSLBytecode);
155  }
156  }
157 
158  public virtual byte[] Data
159  {
160  get { return m_data; }
161  set { m_data = value; }
162  }
163 
167  public UUID FullID
168  {
169  get { return m_metadata.FullID; }
170  set { m_metadata.FullID = value; }
171  }
172 
176  public string ID
177  {
178  get { return m_metadata.ID; }
179  set { m_metadata.ID = value; }
180  }
181 
182  public string Name
183  {
184  get { return m_metadata.Name; }
185  set { m_metadata.Name = value; }
186  }
187 
188  public string Description
189  {
190  get { return m_metadata.Description; }
191  set { m_metadata.Description = value; }
192  }
193 
197  public sbyte Type
198  {
199  get { return m_metadata.Type; }
200  set { m_metadata.Type = value; }
201  }
202 
203  public int UploadAttempts
204  {
205  get { return m_uploadAttempts; }
206  set { m_uploadAttempts = value; }
207  }
208 
212  public bool Local
213  {
214  get { return m_metadata.Local; }
215  set { m_metadata.Local = value; }
216  }
217 
221  public bool Temporary
222  {
223  get { return m_metadata.Temporary; }
224  set { m_metadata.Temporary = value; }
225  }
226 
227  public string CreatorID
228  {
229  get { return m_metadata.CreatorID; }
230  set { m_metadata.CreatorID = value; }
231  }
232 
233  public AssetFlags Flags
234  {
235  get { return m_metadata.Flags; }
236  set { m_metadata.Flags = value; }
237  }
238 
239  [XmlIgnore]
240  public AssetMetadata Metadata
241  {
242  get { return m_metadata; }
243  set { m_metadata = value; }
244  }
245 
246  public override string ToString()
247  {
248  return FullID.ToString();
249  }
250  }
251 
252  [Serializable]
253  public class AssetMetadata
254  {
255  private UUID m_fullid;
256  private string m_id;
257  private string m_name = String.Empty;
258  private string m_description = String.Empty;
259  private DateTime m_creation_date;
260  private sbyte m_type = (sbyte)AssetType.Unknown;
261  private string m_content_type;
262  private byte[] m_sha1;
263  private bool m_local;
264  private bool m_temporary;
265  private string m_creatorid;
266  private AssetFlags m_flags;
267 
268  public UUID FullID
269  {
270  get { return m_fullid; }
271  set { m_fullid = value; m_id = m_fullid.ToString(); }
272  }
273 
274  public string ID
275  {
276  //get { return m_fullid.ToString(); }
277  //set { m_fullid = new UUID(value); }
278  get
279  {
280  if (String.IsNullOrEmpty(m_id))
281  m_id = m_fullid.ToString();
282 
283  return m_id;
284  }
285 
286  set
287  {
288  UUID uuid = UUID.Zero;
289  if (UUID.TryParse(value, out uuid))
290  {
291  m_fullid = uuid;
292  m_id = m_fullid.ToString();
293  }
294  else
295  m_id = value;
296  }
297  }
298 
299  public string Name
300  {
301  get { return m_name; }
302  set { m_name = value; }
303  }
304 
305  public string Description
306  {
307  get { return m_description; }
308  set { m_description = value; }
309  }
310 
311  public DateTime CreationDate
312  {
313  get { return m_creation_date; }
314  set { m_creation_date = value; }
315  }
316 
317  public sbyte Type
318  {
319  get { return m_type; }
320  set { m_type = value; }
321  }
322 
323  public string ContentType
324  {
325  get
326  {
327  if (!String.IsNullOrEmpty(m_content_type))
328  return m_content_type;
329  else
330  return SLUtil.SLAssetTypeToContentType(m_type);
331  }
332  set
333  {
334  m_content_type = value;
335 
336  sbyte type = (sbyte)SLUtil.ContentTypeToSLAssetType(value);
337  if (type != -1)
338  m_type = type;
339  }
340  }
341 
342  public byte[] SHA1
343  {
344  get { return m_sha1; }
345  set { m_sha1 = value; }
346  }
347 
348  public bool Local
349  {
350  get { return m_local; }
351  set { m_local = value; }
352  }
353 
354  public bool Temporary
355  {
356  get { return m_temporary; }
357  set { m_temporary = value; }
358  }
359 
360  public string CreatorID
361  {
362  get { return m_creatorid; }
363  set { m_creatorid = value; }
364  }
365 
366  public AssetFlags Flags
367  {
368  get { return m_flags; }
369  set { m_flags = value; }
370  }
371  }
372 }
AssetBase(UUID assetID, string name, sbyte assetType, string creatorID)
Definition: AssetBase.cs:79
AssetBase(string assetID, string name, sbyte assetType, string creatorID)
Definition: AssetBase.cs:95
Asset class. All Assets are reference by this class or a class derived from this class ...
Definition: AssetBase.cs:49
override string ToString()
Definition: AssetBase.cs:246