aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestPreparation.cs
diff options
context:
space:
mode:
authorJustin Clarke Casey2008-06-16 17:13:28 +0000
committerJustin Clarke Casey2008-06-16 17:13:28 +0000
commite31de6707fe6296cbfe3ee5765b48eef42828541 (patch)
treedc8536374b079eb29ebc39b3e45fa1cce5924418 /OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestPreparation.cs
parentchange some messages on the migrations front to be (diff)
downloadopensim-SC_OLD-e31de6707fe6296cbfe3ee5765b48eef42828541.zip
opensim-SC_OLD-e31de6707fe6296cbfe3ee5765b48eef42828541.tar.gz
opensim-SC_OLD-e31de6707fe6296cbfe3ee5765b48eef42828541.tar.bz2
opensim-SC_OLD-e31de6707fe6296cbfe3ee5765b48eef42828541.tar.xz
* refactor: Fission ArchiveWriteRequest into prepare and execute classes
Diffstat (limited to 'OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestPreparation.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestPreparation.cs142
1 files changed, 142 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestPreparation.cs b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestPreparation.cs
new file mode 100644
index 0000000..a93e58d
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestPreparation.cs
@@ -0,0 +1,142 @@
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 OpenSim 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
28using OpenSim.Framework;
29using OpenSim.Framework.Communications.Cache;
30using OpenSim.Region.Environment.Interfaces;
31using OpenSim.Region.Environment.Modules.World.Serialiser;
32using OpenSim.Region.Environment.Scenes;
33using System.Collections.Generic;
34using System.Reflection;
35using System.Threading;
36using libsecondlife;
37using log4net;
38using Nini.Config;
39
40namespace OpenSim.Region.Environment.Modules.World.Archiver
41{
42 /// <summary>
43 /// Prepare to write out an archive.
44 /// </summary>
45 public class ArchiveWriteRequestPreparation
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 protected Scene m_scene;
50 protected string m_savePath;
51
52 public ArchiveWriteRequestPreparation(Scene scene, string savePath)
53 {
54 m_scene = scene;
55 m_savePath = savePath;
56 }
57
58 public void ArchiveRegion()
59 {
60 Dictionary<LLUUID, int> assetUuids = new Dictionary<LLUUID, int>();
61
62 List<EntityBase> entities = m_scene.GetEntities();
63
64 foreach (EntityBase entity in entities)
65 {
66 if (entity is SceneObjectGroup)
67 {
68 SceneObjectGroup sceneObject = (SceneObjectGroup)entity;
69
70 foreach (SceneObjectPart part in sceneObject.GetParts())
71 {
72 // XXX: Not a great way to iterate through face textures, but there's no
73 // other way to tell how many faces there actually are
74 //int i = 0;
75 foreach (LLObject.TextureEntryFace texture in part.Shape.Textures.FaceTextures)
76 {
77 if (texture != null)
78 {
79 //m_log.DebugFormat("[ARCHIVER]: Got face {0}", i++);
80 assetUuids[texture.TextureID] = 1;
81 }
82 }
83
84 foreach (TaskInventoryItem tit in part.TaskInventory.Values)
85 {
86 if (tit.Type != (int)InventoryType.Object)
87 {
88 m_log.DebugFormat("[ARCHIVER]: Recording asset {0} in object {1}", tit.AssetID, part.UUID);
89 assetUuids[tit.AssetID] = 1;
90 }
91 else
92 {
93 // TODO: Need to unpack every tit and go through its textures & items, recursively
94 // this will mean going through the 'assets' received multiple times so that we can
95 // unpack objects within objects before recursively requesting the inner assets
96 }
97 }
98 }
99 }
100 }
101
102 string serializedEntities = SerializeObjects(entities);
103
104 if (serializedEntities != null && serializedEntities.Length > 0)
105 {
106 m_log.DebugFormat("[ARCHIVER]: Successfully got serialization for {0} entities", entities.Count);
107 m_log.DebugFormat("[ARCHIVER]: Requiring save of {0} textures", assetUuids.Count);
108
109 // Asynchronously request all the assets required to perform this archive operation
110 ArchiveWriteRequestExecution awre = new ArchiveWriteRequestExecution(serializedEntities, m_savePath);
111 new AssetsRequest(assetUuids.Keys, m_scene.AssetCache, awre.ReceivedAllAssets).Execute();
112 }
113 }
114
115 /// <summary>
116 /// Get an xml representation of the given scene objects.
117 /// </summary>
118 /// <param name="scene"></param>
119 /// <returns></returns>
120 protected static string SerializeObjects(List<EntityBase> entities)
121 {
122 string serialization = "<scene>";
123
124 List<string> serObjects = new List<string>();
125
126 foreach (EntityBase ent in entities)
127 {
128 if (ent is SceneObjectGroup)
129 {
130 serObjects.Add(((SceneObjectGroup) ent).ToXmlString2());
131 }
132 }
133
134 foreach (string serObject in serObjects)
135 serialization += serObject;
136
137 serialization += "</scene>";
138
139 return serialization;
140 }
141 }
142}