diff options
author | Justin Clark-Casey (justincc) | 2010-05-21 20:43:11 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2010-05-21 20:43:11 +0100 |
commit | 721c1085da22229f4d40529dd2738a2cf62a91b7 (patch) | |
tree | cae1c731191972cd0bf672bb2e42e312d4239a83 | |
parent | minor: refactor CreateAsset to eliminate dupe code (diff) | |
download | opensim-SC-721c1085da22229f4d40529dd2738a2cf62a91b7.zip opensim-SC-721c1085da22229f4d40529dd2738a2cf62a91b7.tar.gz opensim-SC-721c1085da22229f4d40529dd2738a2cf62a91b7.tar.bz2 opensim-SC-721c1085da22229f4d40529dd2738a2cf62a91b7.tar.xz |
make oar object filename/pathname creation a helper method
reused in both tests and oar code
reduction in checking is outweighed by greater test clarity
Diffstat (limited to '')
5 files changed, 108 insertions, 38 deletions
diff --git a/OpenSim/Framework/Serialization/ArchiveConstants.cs b/OpenSim/Framework/Serialization/ArchiveConstants.cs index 1cd80db..475a9de 100644 --- a/OpenSim/Framework/Serialization/ArchiveConstants.cs +++ b/OpenSim/Framework/Serialization/ArchiveConstants.cs | |||
@@ -25,6 +25,7 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | ||
28 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
29 | using OpenMetaverse; | 30 | using OpenMetaverse; |
30 | 31 | ||
@@ -85,6 +86,11 @@ namespace OpenSim.Framework.Serialization | |||
85 | /// </value> | 86 | /// </value> |
86 | public const string INVENTORY_NODE_NAME_COMPONENT_SEPARATOR = "__"; | 87 | public const string INVENTORY_NODE_NAME_COMPONENT_SEPARATOR = "__"; |
87 | 88 | ||
89 | /// <summary> | ||
90 | /// Template used for creating filenames in OpenSim Archives. | ||
91 | /// </summary> | ||
92 | public const string OAR_OBJECT_FILENAME_TEMPLATE = "{0}_{1:000}-{2:000}-{3:000}__{4}.xml"; | ||
93 | |||
88 | /// <value> | 94 | /// <value> |
89 | /// Extensions used for asset types in the archive | 95 | /// Extensions used for asset types in the archive |
90 | /// </value> | 96 | /// </value> |
@@ -139,5 +145,32 @@ namespace OpenSim.Framework.Serialization | |||
139 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.tga"] = (sbyte)AssetType.TextureTGA; | 145 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.tga"] = (sbyte)AssetType.TextureTGA; |
140 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "trashfolder.txt"] = (sbyte)AssetType.TrashFolder; | 146 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "trashfolder.txt"] = (sbyte)AssetType.TrashFolder; |
141 | } | 147 | } |
148 | |||
149 | /// <summary> | ||
150 | /// Create the filename used to store an object in an OpenSim Archive. | ||
151 | /// </summary> | ||
152 | /// <param name="objectName"></param> | ||
153 | /// <param name="uuid"></param> | ||
154 | /// <param name="pos"></param> | ||
155 | /// <returns></returns> | ||
156 | public static string CreateOarObjectFilename(string objectName, UUID uuid, Vector3 pos) | ||
157 | { | ||
158 | return string.Format( | ||
159 | OAR_OBJECT_FILENAME_TEMPLATE, objectName, | ||
160 | Math.Round(pos.X), Math.Round(pos.Y), Math.Round(pos.Z), | ||
161 | uuid); | ||
162 | } | ||
163 | |||
164 | /// <summary> | ||
165 | /// Create the path used to store an object in an OpenSim Archives. | ||
166 | /// </summary> | ||
167 | /// <param name="objectName"></param> | ||
168 | /// <param name="uuid"></param> | ||
169 | /// <param name="pos"></param> | ||
170 | /// <returns></returns> | ||
171 | public static string CreateOarObjectPath(string objectName, UUID uuid, Vector3 pos) | ||
172 | { | ||
173 | return OBJECTS_PATH + CreateOarObjectFilename(objectName, uuid, pos); | ||
174 | } | ||
142 | } | 175 | } |
143 | } | 176 | } |
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveHelpers.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveHelpers.cs new file mode 100644 index 0000000..880bd7c --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveHelpers.cs | |||
@@ -0,0 +1,64 @@ | |||
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 OpenMetaverse; | ||
29 | using OpenSim.Framework.Serialization; | ||
30 | using OpenSim.Region.Framework.Scenes; | ||
31 | |||
32 | namespace OpenSim.Region.CoreModules.World.Archiver | ||
33 | { | ||
34 | /// <summary> | ||
35 | /// Helper methods for archive manipulation | ||
36 | /// </summary> | ||
37 | /// This is a separate class from ArchiveConstants because we need to bring in very OpenSim specific classes. | ||
38 | public static class ArchiveHelpers | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// Create the filename used for objects in OpenSim Archives. | ||
42 | /// </summary> | ||
43 | /// <param name="objectName"></param> | ||
44 | /// <param name="uuid"></param> | ||
45 | /// <param name="pos"></param> | ||
46 | /// <returns></returns> | ||
47 | public static string CreateObjectFilename(SceneObjectGroup sog) | ||
48 | { | ||
49 | return ArchiveConstants.CreateOarObjectFilename(sog.Name, sog.UUID, sog.AbsolutePosition); | ||
50 | } | ||
51 | |||
52 | /// <summary> | ||
53 | /// Create the path used to store an object in an OpenSim Archive. | ||
54 | /// </summary> | ||
55 | /// <param name="objectName"></param> | ||
56 | /// <param name="uuid"></param> | ||
57 | /// <param name="pos"></param> | ||
58 | /// <returns></returns> | ||
59 | public static string CreateObjectPath(SceneObjectGroup sog) | ||
60 | { | ||
61 | return ArchiveConstants.CreateOarObjectPath(sog.Name, sog.UUID, sog.AbsolutePosition); | ||
62 | } | ||
63 | } | ||
64 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs index c52f029..8d62fe1 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs | |||
@@ -38,7 +38,6 @@ using OpenMetaverse; | |||
38 | using OpenSim.Framework; | 38 | using OpenSim.Framework; |
39 | using OpenSim.Framework.Serialization; | 39 | using OpenSim.Framework.Serialization; |
40 | using OpenSim.Framework.Serialization.External; | 40 | using OpenSim.Framework.Serialization.External; |
41 | |||
42 | using OpenSim.Region.CoreModules.World.Terrain; | 41 | using OpenSim.Region.CoreModules.World.Terrain; |
43 | using OpenSim.Region.Framework.Interfaces; | 42 | using OpenSim.Region.Framework.Interfaces; |
44 | using OpenSim.Region.Framework.Scenes; | 43 | using OpenSim.Region.Framework.Scenes; |
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestExecution.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestExecution.cs index 9fc6ec4..586d98e 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestExecution.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestExecution.cs | |||
@@ -145,17 +145,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
145 | { | 145 | { |
146 | //m_log.DebugFormat("[ARCHIVER]: Saving {0} {1}, {2}", entity.Name, entity.UUID, entity.GetType()); | 146 | //m_log.DebugFormat("[ARCHIVER]: Saving {0} {1}, {2}", entity.Name, entity.UUID, entity.GetType()); |
147 | 147 | ||
148 | Vector3 position = sceneObject.AbsolutePosition; | ||
149 | |||
150 | string serializedObject = m_serialiser.SerializeGroupToXml2(sceneObject); | 148 | string serializedObject = m_serialiser.SerializeGroupToXml2(sceneObject); |
151 | string filename | 149 | m_archiveWriter.WriteFile(ArchiveHelpers.CreateObjectPath(sceneObject), serializedObject); |
152 | = string.Format( | ||
153 | "{0}{1}_{2:000}-{3:000}-{4:000}__{5}.xml", | ||
154 | ArchiveConstants.OBJECTS_PATH, sceneObject.Name, | ||
155 | Math.Round(position.X), Math.Round(position.Y), Math.Round(position.Z), | ||
156 | sceneObject.UUID); | ||
157 | |||
158 | m_archiveWriter.WriteFile(filename, serializedObject); | ||
159 | } | 150 | } |
160 | 151 | ||
161 | m_log.InfoFormat("[ARCHIVER]: Added scene objects to archive."); | 152 | m_log.InfoFormat("[ARCHIVER]: Added scene objects to archive."); |
diff --git a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs index f3e5458..4d04af1 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs | |||
@@ -26,6 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | ||
29 | using System.IO; | 30 | using System.IO; |
30 | using System.Reflection; | 31 | using System.Reflection; |
31 | using System.Threading; | 32 | using System.Threading; |
@@ -129,7 +130,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
129 | //log4net.Config.XmlConfigurator.Configure(); | 130 | //log4net.Config.XmlConfigurator.Configure(); |
130 | 131 | ||
131 | SceneObjectPart part1 = CreateSceneObjectPart1(); | 132 | SceneObjectPart part1 = CreateSceneObjectPart1(); |
132 | m_scene.AddNewSceneObject(new SceneObjectGroup(part1), false); | 133 | SceneObjectGroup sog1 = new SceneObjectGroup(part1); |
134 | m_scene.AddNewSceneObject(sog1, false); | ||
133 | 135 | ||
134 | SceneObjectPart part2 = CreateSceneObjectPart2(); | 136 | SceneObjectPart part2 = CreateSceneObjectPart2(); |
135 | 137 | ||
@@ -169,20 +171,13 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
169 | 171 | ||
170 | bool gotControlFile = false; | 172 | bool gotControlFile = false; |
171 | bool gotNcAssetFile = false; | 173 | bool gotNcAssetFile = false; |
172 | bool gotObject1File = false; | ||
173 | bool gotObject2File = false; | ||
174 | 174 | ||
175 | string expectedNcAssetFileName = string.Format("{0}_{1}", ncAssetUuid, "notecard.txt"); | 175 | string expectedNcAssetFileName = string.Format("{0}_{1}", ncAssetUuid, "notecard.txt"); |
176 | string expectedObject1FileName = string.Format( | 176 | |
177 | "{0}_{1:000}-{2:000}-{3:000}__{4}.xml", | 177 | List<string> foundPaths = new List<string>(); |
178 | part1.Name, | 178 | List<string> expectedPaths = new List<string>(); |
179 | Math.Round(part1.GroupPosition.X), Math.Round(part1.GroupPosition.Y), Math.Round(part1.GroupPosition.Z), | 179 | expectedPaths.Add(ArchiveHelpers.CreateObjectPath(sog1)); |
180 | part1.UUID); | 180 | expectedPaths.Add(ArchiveHelpers.CreateObjectPath(sog2)); |
181 | string expectedObject2FileName = string.Format( | ||
182 | "{0}_{1:000}-{2:000}-{3:000}__{4}.xml", | ||
183 | part2.Name, | ||
184 | Math.Round(part2.GroupPosition.X), Math.Round(part2.GroupPosition.Y), Math.Round(part2.GroupPosition.Z), | ||
185 | part2.UUID); | ||
186 | 181 | ||
187 | string filePath; | 182 | string filePath; |
188 | TarArchiveReader.TarEntryType tarEntryType; | 183 | TarArchiveReader.TarEntryType tarEntryType; |
@@ -202,25 +197,13 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
202 | } | 197 | } |
203 | else if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH)) | 198 | else if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH)) |
204 | { | 199 | { |
205 | string fileName = filePath.Remove(0, ArchiveConstants.OBJECTS_PATH.Length); | 200 | foundPaths.Add(filePath); |
206 | |||
207 | if (fileName.StartsWith(part1.Name)) | ||
208 | { | ||
209 | Assert.That(fileName, Is.EqualTo(expectedObject1FileName)); | ||
210 | gotObject1File = true; | ||
211 | } | ||
212 | else if (fileName.StartsWith(part2.Name)) | ||
213 | { | ||
214 | Assert.That(fileName, Is.EqualTo(expectedObject2FileName)); | ||
215 | gotObject2File = true; | ||
216 | } | ||
217 | } | 201 | } |
218 | } | 202 | } |
219 | 203 | ||
220 | Assert.That(gotControlFile, Is.True, "No control file in archive"); | 204 | Assert.That(gotControlFile, Is.True, "No control file in archive"); |
221 | Assert.That(gotNcAssetFile, Is.True, "No notecard asset file in archive"); | 205 | Assert.That(gotNcAssetFile, Is.True, "No notecard asset file in archive"); |
222 | Assert.That(gotObject1File, Is.True, "No object1 file in archive"); | 206 | Assert.That(foundPaths, Is.EquivalentTo(expectedPaths)); |
223 | Assert.That(gotObject2File, Is.True, "No object2 file in archive"); | ||
224 | 207 | ||
225 | // TODO: Test presence of more files and contents of files. | 208 | // TODO: Test presence of more files and contents of files. |
226 | } | 209 | } |