diff options
author | Justin Clarke Casey | 2009-04-23 20:15:05 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2009-04-23 20:15:05 +0000 |
commit | 1ccc99a3f9d96fbdea478be7e7df427a9e5377a7 (patch) | |
tree | 713222af91ebef24e5604efffc9e6b1c68a7700b /OpenSim/Region/CoreModules | |
parent | * Allow interested user data plugins to store temporary user profiles (diff) | |
download | opensim-SC-1ccc99a3f9d96fbdea478be7e7df427a9e5377a7.zip opensim-SC-1ccc99a3f9d96fbdea478be7e7df427a9e5377a7.tar.gz opensim-SC-1ccc99a3f9d96fbdea478be7e7df427a9e5377a7.tar.bz2 opensim-SC-1ccc99a3f9d96fbdea478be7e7df427a9e5377a7.tar.xz |
* refactor: move archive user inventory item serialization out to a separate file
Diffstat (limited to 'OpenSim/Region/CoreModules')
4 files changed, 87 insertions, 148 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs index 8732e2e..2d6187f 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs | |||
@@ -36,6 +36,7 @@ using log4net; | |||
36 | using OpenMetaverse; | 36 | using OpenMetaverse; |
37 | using OpenSim.Framework; | 37 | using OpenSim.Framework; |
38 | using OpenSim.Framework.Serialization; | 38 | using OpenSim.Framework.Serialization; |
39 | using OpenSim.Framework.Serialization.External; | ||
39 | using OpenSim.Framework.Communications; | 40 | using OpenSim.Framework.Communications; |
40 | using OpenSim.Framework.Communications.Cache; | 41 | using OpenSim.Framework.Communications.Cache; |
41 | using OpenSim.Region.CoreModules.World.Archiver; | 42 | using OpenSim.Region.CoreModules.World.Archiver; |
@@ -78,71 +79,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
78 | this.commsManager = commsManager; | 79 | this.commsManager = commsManager; |
79 | } | 80 | } |
80 | 81 | ||
81 | protected InventoryItemBase LoadInvItem(string contents) | ||
82 | { | ||
83 | InventoryItemBase item = new InventoryItemBase(); | ||
84 | StringReader sr = new StringReader(contents); | ||
85 | XmlTextReader reader = new XmlTextReader(sr); | ||
86 | |||
87 | if (contents.Equals("")) return null; | ||
88 | |||
89 | reader.ReadStartElement("InventoryItem"); | ||
90 | reader.ReadStartElement("Name"); | ||
91 | item.Name = reader.ReadString(); | ||
92 | reader.ReadEndElement(); | ||
93 | reader.ReadStartElement("ID"); | ||
94 | item.ID = UUID.Parse(reader.ReadString()); | ||
95 | reader.ReadEndElement(); | ||
96 | reader.ReadStartElement("InvType"); | ||
97 | item.InvType = Convert.ToInt32(reader.ReadString()); | ||
98 | reader.ReadEndElement(); | ||
99 | reader.ReadStartElement("CreatorUUID"); | ||
100 | item.CreatorId = reader.ReadString(); | ||
101 | reader.ReadEndElement(); | ||
102 | reader.ReadStartElement("CreationDate"); | ||
103 | item.CreationDate = Convert.ToInt32(reader.ReadString()); | ||
104 | reader.ReadEndElement(); | ||
105 | reader.ReadStartElement("Owner"); | ||
106 | item.Owner = UUID.Parse(reader.ReadString()); | ||
107 | reader.ReadEndElement(); | ||
108 | reader.ReadElementString("Description"); | ||
109 | reader.ReadStartElement("AssetType"); | ||
110 | item.AssetType = Convert.ToInt32(reader.ReadString()); | ||
111 | reader.ReadEndElement(); | ||
112 | reader.ReadStartElement("AssetID"); | ||
113 | item.AssetID = UUID.Parse(reader.ReadString()); | ||
114 | reader.ReadEndElement(); | ||
115 | reader.ReadStartElement("SaleType"); | ||
116 | item.SaleType = Convert.ToByte(reader.ReadString()); | ||
117 | reader.ReadEndElement(); | ||
118 | reader.ReadStartElement("SalePrice"); | ||
119 | item.SalePrice = Convert.ToInt32(reader.ReadString()); | ||
120 | reader.ReadEndElement(); | ||
121 | reader.ReadStartElement("BasePermissions"); | ||
122 | item.BasePermissions = Convert.ToUInt32(reader.ReadString()); | ||
123 | reader.ReadEndElement(); | ||
124 | reader.ReadStartElement("CurrentPermissions"); | ||
125 | item.CurrentPermissions = Convert.ToUInt32(reader.ReadString()); | ||
126 | reader.ReadEndElement(); | ||
127 | reader.ReadStartElement("EveryOnePermssions"); | ||
128 | item.EveryOnePermissions = Convert.ToUInt32(reader.ReadString()); | ||
129 | reader.ReadEndElement(); | ||
130 | reader.ReadStartElement("NextPermissions"); | ||
131 | item.NextPermissions = Convert.ToUInt32(reader.ReadString()); | ||
132 | reader.ReadEndElement(); | ||
133 | reader.ReadStartElement("Flags"); | ||
134 | item.Flags = Convert.ToUInt32(reader.ReadString()); | ||
135 | reader.ReadEndElement(); | ||
136 | reader.ReadStartElement("GroupID"); | ||
137 | item.GroupID = UUID.Parse(reader.ReadString()); | ||
138 | reader.ReadEndElement(); | ||
139 | reader.ReadStartElement("GroupOwned"); | ||
140 | item.GroupOwned = Convert.ToBoolean(reader.ReadString()); | ||
141 | reader.ReadEndElement(); | ||
142 | |||
143 | return item; | ||
144 | } | ||
145 | |||
146 | /// <summary> | 82 | /// <summary> |
147 | /// Execute the request | 83 | /// Execute the request |
148 | /// </summary> | 84 | /// </summary> |
@@ -322,27 +258,24 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
322 | 258 | ||
323 | if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType) | 259 | if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType) |
324 | { | 260 | { |
325 | InventoryItemBase item = LoadInvItem(m_asciiEncoding.GetString(data)); | 261 | InventoryItemBase item = UserInventoryItemSerializer.Deserialize(data); |
262 | |||
263 | // Don't use the item ID that's in the file | ||
264 | item.ID = UUID.Random(); | ||
326 | 265 | ||
327 | if (item != null) | 266 | item.CreatorId = m_userInfo.UserProfile.ID.ToString(); |
328 | { | 267 | item.Owner = m_userInfo.UserProfile.ID; |
329 | // Don't use the item ID that's in the file | ||
330 | item.ID = UUID.Random(); | ||
331 | |||
332 | item.CreatorId = m_userInfo.UserProfile.ID.ToString(); | ||
333 | item.Owner = m_userInfo.UserProfile.ID; | ||
334 | 268 | ||
335 | // Reset folder ID to the one in which we want to load it | 269 | // Reset folder ID to the one in which we want to load it |
336 | item.Folder = foundFolder.ID; | 270 | item.Folder = foundFolder.ID; |
337 | 271 | ||
338 | m_userInfo.AddItem(item); | 272 | m_userInfo.AddItem(item); |
339 | successfulItemRestores++; | 273 | successfulItemRestores++; |
340 | 274 | ||
341 | // If we're loading an item directly into the given destination folder then we need to record | 275 | // If we're loading an item directly into the given destination folder then we need to record |
342 | // it separately from any loaded root folders | 276 | // it separately from any loaded root folders |
343 | if (rootDestinationFolder == foundFolder) | 277 | if (rootDestinationFolder == foundFolder) |
344 | nodesLoaded.Add(item); | 278 | nodesLoaded.Add(item); |
345 | } | ||
346 | } | 279 | } |
347 | } | 280 | } |
348 | } | 281 | } |
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs index f302696..833b64a 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs | |||
@@ -123,71 +123,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
123 | 123 | ||
124 | protected void SaveInvItem(InventoryItemBase inventoryItem, string path) | 124 | protected void SaveInvItem(InventoryItemBase inventoryItem, string path) |
125 | { | 125 | { |
126 | string filename = string.Format("{0}{1}_{2}.xml", path, inventoryItem.Name, inventoryItem.ID); | 126 | string filename = string.Format("{0}{1}_{2}.xml", path, inventoryItem.Name, inventoryItem.ID); |
127 | StringWriter sw = new StringWriter(); | 127 | string serialization = UserInventoryItemSerializer.Serialize(inventoryItem); |
128 | XmlTextWriter writer = new XmlTextWriter(sw); | 128 | m_archive.WriteFile(filename, serialization); |
129 | writer.Formatting = Formatting.Indented; | ||
130 | |||
131 | writer.WriteStartElement("InventoryItem"); | ||
132 | |||
133 | writer.WriteStartElement("Name"); | ||
134 | writer.WriteString(inventoryItem.Name); | ||
135 | writer.WriteEndElement(); | ||
136 | writer.WriteStartElement("ID"); | ||
137 | writer.WriteString(inventoryItem.ID.ToString()); | ||
138 | writer.WriteEndElement(); | ||
139 | writer.WriteStartElement("InvType"); | ||
140 | writer.WriteString(inventoryItem.InvType.ToString()); | ||
141 | writer.WriteEndElement(); | ||
142 | writer.WriteStartElement("CreatorUUID"); | ||
143 | writer.WriteString(inventoryItem.CreatorId); | ||
144 | writer.WriteEndElement(); | ||
145 | writer.WriteStartElement("CreationDate"); | ||
146 | writer.WriteString(inventoryItem.CreationDate.ToString()); | ||
147 | writer.WriteEndElement(); | ||
148 | writer.WriteStartElement("Owner"); | ||
149 | writer.WriteString(inventoryItem.Owner.ToString()); | ||
150 | writer.WriteEndElement(); | ||
151 | writer.WriteStartElement("Description"); | ||
152 | writer.WriteString(inventoryItem.Description); | ||
153 | writer.WriteEndElement(); | ||
154 | writer.WriteStartElement("AssetType"); | ||
155 | writer.WriteString(inventoryItem.AssetType.ToString()); | ||
156 | writer.WriteEndElement(); | ||
157 | writer.WriteStartElement("AssetID"); | ||
158 | writer.WriteString(inventoryItem.AssetID.ToString()); | ||
159 | writer.WriteEndElement(); | ||
160 | writer.WriteStartElement("SaleType"); | ||
161 | writer.WriteString(inventoryItem.SaleType.ToString()); | ||
162 | writer.WriteEndElement(); | ||
163 | writer.WriteStartElement("SalePrice"); | ||
164 | writer.WriteString(inventoryItem.SalePrice.ToString()); | ||
165 | writer.WriteEndElement(); | ||
166 | writer.WriteStartElement("BasePermissions"); | ||
167 | writer.WriteString(inventoryItem.BasePermissions.ToString()); | ||
168 | writer.WriteEndElement(); | ||
169 | writer.WriteStartElement("CurrentPermissions"); | ||
170 | writer.WriteString(inventoryItem.CurrentPermissions.ToString()); | ||
171 | writer.WriteEndElement(); | ||
172 | writer.WriteStartElement("EveryOnePermssions"); | ||
173 | writer.WriteString(inventoryItem.EveryOnePermissions.ToString()); | ||
174 | writer.WriteEndElement(); | ||
175 | writer.WriteStartElement("NextPermissions"); | ||
176 | writer.WriteString(inventoryItem.NextPermissions.ToString()); | ||
177 | writer.WriteEndElement(); | ||
178 | writer.WriteStartElement("Flags"); | ||
179 | writer.WriteString(inventoryItem.Flags.ToString()); | ||
180 | writer.WriteEndElement(); | ||
181 | writer.WriteStartElement("GroupID"); | ||
182 | writer.WriteString(inventoryItem.GroupID.ToString()); | ||
183 | writer.WriteEndElement(); | ||
184 | writer.WriteStartElement("GroupOwned"); | ||
185 | writer.WriteString(inventoryItem.GroupOwned.ToString()); | ||
186 | writer.WriteEndElement(); | ||
187 | |||
188 | writer.WriteEndElement(); | ||
189 | |||
190 | m_archive.WriteFile(filename, sw.ToString()); | ||
191 | 129 | ||
192 | UUID creatorId = inventoryItem.CreatorIdAsUuid; | 130 | UUID creatorId = inventoryItem.CreatorIdAsUuid; |
193 | 131 | ||
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs index 8e6b461..e471160 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs | |||
@@ -188,5 +188,73 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
188 | 188 | ||
189 | // TODO: Test presence of more files and contents of files. | 189 | // TODO: Test presence of more files and contents of files. |
190 | } | 190 | } |
191 | |||
192 | /* | ||
193 | /// <summary> | ||
194 | /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet). | ||
195 | /// </summary> | ||
196 | [Test] | ||
197 | public void TestLoadIarV0p1() | ||
198 | { | ||
199 | //log4net.Config.XmlConfigurator.Configure(); | ||
200 | |||
201 | MemoryStream archiveWriteStream = new MemoryStream(); | ||
202 | TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream); | ||
203 | |||
204 | string item1FileName = string.Format("{0}{1}/{2}", INVENTORY_PATH, "a", "b.lsl"); | ||
205 | tar.WriteFile(item1FileName, item1. | ||
206 | |||
207 | string part1Name = "object1"; | ||
208 | PrimitiveBaseShape shape = PrimitiveBaseShape.CreateCylinder(); | ||
209 | Vector3 groupPosition = new Vector3(90, 80, 70); | ||
210 | Quaternion rotationOffset = new Quaternion(60, 70, 80, 90); | ||
211 | Vector3 offsetPosition = new Vector3(20, 25, 30); | ||
212 | |||
213 | SerialiserModule serialiserModule = new SerialiserModule(); | ||
214 | ArchiverModule archiverModule = new ArchiverModule(); | ||
215 | |||
216 | Scene scene = SceneSetupHelpers.SetupScene(); | ||
217 | SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); | ||
218 | |||
219 | SceneObjectPart part1 | ||
220 | = new SceneObjectPart( | ||
221 | UUID.Zero, shape, groupPosition, rotationOffset, offsetPosition); | ||
222 | part1.Name = part1Name; | ||
223 | SceneObjectGroup object1 = new SceneObjectGroup(part1); | ||
224 | scene.AddNewSceneObject(object1, false); | ||
225 | |||
226 | string object1FileName = string.Format( | ||
227 | "{0}_{1:000}-{2:000}-{3:000}__{4}.xml", | ||
228 | part1Name, | ||
229 | Math.Round(groupPosition.X), Math.Round(groupPosition.Y), Math.Round(groupPosition.Z), | ||
230 | part1.UUID); | ||
231 | tar.WriteFile(ArchiveConstants.OBJECTS_PATH + object1FileName, object1.ToXmlString2()); | ||
232 | |||
233 | tar.Close(); | ||
234 | |||
235 | MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); | ||
236 | |||
237 | // SerialiserModule serialiserModule = new SerialiserModule(); | ||
238 | // ArchiverModule archiverModule = new ArchiverModule(); | ||
239 | |||
240 | // Scene scene = SceneSetupHelpers.SetupScene(); | ||
241 | // SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); | ||
242 | |||
243 | archiverModule.DearchiveRegion(archiveReadStream); | ||
244 | |||
245 | SceneObjectPart object1PartLoaded = scene.GetSceneObjectPart(part1Name); | ||
246 | |||
247 | Assert.That(object1PartLoaded, Is.Not.Null, "object1 was not loaded"); | ||
248 | Assert.That(object1PartLoaded.Name, Is.EqualTo(part1Name), "object1 names not identical"); | ||
249 | Assert.That(object1PartLoaded.GroupPosition, Is.EqualTo(groupPosition), "object1 group position not equal"); | ||
250 | Assert.That( | ||
251 | object1PartLoaded.RotationOffset, Is.EqualTo(rotationOffset), "object1 rotation offset not equal"); | ||
252 | Assert.That( | ||
253 | object1PartLoaded.OffsetPosition, Is.EqualTo(offsetPosition), "object1 offset position not equal"); | ||
254 | |||
255 | // Temporary | ||
256 | Console.WriteLine("Successfully completed {0}", MethodBase.GetCurrentMethod()); | ||
257 | } | ||
258 | */ | ||
191 | } | 259 | } |
192 | } | 260 | } |
diff --git a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs index a25b25f..323d62b 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs | |||
@@ -44,7 +44,7 @@ using OpenSim.Tests.Common.Setup; | |||
44 | 44 | ||
45 | namespace OpenSim.Region.CoreModules.World.Archiver.Tests | 45 | namespace OpenSim.Region.CoreModules.World.Archiver.Tests |
46 | { | 46 | { |
47 | [TestFixture, LongRunning] | 47 | [TestFixture] |
48 | public class ArchiverTests | 48 | public class ArchiverTests |
49 | { | 49 | { |
50 | private Guid m_lastRequestId; | 50 | private Guid m_lastRequestId; |