corrade-vassal – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * Copyright (c) 2006-2014, openmetaverse.org
3 * All rights reserved.
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 *
8 * - Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 * - Neither the name of the openmetaverse.org nor the names
11 * of its contributors may be used to endorse or promote products derived from
12 * this software without specific prior written permission.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
25 */
26  
27 using System;
28 using System.Collections.Generic;
29 using System.Text;
30 using System.Runtime.Serialization;
31  
32 namespace OpenMetaverse
33 {
34 [Serializable()]
35 public class InventoryNode : ISerializable
36 {
37 private InventoryBase data;
38 private InventoryNode parent;
39 private UUID parentID; //used for de-seralization
40 private InventoryNodeDictionary nodes;
41 private bool needsUpdate = true;
42 [NonSerialized]
43 private object tag;
44  
45 /// <summary></summary>
46 public InventoryBase Data
47 {
48 get { return data; }
49 set { data = value; }
50 }
51  
52 /// <summary>User data</summary>
53 public object Tag
54 {
55 get { return tag; }
56 set { tag = value; }
57 }
58  
59 /// <summary></summary>
60 public InventoryNode Parent
61 {
62 get { return parent; }
63 set { parent = value; }
64 }
65  
66 /// <summary></summary>
67 public UUID ParentID
68 {
69 get { return parentID; }
70 }
71  
72 /// <summary></summary>
73 public InventoryNodeDictionary Nodes
74 {
75 get
76 {
77 if (nodes == null)
78 nodes = new InventoryNodeDictionary(this);
79  
80 return nodes;
81 }
82 set { nodes = value; }
83 }
84  
85  
86 public System.DateTime ModifyTime
87 {
88 get
89 {
90 if (Data is InventoryItem)
91 {
92 return ((InventoryItem)Data).CreationDate;
93 }
94 DateTime newest = default(DateTime);//.MinValue;
95 if (Data is InventoryFolder)
96 {
97 foreach (var node in Nodes.Values)
98 {
99 var t = node.ModifyTime;
100 if (t > newest) newest = t;
101 }
102 }
103 return newest;
104 }
105 }
106 public void Sort()
107 {
108 Nodes.Sort();
109 }
110  
111 /// <summary>
112 /// For inventory folder nodes specifies weather the folder needs to be
113 /// refreshed from the server
114 /// </summary>
115 public bool NeedsUpdate
116 {
117 get { return needsUpdate; }
118 set { needsUpdate = value; }
119 }
120  
121 /// <summary>
122 ///
123 /// </summary>
124 public InventoryNode()
125 {
126 }
127  
128 /// <summary>
129 ///
130 /// </summary>
131 /// <param name="data"></param>
132 public InventoryNode(InventoryBase data)
133 {
134 this.data = data;
135 }
136  
137 /// <summary>
138 /// De-serialization constructor for the InventoryNode Class
139 /// </summary>
140 public InventoryNode(InventoryBase data, InventoryNode parent)
141 {
142 this.data = data;
143 this.parent = parent;
144  
145 if (parent != null)
146 {
147 // Add this node to the collection of parent nodes
148 lock (parent.Nodes.SyncRoot) parent.Nodes.Add(data.UUID, this);
149 }
150 }
151  
152 /// <summary>
153 /// Serialization handler for the InventoryNode Class
154 /// </summary>
155 public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
156 {
157 if(parent!=null)
158 info.AddValue("Parent", parent.Data.UUID, typeof(UUID)); //We need to track the parent UUID for de-serialization
159 else
160 info.AddValue("Parent", UUID.Zero, typeof(UUID));
161  
162 info.AddValue("Type", data.GetType(), typeof(Type));
163  
164 data.GetObjectData(info, ctxt);
165 }
166  
167 /// <summary>
168 /// De-serialization handler for the InventoryNode Class
169 /// </summary>
170 public InventoryNode(SerializationInfo info, StreamingContext ctxt)
171 {
172 parentID = (UUID)info.GetValue("Parent", typeof(UUID));
173 Type type = (Type)info.GetValue("Type", typeof(Type));
174  
175 // Construct a new inventory object based on the Type stored in Type
176 System.Reflection.ConstructorInfo ctr = type.GetConstructor(new Type[] {typeof(SerializationInfo),typeof(StreamingContext)});
177 data = (InventoryBase) ctr.Invoke(new Object[] { info, ctxt });
178 }
179  
180 /// <summary>
181 ///
182 /// </summary>
183 /// <returns></returns>
184 public override string ToString()
185 {
186 if (this.Data == null) return "[Empty Node]";
187 return this.Data.ToString();
188 }
189 }
190 }