aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Serialization/External
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-02-03 22:21:54 +0000
committerJustin Clark-Casey (justincc)2012-02-03 22:21:54 +0000
commitf17066b7bf27c22448d883e0af9d20a42f671b62 (patch)
treec1b4fed29d33d2055dd990fd53c616a8fe1e8f60 /OpenSim/Framework/Serialization/External
parentCorrected console help texts for "save iar" (diff)
downloadopensim-SC_OLD-f17066b7bf27c22448d883e0af9d20a42f671b62.zip
opensim-SC_OLD-f17066b7bf27c22448d883e0af9d20a42f671b62.tar.gz
opensim-SC_OLD-f17066b7bf27c22448d883e0af9d20a42f671b62.tar.bz2
opensim-SC_OLD-f17066b7bf27c22448d883e0af9d20a42f671b62.tar.xz
Change LandDataSerializer deserialization so that in the future it won't care about extra elements or element order.
This brings it into line with other deserializations such as object and will improve future backward compatibility.
Diffstat (limited to 'OpenSim/Framework/Serialization/External')
-rw-r--r--OpenSim/Framework/Serialization/External/LandDataSerializer.cs237
-rw-r--r--OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs3
-rw-r--r--OpenSim/Framework/Serialization/External/UserProfileSerializer.cs5
3 files changed, 182 insertions, 63 deletions
diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs
index 3ae9a8e..bf6c4e5 100644
--- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs
+++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs
@@ -28,8 +28,10 @@
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.IO; 30using System.IO;
31using System.Reflection;
31using System.Text; 32using System.Text;
32using System.Xml; 33using System.Xml;
34using log4net;
33using OpenMetaverse; 35using OpenMetaverse;
34using OpenSim.Framework; 36using OpenSim.Framework;
35 37
@@ -40,8 +42,152 @@ namespace OpenSim.Framework.Serialization.External
40 /// </summary> 42 /// </summary>
41 public class LandDataSerializer 43 public class LandDataSerializer
42 { 44 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46
43 protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding(); 47 protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding();
44 48
49 private delegate void LandDataProcessor(LandData landData, XmlTextReader reader);
50 private static Dictionary<string, LandDataProcessor> m_ldProcessors
51 = new Dictionary<string, LandDataProcessor>();
52
53 private delegate void LandAccessEntryProcessor(LandAccessEntry lae, XmlTextReader reader);
54 private static Dictionary<string, LandAccessEntryProcessor> m_laeProcessors
55 = new Dictionary<string, LandAccessEntryProcessor>();
56
57 static LandDataSerializer()
58 {
59 // LandData processors
60 m_ldProcessors.Add(
61 "Area", (ld, xtr) => ld.Area = Convert.ToInt32(xtr.ReadElementString("Area")));
62 m_ldProcessors.Add(
63 "AuctionID", (ld, xtr) => ld.AuctionID = Convert.ToUInt32(xtr.ReadElementString("AuctionID")));
64 m_ldProcessors.Add(
65 "AuthBuyerID", (ld, xtr) => ld.AuthBuyerID = UUID.Parse(xtr.ReadElementString("AuthBuyerID")));
66 m_ldProcessors.Add(
67 "Category", (ld, xtr) => ld.Category = (ParcelCategory)Convert.ToSByte(xtr.ReadElementString("Category")));
68 m_ldProcessors.Add(
69 "ClaimDate", (ld, xtr) => ld.ClaimDate = Convert.ToInt32(xtr.ReadElementString("ClaimDate")));
70 m_ldProcessors.Add(
71 "ClaimPrice", (ld, xtr) => ld.ClaimPrice = Convert.ToInt32(xtr.ReadElementString("ClaimPrice")));
72 m_ldProcessors.Add(
73 "GlobalID", (ld, xtr) => ld.GlobalID = UUID.Parse(xtr.ReadElementString("GlobalID")));
74 m_ldProcessors.Add(
75 "GroupID", (ld, xtr) => ld.GroupID = UUID.Parse(xtr.ReadElementString("GroupID")));
76 m_ldProcessors.Add(
77 "IsGroupOwned", (ld, xtr) => ld.IsGroupOwned = Convert.ToBoolean(xtr.ReadElementString("IsGroupOwned")));
78 m_ldProcessors.Add(
79 "Bitmap", (ld, xtr) => ld.Bitmap = Convert.FromBase64String(xtr.ReadElementString("Bitmap")));
80 m_ldProcessors.Add(
81 "Description", (ld, xtr) => ld.Description = xtr.ReadElementString("Description"));
82 m_ldProcessors.Add(
83 "Flags", (ld, xtr) => ld.Flags = Convert.ToUInt32(xtr.ReadElementString("Flags")));
84 m_ldProcessors.Add(
85 "LandingType", (ld, xtr) => ld.LandingType = Convert.ToByte(xtr.ReadElementString("LandingType")));
86 m_ldProcessors.Add(
87 "Name", (ld, xtr) => ld.Name = xtr.ReadElementString("Name"));
88 m_ldProcessors.Add(
89 "Status", (ld, xtr) => ld.Status = (ParcelStatus)Convert.ToSByte(xtr.ReadElementString("Status")));
90 m_ldProcessors.Add(
91 "LocalID", (ld, xtr) => ld.LocalID = Convert.ToInt32(xtr.ReadElementString("LocalID")));
92 m_ldProcessors.Add(
93 "MediaAutoScale", (ld, xtr) => ld.MediaAutoScale = Convert.ToByte(xtr.ReadElementString("MediaAutoScale")));
94 m_ldProcessors.Add(
95 "MediaID", (ld, xtr) => ld.MediaID = UUID.Parse(xtr.ReadElementString("MediaID")));
96 m_ldProcessors.Add(
97 "MediaURL", (ld, xtr) => ld.MediaURL = xtr.ReadElementString("MediaURL"));
98 m_ldProcessors.Add(
99 "MusicURL", (ld, xtr) => ld.MusicURL = xtr.ReadElementString("MusicURL"));
100
101 m_ldProcessors.Add(
102 "ParcelAccessList", ProcessParcelAccessList);
103
104 m_ldProcessors.Add(
105 "PassHours", (ld, xtr) => ld.PassHours = Convert.ToSingle(xtr.ReadElementString("PassHours")));
106 m_ldProcessors.Add(
107 "PassPrice", (ld, xtr) => ld.PassPrice = Convert.ToInt32(xtr.ReadElementString("PassPrice")));
108 m_ldProcessors.Add(
109 "SalePrice", (ld, xtr) => ld.SalePrice = Convert.ToInt32(xtr.ReadElementString("SalePrice")));
110 m_ldProcessors.Add(
111 "SnapshotID", (ld, xtr) => ld.SnapshotID = UUID.Parse(xtr.ReadElementString("SnapshotID")));
112 m_ldProcessors.Add(
113 "UserLocation", (ld, xtr) => ld.UserLocation = Vector3.Parse(xtr.ReadElementString("UserLocation")));
114 m_ldProcessors.Add(
115 "UserLookAt", (ld, xtr) => ld.UserLookAt = Vector3.Parse(xtr.ReadElementString("UserLookAt")));
116
117 // No longer used here //
118 // m_ldProcessors.Add("Dwell", (landData, xtr) => return);
119
120 m_ldProcessors.Add(
121 "OtherCleanTime", (ld, xtr) => ld.OtherCleanTime = Convert.ToInt32(xtr.ReadElementString("OtherCleanTime")));
122
123 // LandAccessEntryProcessors
124 m_laeProcessors.Add(
125 "AgentID", (lae, xtr) => lae.AgentID = UUID.Parse(xtr.ReadElementString("AgentID")));
126 m_laeProcessors.Add(
127 "Time", (lae, xtr) =>
128 {
129 // We really don't care about temp vs perm here and this
130 // would break on old oars. Assume all bans are perm
131 xtr.ReadElementString("Time");
132 lae.Expires = 0; // Convert.ToUint( xtr.ReadElementString("Time"));
133 }
134 );
135 m_laeProcessors.Add(
136 "AccessList", (lae, xtr) => lae.Flags = (AccessList)Convert.ToUInt32(xtr.ReadElementString("AccessList")));
137 }
138
139 public static void ProcessParcelAccessList(LandData ld, XmlTextReader xtr)
140 {
141 if (!xtr.IsEmptyElement)
142 {
143 while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement)
144 {
145 LandAccessEntry lae = new LandAccessEntry();
146
147 xtr.ReadStartElement("ParcelAccessEntry");
148
149 string nodeName = string.Empty;
150 while (xtr.NodeType != XmlNodeType.EndElement)
151 {
152 nodeName = xtr.Name;
153
154// m_log.DebugFormat("[LandDataSerializer]: Processing: {0} in ParcelAccessEntry", nodeName);
155
156 LandAccessEntryProcessor p = null;
157 if (m_laeProcessors.TryGetValue(xtr.Name, out p))
158 {
159// m_log.DebugFormat("[LandDataSerializer]: Found {0} processor in ParcelAccessEntry", nodeName);
160
161 try
162 {
163 p(lae, xtr);
164 }
165 catch (Exception e)
166 {
167 m_log.ErrorFormat(
168 "[LandDataSerializer]: Exception while parsing element {0} in ParcelAccessEntry, continuing. Exception {1}{2}",
169 nodeName, e.Message, e.StackTrace);
170
171 if (xtr.NodeType == XmlNodeType.EndElement)
172 xtr.Read();
173 }
174 }
175 else
176 {
177 // m_log.DebugFormat("[LandDataSerializer]: caught unknown element {0}", nodeName);
178 xtr.ReadOuterXml(); // ignore
179 }
180 }
181
182 xtr.ReadEndElement();
183
184 ld.ParcelAccessList.Add(lae);
185 }
186 }
187
188 xtr.Read();
189 }
190
45 /// <summary> 191 /// <summary>
46 /// Reify/deserialize landData 192 /// Reify/deserialize landData
47 /// </summary> 193 /// </summary>
@@ -63,72 +209,43 @@ namespace OpenSim.Framework.Serialization.External
63 { 209 {
64 LandData landData = new LandData(); 210 LandData landData = new LandData();
65 211
66 StringReader sr = new StringReader(serializedLandData); 212 using (XmlTextReader reader = new XmlTextReader(new StringReader(serializedLandData)))
67 XmlTextReader xtr = new XmlTextReader(sr);
68
69 xtr.ReadStartElement("LandData");
70
71 landData.Area = Convert.ToInt32( xtr.ReadElementString("Area"));
72 landData.AuctionID = Convert.ToUInt32( xtr.ReadElementString("AuctionID"));
73 landData.AuthBuyerID = UUID.Parse( xtr.ReadElementString("AuthBuyerID"));
74 landData.Category = (ParcelCategory)Convert.ToSByte( xtr.ReadElementString("Category"));
75 landData.ClaimDate = Convert.ToInt32( xtr.ReadElementString("ClaimDate"));
76 landData.ClaimPrice = Convert.ToInt32( xtr.ReadElementString("ClaimPrice"));
77 landData.GlobalID = UUID.Parse( xtr.ReadElementString("GlobalID"));
78 landData.GroupID = UUID.Parse( xtr.ReadElementString("GroupID"));
79 landData.IsGroupOwned = Convert.ToBoolean( xtr.ReadElementString("IsGroupOwned"));
80 landData.Bitmap = Convert.FromBase64String( xtr.ReadElementString("Bitmap"));
81 landData.Description = xtr.ReadElementString("Description");
82 landData.Flags = Convert.ToUInt32( xtr.ReadElementString("Flags"));
83 landData.LandingType = Convert.ToByte( xtr.ReadElementString("LandingType"));
84 landData.Name = xtr.ReadElementString("Name");
85 landData.Status = (ParcelStatus)Convert.ToSByte( xtr.ReadElementString("Status"));
86 landData.LocalID = Convert.ToInt32( xtr.ReadElementString("LocalID"));
87 landData.MediaAutoScale = Convert.ToByte( xtr.ReadElementString("MediaAutoScale"));
88 landData.MediaID = UUID.Parse( xtr.ReadElementString("MediaID"));
89 landData.MediaURL = xtr.ReadElementString("MediaURL");
90 landData.MusicURL = xtr.ReadElementString("MusicURL");
91 landData.OwnerID = UUID.Parse( xtr.ReadElementString("OwnerID"));
92
93 landData.ParcelAccessList = new List<LandAccessEntry>();
94 xtr.Read();
95 if (xtr.Name != "ParcelAccessList")
96 throw new XmlException(String.Format("Expected \"ParcelAccessList\" element but got \"{0}\"", xtr.Name));
97
98 if (!xtr.IsEmptyElement)
99 { 213 {
100 while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) 214 reader.ReadStartElement("LandData");
101 {
102 LandAccessEntry pae = new LandAccessEntry();
103 215
104 xtr.ReadStartElement("ParcelAccessEntry"); 216 string nodeName = string.Empty;
105 pae.AgentID = UUID.Parse( xtr.ReadElementString("AgentID")); 217 while (reader.NodeType != XmlNodeType.EndElement)
106 // We really don't care about temp vs perm here and this 218 {
107 // would break on old oars. Assume all bans are perm 219 nodeName = reader.Name;
108 xtr.ReadElementString("Time");
109 pae.Expires = 0; // Convert.ToUint( xtr.ReadElementString("Time"));
110 pae.Flags = (AccessList)Convert.ToUInt32( xtr.ReadElementString("AccessList"));
111 xtr.ReadEndElement();
112 220
113 landData.ParcelAccessList.Add(pae); 221// m_log.DebugFormat("[LandDataSerializer]: Processing: {0}", nodeName);
114 }
115 }
116 xtr.Read();
117 222
118 landData.PassHours = Convert.ToSingle( xtr.ReadElementString("PassHours")); 223 LandDataProcessor p = null;
119 landData.PassPrice = Convert.ToInt32( xtr.ReadElementString("PassPrice")); 224 if (m_ldProcessors.TryGetValue(reader.Name, out p))
120 landData.SalePrice = Convert.ToInt32( xtr.ReadElementString("SalePrice")); 225 {
121 landData.SnapshotID = UUID.Parse( xtr.ReadElementString("SnapshotID")); 226 try
122 landData.UserLocation = Vector3.Parse( xtr.ReadElementString("UserLocation")); 227 {
123 landData.UserLookAt = Vector3.Parse( xtr.ReadElementString("UserLookAt")); 228 p(landData, reader);
124 // No longer used here 229 }
125 xtr.ReadElementString("Dwell"); 230 catch (Exception e)
126 landData.OtherCleanTime = Convert.ToInt32( xtr.ReadElementString("OtherCleanTime")); 231 {
232 m_log.ErrorFormat(
233 "[LandDataSerializer]: exception while parsing element {0}, continuing. Exception {1}{2}",
234 nodeName, e.Message, e.StackTrace);
127 235
128 xtr.ReadEndElement(); 236 if (reader.NodeType == XmlNodeType.EndElement)
237 reader.Read();
238 }
239 }
240 else
241 {
242 // m_log.DebugFormat("[LandDataSerializer]: caught unknown element {0}", nodeName);
243 reader.ReadOuterXml(); // ignore
244 }
245 }
129 246
130 xtr.Close(); 247 reader.ReadEndElement();
131 sr.Close(); 248 }
132 249
133 return landData; 250 return landData;
134 } 251 }
diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
index f138437..5d986d5 100644
--- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
+++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
@@ -41,8 +41,7 @@ namespace OpenSim.Framework.Serialization.External
41{ 41{
42 /// <summary> 42 /// <summary>
43 /// Serialize and deserialize user inventory items as an external format. 43 /// Serialize and deserialize user inventory items as an external format.
44 /// </summary> 44 /// </summary>
45 /// XXX: Please do not use yet.
46 public class UserInventoryItemSerializer 45 public class UserInventoryItemSerializer
47 { 46 {
48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
diff --git a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs
index f50b49a..c685a15 100644
--- a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs
+++ b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs
@@ -33,8 +33,11 @@ using OpenSim.Framework;
33namespace OpenSim.Framework.Serialization.External 33namespace OpenSim.Framework.Serialization.External
34{ 34{
35 /// <summary> 35 /// <summary>
36 /// Serialize and deserialize region settings as an external format. 36 /// Serialize and deserialize user profiles as an external format.
37 /// </summary> 37 /// </summary>
38 /// <remarks>
39 /// Currently UNUSED.
40 /// </remarks>
38 public class UserProfileSerializer 41 public class UserProfileSerializer
39 { 42 {
40 public const int MAJOR_VERSION = 0; 43 public const int MAJOR_VERSION = 0;