aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/ContentManagementSystem/CMModel.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules/ContentManagementSystem/CMModel.cs')
-rw-r--r--OpenSim/Region/OptionalModules/ContentManagementSystem/CMModel.cs366
1 files changed, 0 insertions, 366 deletions
diff --git a/OpenSim/Region/OptionalModules/ContentManagementSystem/CMModel.cs b/OpenSim/Region/OptionalModules/ContentManagementSystem/CMModel.cs
deleted file mode 100644
index 84c7f29..0000000
--- a/OpenSim/Region/OptionalModules/ContentManagementSystem/CMModel.cs
+++ /dev/null
@@ -1,366 +0,0 @@
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
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Diagnostics;
32
33using OpenMetaverse;
34
35using OpenSim;
36using OpenSim.Framework;
37using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.Framework.Scenes;
39using OpenSim.Region.Framework.Scenes.Serialization;
40using OpenSim.Region.Physics.Manager;
41
42using log4net;
43
44namespace OpenSim.Region.OptionalModules.ContentManagement
45{
46 public class CMModel
47 {
48 #region Static Fields
49
50 static float TimeToUpdate = 0;
51 static float TimeToConvertXml = 0;
52 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
53
54 #endregion Static Fields
55
56 #region Fields
57
58 /// <value>
59 /// The class that contains all auras and metaentities used in the CMS.
60 /// </value>
61 CMEntityCollection m_MetaEntityCollection = new CMEntityCollection();
62 IContentDatabase m_database = null;
63
64 #endregion Fields
65
66 #region Constructors
67
68 public CMModel()
69 {
70 }
71
72 #endregion Constructors
73
74 #region Public Properties
75
76 public CMEntityCollection MetaEntityCollection
77 {
78 get { return m_MetaEntityCollection; }
79 }
80
81 #endregion Public Properties
82
83 #region Public Methods
84
85 /// <summary>
86 /// Compares the scene's object group list to the list of meta entities. If there is an object group that does not have a corresponding meta entity
87 /// it is a new part that must have a green aura (for diff mode).
88 /// Returns list of ContentManagementEntities
89 /// </summary>
90 public ArrayList CheckForNewEntitiesMissingAuras(Scene scene)
91 {
92 ArrayList missingList = null;
93 ArrayList newList = new ArrayList();
94
95 m_log.Debug("[CONTENT MANAGEMENT] Checking for new scene object parts in scene: " + scene.RegionInfo.RegionName);
96
97 //Check if the current scene has groups not included in the current list of MetaEntities
98 //If so, then the current scene's parts that are new should be marked green.
99 missingList = m_MetaEntityCollection.CheckForMissingEntities(scene.GetEntities());
100
101 foreach (Object missingPart in missingList)
102 {
103 if (m_MetaEntityCollection.Auras.ContainsKey(((SceneObjectPart)missingPart).UUID))
104 continue;
105 newList.Add(m_MetaEntityCollection.CreateAuraForNewlyCreatedEntity((SceneObjectPart)missingPart));
106 }
107 m_log.Info("Number of missing objects found: " + newList.Count);
108 return newList;
109 }
110
111 /// <summary>
112 /// Uses the database to serialize all current scene objects into xml and save into a database with an accompanying log message.
113 /// </summary>
114 public void CommitRegion(Scene scene, String logMessage)
115 {
116 m_log.Debug("[CONTENT MANAG] saving " + scene.RegionInfo.RegionName + " with log message: " + logMessage + " length of message: " + logMessage.Length);
117 m_database.SaveRegion(scene.RegionInfo.RegionID, scene.RegionInfo.RegionName, logMessage);
118 m_log.Debug("[CONTENT MANAG] the region name we are dealing with heeeeeeeere: " + scene.RegionInfo.RegionName);
119 }
120
121 public void DeleteAllMetaObjects()
122 {
123 m_MetaEntityCollection.ClearAll();
124 }
125
126 public ContentManagementEntity FindMetaEntityAffectedByUndo(UUID uuid)
127 {
128 ContentManagementEntity ent = GetMetaGroupByPrim(uuid);
129 return ent;
130 }
131
132 //-------------------------------- HELPERS --------------------------------------------------------------------//
133 public ContentManagementEntity GetMetaGroupByPrim(UUID uuid)
134 {
135 foreach (Object ent in m_MetaEntityCollection.Entities.Values)
136 {
137 if (((ContentManagementEntity)ent).HasChildPrim(uuid))
138 return (ContentManagementEntity)ent;
139 }
140 return null;
141 }
142
143 public void Initialise(string database)
144 {
145 if (database == "FileSystemDatabase")
146 m_database = new FileSystemDatabase();
147 else if (database == "GitDatabase")
148 m_database = new GitDatabase();
149 }
150
151 public void InitialiseDatabase(Scene scene, string dir)
152 {
153 m_database.Initialise(scene, dir);
154 }
155
156 /// <summary>
157 /// Should be called just once to finish initializing the database.
158 /// </summary>
159 public void PostInitialise()
160 {
161 m_database.PostInitialise();
162 }
163
164 /// <summary>
165 /// Removes the green aura when an a new scene object group is deleted.
166 /// </summary>
167 public void RemoveOrUpdateDeletedEntity(SceneObjectGroup group)
168 {
169 // Deal with new parts not revisioned that have been deleted.
170 SceneObjectPart[] parts = group.Parts;
171 for (int i = 0; i < parts.Length; i++)
172 {
173 if (m_MetaEntityCollection.Auras.ContainsKey(parts[i].UUID))
174 m_MetaEntityCollection.RemoveNewlyCreatedEntityAura(parts[i].UUID);
175 }
176 }
177
178 /// <summary>
179 /// Retrieves the latest revision of a region in xml form,
180 /// converts it to scene object groups and scene presences,
181 /// swaps the current scene's entity list with the revision's list.
182 /// Note: Since deleted objects while
183 /// </summary>
184 public void RollbackRegion(Scene scene)
185 {
186 System.Collections.ArrayList xmllist = null;
187 SceneObjectGroup temp = null;
188 System.Collections.Hashtable deleteListUUIDs = new Hashtable();
189// Dictionary<LLUUID, EntityBase> SearchList = new Dictionary<LLUUID,EntityBase>();
190 Dictionary<UUID, EntityBase> ReplacementList = new Dictionary<UUID,EntityBase>();
191 int revision = m_database.GetMostRecentRevision(scene.RegionInfo.RegionID);
192// EntityBase[] searchArray;
193
194 xmllist = m_database.GetRegionObjectXMLList(scene.RegionInfo.RegionID, revision);
195 if (xmllist == null)
196 {
197 m_log.Info("[CMMODEL]: Region (" + scene.RegionInfo.RegionID + ") does not have given revision number (" + revision + ").");
198 return;
199 }
200
201 m_log.Info("[CMMODEL]: Region (" + scene.RegionInfo.RegionID + ") revision number (" + revision + ").");
202 m_log.Info("[CMMODEL]: Scene Objects = " + xmllist.Count);
203 m_log.Info("[CMMODEL]: Converting scene entities list to specified revision.");
204
205 m_log.ErrorFormat("[CMMODEL]: 1");
206
207 foreach (string xml in xmllist)
208 {
209 try
210 {
211 temp = SceneObjectSerializer.FromXml2Format(xml);
212 temp.SetScene(scene);
213
214 SceneObjectPart[] parts = temp.Parts;
215 for (int i = 0; i < parts.Length; i++)
216 parts[i].RegionHandle = scene.RegionInfo.RegionHandle;
217
218 ReplacementList.Add(temp.UUID, (EntityBase)temp);
219 }
220 catch (Exception e)
221 {
222 m_log.Info("[CMMODEL]: Error while creating replacement list for rollback: " + e);
223 }
224 }
225
226 //If in scene but not in revision and not a client, remove them
227 while (true)
228 {
229 try
230 {
231 foreach (EntityBase entity in scene.GetEntities())
232 {
233 if (entity == null)
234 continue;
235
236 if (entity is ScenePresence)
237 {
238 ReplacementList.Add(entity.UUID, entity);
239 continue;
240 }
241 else //if (!ReplacementList.ContainsKey(entity.UUID))
242 deleteListUUIDs.Add(entity.UUID, 0);
243 }
244 }
245 catch(Exception e)
246 {
247 m_log.ErrorFormat("[CMMODEL]: " + e);
248 deleteListUUIDs.Clear();
249 ReplacementList.Clear();
250 continue;
251 }
252 break;
253 }
254
255 foreach (UUID uuid in deleteListUUIDs.Keys)
256 {
257 try
258 {
259 // I thought that the DeleteGroup() function would handle all of this, but it doesn't. I'm not sure WHAT it handles.
260 ((SceneObjectGroup)scene.Entities[uuid]).DetachFromBackup();
261 scene.PhysicsScene.RemovePrim(((SceneObjectGroup)scene.Entities[uuid]).RootPart.PhysActor);
262 scene.SendKillObject(new List<uint>() { scene.Entities[uuid].LocalId });
263 scene.SceneGraph.DeleteSceneObject(uuid, false);
264 ((SceneObjectGroup)scene.Entities[uuid]).DeleteGroupFromScene(false);
265 scene.SendKillObject(new List<uint>() { ((SceneObjectGroup)scene.Entities[uuid]).LocalId });
266 }
267 catch(Exception e)
268 {
269 m_log.ErrorFormat("[CMMODEL]: Error while removing objects from scene: " + e);
270 }
271 }
272
273 lock (scene)
274 {
275 scene.Entities.Clear();
276
277 foreach (KeyValuePair<UUID,EntityBase> kvp in ReplacementList)
278 {
279 scene.Entities.Add(kvp.Value);
280 }
281 }
282
283 foreach (EntityBase ent in ReplacementList.Values)
284 {
285 try
286 {
287 if (!(ent is SceneObjectGroup))
288 continue;
289
290 if ((((SceneObjectGroup)ent).RootPart.GetEffectiveObjectFlags() & (uint) PrimFlags.Phantom) == 0)
291 ((SceneObjectGroup)ent).ApplyPhysics(true);
292 ((SceneObjectGroup)ent).AttachToBackup();
293 ((SceneObjectGroup)ent).HasGroupChanged = true; // If not true, then attaching to backup does nothing because no change is detected.
294 ((SceneObjectGroup)ent).ScheduleGroupForFullUpdate();
295 }
296 catch(Exception e)
297 {
298 m_log.ErrorFormat("[CMMODEL]: Error while attaching new scene entities to backup and scheduling for a full update: " + e);
299 }
300 }
301 m_log.Info("[CMMODEL]: Scheduling a backup of new scene object groups to backup.");
302 scene.Backup(true);
303 }
304
305 /// <summary>
306 /// Downloads the latest revision of the given scene and converts the xml file to CMEntities. After this method, the view can find the differences
307 /// and display the differences to clients.
308 /// </summary>
309 public void UpdateCMEntities(Scene scene)
310 {
311 Stopwatch x = new Stopwatch();
312 x.Start();
313
314 System.Collections.ArrayList xmllist = null;
315 m_log.Debug("[CONTENT MANAGEMENT] Retrieving object xml files for region: " + scene.RegionInfo.RegionID);
316 xmllist = m_database.GetRegionObjectXMLList(scene.RegionInfo.RegionID);
317 m_log.Info("[FSDB]: got list");
318 if (xmllist == null)
319 return;
320
321 Stopwatch y = new Stopwatch();
322 y.Start();
323 foreach (string xml in xmllist)
324 m_MetaEntityCollection.CreateNewEntity(xml, scene);
325 y.Stop();
326 TimeToConvertXml += y.ElapsedMilliseconds;
327 m_log.Info("[FileSystemDatabase] Time spent converting xml to metaentities for " + scene.RegionInfo.RegionName + ": " + y.ElapsedMilliseconds);
328 m_log.Info("[FileSystemDatabase] Time spent converting xml to metaentities so far: " + TimeToConvertXml);
329
330 m_log.Info("[FSDB]: checking for new scene object parts missing green auras and create the auras");
331 CheckForNewEntitiesMissingAuras(scene);
332
333 x.Stop();
334 TimeToUpdate += x.ElapsedMilliseconds;
335 m_log.Info("[FileSystemDatabase] Time spent Updating entity list for " + scene.RegionInfo.RegionName + ": " + x.ElapsedMilliseconds);
336 m_log.Info("[FileSystemDatabase] Time spent Updating so far: " + TimeToUpdate);
337 }
338
339 /// <summary>
340 /// Detects if a scene object group from the scene list has moved or changed scale. The green aura
341 /// that surrounds the object is then moved or scaled with the group.
342 /// </summary>
343 public System.Collections.ArrayList UpdateNormalEntityEffects(SceneObjectGroup group)
344 {
345 System.Collections.ArrayList auraList = new System.Collections.ArrayList();
346 if (group == null)
347 return null;
348
349 SceneObjectPart[] parts = group.Parts;
350 for (int i = 0; i < parts.Length; i++)
351 {
352 SceneObjectPart part = parts[i];
353 if (m_MetaEntityCollection.Auras.ContainsKey(part.UUID))
354 {
355 ((AuraMetaEntity)m_MetaEntityCollection.Auras[part.UUID]).SetAura(new Vector3(0, 254, 0), part.Scale);
356 ((AuraMetaEntity)m_MetaEntityCollection.Auras[part.UUID]).RootPart.GroupPosition = part.GetWorldPosition();
357 auraList.Add((AuraMetaEntity)m_MetaEntityCollection.Auras[part.UUID]);
358 }
359 }
360
361 return auraList;
362 }
363
364 #endregion Public Methods
365 }
366}