From 02bac7fea4f556f827b9bc4456c5c02c84ae8dbd Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Thu, 14 May 2009 18:46:17 +0000 Subject: * refactor: move SceneXmlLoader into subpackage --- .../Scenes/Serialization/SceneXmlLoader.cs | 290 +++++++++++++++++++++ 1 file changed, 290 insertions(+) create mode 100644 OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs (limited to 'OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs') diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs new file mode 100644 index 0000000..24f1be1 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs @@ -0,0 +1,290 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using System.Xml; +using OpenMetaverse; +using log4net; +using OpenSim.Framework; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Region.Physics.Manager; + +namespace OpenSim.Region.Framework.Scenes.Serialization +{ + /// + /// Static methods to serialize and deserialize scene objects to and from XML + /// + public class SceneXmlLoader + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + public static void LoadPrimsFromXml(Scene scene, string fileName, bool newIDS, Vector3 loadOffset) + { + XmlDocument doc = new XmlDocument(); + XmlNode rootNode; + + if (fileName.StartsWith("http:") || File.Exists(fileName)) + { + XmlTextReader reader = new XmlTextReader(fileName); + reader.WhitespaceHandling = WhitespaceHandling.None; + doc.Load(reader); + reader.Close(); + rootNode = doc.FirstChild; + foreach (XmlNode aPrimNode in rootNode.ChildNodes) + { + SceneObjectGroup obj = SceneObjectSerializer.FromOriginalXmlFormat(aPrimNode.OuterXml); + + if (newIDS) + { + obj.ResetIDs(); + } + //if we want this to be a import method then we need new uuids for the object to avoid any clashes + //obj.RegenerateFullIDs(); + + scene.AddNewSceneObject(obj, true); + } + } + else + { + throw new Exception("Could not open file " + fileName + " for reading"); + } + } + + public static void SavePrimsToXml(Scene scene, string fileName) + { + FileStream file = new FileStream(fileName, FileMode.Create); + StreamWriter stream = new StreamWriter(file); + int primCount = 0; + stream.WriteLine("\n"); + + List EntityList = scene.GetEntities(); + + foreach (EntityBase ent in EntityList) + { + if (ent is SceneObjectGroup) + { + stream.WriteLine(SceneObjectSerializer.ToOriginalXmlFormat((SceneObjectGroup)ent)); + primCount++; + } + } + stream.WriteLine("\n"); + stream.Close(); + file.Close(); + } + + public static string SaveGroupToXml2(SceneObjectGroup grp) + { + return SceneObjectSerializer.ToXml2Format(grp); + } + + public static SceneObjectGroup DeserializeGroupFromXml2(string xmlString) + { + XmlDocument doc = new XmlDocument(); + XmlNode rootNode; + + XmlTextReader reader = new XmlTextReader(new StringReader(xmlString)); + reader.WhitespaceHandling = WhitespaceHandling.None; + doc.Load(reader); + reader.Close(); + rootNode = doc.FirstChild; + + // This is to deal with neighbouring regions that are still surrounding the group xml with the + // tag. It should be possible to remove the first part of this if statement once we go past 0.5.9 (or + // when some other changes forces all regions to upgrade). + // This might seem rather pointless since prim crossing from this revision to an earlier revision remains + // broken. But it isn't much work to accomodate the old format here. + if (rootNode.LocalName.Equals("scene")) + { + foreach (XmlNode aPrimNode in rootNode.ChildNodes) + { + // There is only ever one prim. This oddity should be removeable post 0.5.9 + return SceneObjectSerializer.FromXml2Format(aPrimNode.OuterXml); + } + + return null; + } + else + { + return SceneObjectSerializer.FromXml2Format(rootNode.OuterXml); + } + } + + /// + /// Load prims from the xml2 format + /// + /// + /// + public static void LoadPrimsFromXml2(Scene scene, string fileName) + { + LoadPrimsFromXml2(scene, new XmlTextReader(fileName), false); + } + + /// + /// Load prims from the xml2 format + /// + /// + /// + /// + public static void LoadPrimsFromXml2(Scene scene, TextReader reader, bool startScripts) + { + LoadPrimsFromXml2(scene, new XmlTextReader(reader), startScripts); + } + + /// + /// Load prims from the xml2 format. This method will close the reader + /// + /// + /// + /// + protected static void LoadPrimsFromXml2(Scene scene, XmlTextReader reader, bool startScripts) + { + XmlDocument doc = new XmlDocument(); + reader.WhitespaceHandling = WhitespaceHandling.None; + doc.Load(reader); + reader.Close(); + XmlNode rootNode = doc.FirstChild; + + ICollection sceneObjects = new List(); + foreach (XmlNode aPrimNode in rootNode.ChildNodes) + { + SceneObjectGroup obj = CreatePrimFromXml2(scene, aPrimNode.OuterXml); + if (obj != null && startScripts) + sceneObjects.Add(obj); + } + + foreach (SceneObjectGroup sceneObject in sceneObjects) + { + sceneObject.CreateScriptInstances(0, true, scene.DefaultScriptEngine, 0); + } + } + + /// + /// Create a prim from the xml2 representation. + /// + /// + /// + /// The scene object created. null if the scene object already existed + protected static SceneObjectGroup CreatePrimFromXml2(Scene scene, string xmlData) + { + SceneObjectGroup obj = SceneObjectSerializer.FromXml2Format(xmlData); + + if (scene.AddRestoredSceneObject(obj, true, false)) + return obj; + else + return null; + } + + public static void SavePrimsToXml2(Scene scene, string fileName) + { + List EntityList = scene.GetEntities(); + + SavePrimListToXml2(EntityList, fileName); + } + + public static void SavePrimsToXml2(Scene scene, TextWriter stream, Vector3 min, Vector3 max) + { + List EntityList = scene.GetEntities(); + + SavePrimListToXml2(EntityList, stream, min, max); + } + + public static void SaveNamedPrimsToXml2(Scene scene, string primName, string fileName) + { + m_log.InfoFormat( + "[SERIALISER]: Saving prims with name {0} in xml2 format for region {1} to {2}", + primName, scene.RegionInfo.RegionName, fileName); + + List entityList = scene.GetEntities(); + List primList = new List(); + + foreach (EntityBase ent in entityList) + { + if (ent is SceneObjectGroup) + { + if (ent.Name == primName) + { + primList.Add(ent); + } + } + } + + SavePrimListToXml2(primList, fileName); + } + + public static void SavePrimListToXml2(List entityList, string fileName) + { + FileStream file = new FileStream(fileName, FileMode.Create); + try + { + StreamWriter stream = new StreamWriter(file); + try + { + SavePrimListToXml2(entityList, stream, Vector3.Zero, Vector3.Zero); + } + finally + { + stream.Close(); + } + } + finally + { + file.Close(); + } + } + + public static void SavePrimListToXml2(List entityList, TextWriter stream, Vector3 min, Vector3 max) + { + int primCount = 0; + stream.WriteLine("\n"); + + foreach (EntityBase ent in entityList) + { + if (ent is SceneObjectGroup) + { + SceneObjectGroup g = (SceneObjectGroup)ent; + if (!min.Equals(Vector3.Zero) || !max.Equals(Vector3.Zero)) + { + Vector3 pos = g.RootPart.GetWorldPosition(); + if (min.X > pos.X || min.Y > pos.Y || min.Z > pos.Z) + continue; + if (max.X < pos.X || max.Y < pos.Y || max.Z < pos.Z) + continue; + } + + stream.WriteLine(SceneObjectSerializer.ToXml2Format(g)); + primCount++; + } + } + stream.WriteLine("\n"); + stream.Flush(); + } + + } +} -- cgit v1.1 From 840de6c036570d559ec6924cd8405d3f34a99fdd Mon Sep 17 00:00:00 2001 From: Jeff Ames Date: Mon, 1 Jun 2009 06:37:14 +0000 Subject: Minor: Change OpenSim to OpenSimulator in older copyright headers and LICENSE.txt. --- OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs') diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs index 24f1be1..7fa1b8c 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs @@ -9,7 +9,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSim Project nor the + * * Neither the name of the OpenSimulator Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * -- cgit v1.1 From ee205e7e812e170f670e690a4e0fa9caa652f226 Mon Sep 17 00:00:00 2001 From: Jeff Ames Date: Thu, 1 Oct 2009 01:00:09 +0900 Subject: Formatting cleanup. --- OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs') diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs index 7fa1b8c..cf0f345 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs @@ -236,7 +236,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization } SavePrimListToXml2(primList, fileName); - } + } public static void SavePrimListToXml2(List entityList, string fileName) { -- cgit v1.1 From 21cad5d3ac68ceb4ac48346835ac087ecb107446 Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 19 Apr 2010 06:29:26 +0100 Subject: All scripts are now created suspended and are only unsuspended when the object is fully rezzed and all scripts in it are instantiated. This ensures that link messages will not be lost on rez/region crossing and makes heavily scripted objects reliable. --- OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs | 1 + 1 file changed, 1 insertion(+) (limited to 'OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs') diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs index cf0f345..b6677f0 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs @@ -182,6 +182,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization foreach (SceneObjectGroup sceneObject in sceneObjects) { sceneObject.CreateScriptInstances(0, true, scene.DefaultScriptEngine, 0); + sceneObject.ResumeScripts(); } } -- cgit v1.1 From dd277a0d02f1aa79f4fcb5d108cbc696e90500c2 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Fri, 10 Sep 2010 12:04:12 -0700 Subject: First pass at cleaning up thread safety in EntityManager and SceneGraph --- .../Scenes/Serialization/SceneXmlLoader.cs | 23 ++++++++++------------ 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs') diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs index b6677f0..5494549 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs @@ -84,9 +84,8 @@ namespace OpenSim.Region.Framework.Scenes.Serialization int primCount = 0; stream.WriteLine("\n"); - List EntityList = scene.GetEntities(); - - foreach (EntityBase ent in EntityList) + EntityBase[] entityList = scene.GetEntities(); + foreach (EntityBase ent in entityList) { if (ent is SceneObjectGroup) { @@ -204,16 +203,14 @@ namespace OpenSim.Region.Framework.Scenes.Serialization public static void SavePrimsToXml2(Scene scene, string fileName) { - List EntityList = scene.GetEntities(); - - SavePrimListToXml2(EntityList, fileName); + EntityBase[] entityList = scene.GetEntities(); + SavePrimListToXml2(entityList, fileName); } public static void SavePrimsToXml2(Scene scene, TextWriter stream, Vector3 min, Vector3 max) { - List EntityList = scene.GetEntities(); - - SavePrimListToXml2(EntityList, stream, min, max); + EntityBase[] entityList = scene.GetEntities(); + SavePrimListToXml2(entityList, stream, min, max); } public static void SaveNamedPrimsToXml2(Scene scene, string primName, string fileName) @@ -222,7 +219,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization "[SERIALISER]: Saving prims with name {0} in xml2 format for region {1} to {2}", primName, scene.RegionInfo.RegionName, fileName); - List entityList = scene.GetEntities(); + EntityBase[] entityList = scene.GetEntities(); List primList = new List(); foreach (EntityBase ent in entityList) @@ -236,10 +233,10 @@ namespace OpenSim.Region.Framework.Scenes.Serialization } } - SavePrimListToXml2(primList, fileName); + SavePrimListToXml2(primList.ToArray(), fileName); } - public static void SavePrimListToXml2(List entityList, string fileName) + public static void SavePrimListToXml2(EntityBase[] entityList, string fileName) { FileStream file = new FileStream(fileName, FileMode.Create); try @@ -260,7 +257,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization } } - public static void SavePrimListToXml2(List entityList, TextWriter stream, Vector3 min, Vector3 max) + public static void SavePrimListToXml2(EntityBase[] entityList, TextWriter stream, Vector3 min, Vector3 max) { int primCount = 0; stream.WriteLine("\n"); -- cgit v1.1 From 54a3b8e079539d1d17b845be5c90702303452b0a Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Wed, 13 Oct 2010 08:16:41 -0700 Subject: New SOG/SOP parser using XmlTextReader + delegates dictionary. Active for load oar and load xml2, but not for packing objects on crossings/TPs yet. --- .../Scenes/Serialization/SceneXmlLoader.cs | 35 +++++++++++++++++----- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs') diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs index 5494549..bb67ca0 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs @@ -124,14 +124,30 @@ namespace OpenSim.Region.Framework.Scenes.Serialization foreach (XmlNode aPrimNode in rootNode.ChildNodes) { // There is only ever one prim. This oddity should be removeable post 0.5.9 - return SceneObjectSerializer.FromXml2Format(aPrimNode.OuterXml); + //return SceneObjectSerializer.FromXml2Format(aPrimNode.OuterXml); + using (reader = new XmlTextReader(new StringReader(aPrimNode.OuterXml))) + { + SceneObjectGroup obj = new SceneObjectGroup(); + if (SceneObjectSerializer.Xml2ToSOG(reader, obj)) + return obj; + + return null; + } } return null; } else { - return SceneObjectSerializer.FromXml2Format(rootNode.OuterXml); + //return SceneObjectSerializer.FromXml2Format(rootNode.OuterXml); + using (reader = new XmlTextReader(new StringReader(rootNode.OuterXml))) + { + SceneObjectGroup obj = new SceneObjectGroup(); + if (SceneObjectSerializer.Xml2ToSOG(reader, obj)) + return obj; + + return null; + } } } @@ -193,12 +209,17 @@ namespace OpenSim.Region.Framework.Scenes.Serialization /// The scene object created. null if the scene object already existed protected static SceneObjectGroup CreatePrimFromXml2(Scene scene, string xmlData) { - SceneObjectGroup obj = SceneObjectSerializer.FromXml2Format(xmlData); + //SceneObjectGroup obj = SceneObjectSerializer.FromXml2Format(xmlData); + using (XmlTextReader reader = new XmlTextReader(new StringReader(xmlData))) + { + SceneObjectGroup obj = new SceneObjectGroup(); + SceneObjectSerializer.Xml2ToSOG(reader, obj); - if (scene.AddRestoredSceneObject(obj, true, false)) - return obj; - else - return null; + if (scene.AddRestoredSceneObject(obj, true, false)) + return obj; + else + return null; + } } public static void SavePrimsToXml2(Scene scene, string fileName) -- cgit v1.1 From 41ce392d9b32c343c5239b3a9fa0ef9f83b6a96f Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Thu, 14 Oct 2010 09:05:46 -0700 Subject: Added manual xml2 serialization. Rewired only save xml2, not oars yet. Seems to be generating xml's that are successfully parsed. Needs more testing. --- OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs') diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs index bb67ca0..c6d4e55 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs @@ -280,6 +280,8 @@ namespace OpenSim.Region.Framework.Scenes.Serialization public static void SavePrimListToXml2(EntityBase[] entityList, TextWriter stream, Vector3 min, Vector3 max) { + XmlTextWriter writer = new XmlTextWriter(stream); + int primCount = 0; stream.WriteLine("\n"); @@ -297,10 +299,14 @@ namespace OpenSim.Region.Framework.Scenes.Serialization continue; } - stream.WriteLine(SceneObjectSerializer.ToXml2Format(g)); + //stream.WriteLine(SceneObjectSerializer.ToXml2Format(g)); + SceneObjectSerializer.SOGToXml2(writer, (SceneObjectGroup)ent); + stream.WriteLine(); + primCount++; } } + stream.WriteLine("\n"); stream.Flush(); } -- cgit v1.1 From 1499607215aab4994f933a8ed2a54ed037a1f9ba Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Fri, 15 Oct 2010 17:27:19 -0700 Subject: Made OARs use the new serialization procedure. (TPs/crossings still on the old one) Added an options argument down the pipeline. For the time being it takes --old-guids as an option to produce instead of . --- .../Scenes/Serialization/SceneXmlLoader.cs | 212 ++++++++++++--------- 1 file changed, 121 insertions(+), 91 deletions(-) (limited to 'OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs') diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs index c6d4e55..d214eba 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs @@ -45,6 +45,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + #region old xml format public static void LoadPrimsFromXml(Scene scene, string fileName, bool newIDS, Vector3 loadOffset) { XmlDocument doc = new XmlDocument(); @@ -98,11 +99,128 @@ namespace OpenSim.Region.Framework.Scenes.Serialization file.Close(); } - public static string SaveGroupToXml2(SceneObjectGroup grp) + #endregion + + #region XML2 serialization + + // Called by archives (save oar) + public static string SaveGroupToXml2(SceneObjectGroup grp, Dictionary options) + { + //return SceneObjectSerializer.ToXml2Format(grp); + using (MemoryStream mem = new MemoryStream()) + { + using (XmlTextWriter writer = new XmlTextWriter(mem, System.Text.Encoding.UTF8)) + { + SceneObjectSerializer.SOGToXml2(writer, grp, options); + writer.Flush(); + + using (StreamReader reader = new StreamReader(mem)) + { + mem.Seek(0, SeekOrigin.Begin); + return reader.ReadToEnd(); + } + } + } + } + + // Called by scene serializer (save xml2) + public static void SavePrimsToXml2(Scene scene, string fileName) + { + EntityBase[] entityList = scene.GetEntities(); + SavePrimListToXml2(entityList, fileName); + } + + // Called by scene serializer (save xml2) + public static void SaveNamedPrimsToXml2(Scene scene, string primName, string fileName) + { + m_log.InfoFormat( + "[SERIALISER]: Saving prims with name {0} in xml2 format for region {1} to {2}", + primName, scene.RegionInfo.RegionName, fileName); + + EntityBase[] entityList = scene.GetEntities(); + List primList = new List(); + + foreach (EntityBase ent in entityList) + { + if (ent is SceneObjectGroup) + { + if (ent.Name == primName) + { + primList.Add(ent); + } + } + } + + SavePrimListToXml2(primList.ToArray(), fileName); + } + + // Called by REST Application plugin + public static void SavePrimsToXml2(Scene scene, TextWriter stream, Vector3 min, Vector3 max) + { + EntityBase[] entityList = scene.GetEntities(); + SavePrimListToXml2(entityList, stream, min, max); + } + + // Called here only. Should be private? + public static void SavePrimListToXml2(EntityBase[] entityList, string fileName) { - return SceneObjectSerializer.ToXml2Format(grp); + FileStream file = new FileStream(fileName, FileMode.Create); + try + { + StreamWriter stream = new StreamWriter(file); + try + { + SavePrimListToXml2(entityList, stream, Vector3.Zero, Vector3.Zero); + } + finally + { + stream.Close(); + } + } + finally + { + file.Close(); + } + } + + // Called here only. Should be private? + public static void SavePrimListToXml2(EntityBase[] entityList, TextWriter stream, Vector3 min, Vector3 max) + { + XmlTextWriter writer = new XmlTextWriter(stream); + + int primCount = 0; + stream.WriteLine("\n"); + + foreach (EntityBase ent in entityList) + { + if (ent is SceneObjectGroup) + { + SceneObjectGroup g = (SceneObjectGroup)ent; + if (!min.Equals(Vector3.Zero) || !max.Equals(Vector3.Zero)) + { + Vector3 pos = g.RootPart.GetWorldPosition(); + if (min.X > pos.X || min.Y > pos.Y || min.Z > pos.Z) + continue; + if (max.X < pos.X || max.Y < pos.Y || max.Z < pos.Z) + continue; + } + + //stream.WriteLine(SceneObjectSerializer.ToXml2Format(g)); + SceneObjectSerializer.SOGToXml2(writer, (SceneObjectGroup)ent, new Dictionary()); + stream.WriteLine(); + + primCount++; + } + } + + stream.WriteLine("\n"); + stream.Flush(); } + #endregion + + #region XML2 deserialization + public static SceneObjectGroup DeserializeGroupFromXml2(string xmlString) { XmlDocument doc = new XmlDocument(); @@ -222,94 +340,6 @@ namespace OpenSim.Region.Framework.Scenes.Serialization } } - public static void SavePrimsToXml2(Scene scene, string fileName) - { - EntityBase[] entityList = scene.GetEntities(); - SavePrimListToXml2(entityList, fileName); - } - - public static void SavePrimsToXml2(Scene scene, TextWriter stream, Vector3 min, Vector3 max) - { - EntityBase[] entityList = scene.GetEntities(); - SavePrimListToXml2(entityList, stream, min, max); - } - - public static void SaveNamedPrimsToXml2(Scene scene, string primName, string fileName) - { - m_log.InfoFormat( - "[SERIALISER]: Saving prims with name {0} in xml2 format for region {1} to {2}", - primName, scene.RegionInfo.RegionName, fileName); - - EntityBase[] entityList = scene.GetEntities(); - List primList = new List(); - - foreach (EntityBase ent in entityList) - { - if (ent is SceneObjectGroup) - { - if (ent.Name == primName) - { - primList.Add(ent); - } - } - } - - SavePrimListToXml2(primList.ToArray(), fileName); - } - - public static void SavePrimListToXml2(EntityBase[] entityList, string fileName) - { - FileStream file = new FileStream(fileName, FileMode.Create); - try - { - StreamWriter stream = new StreamWriter(file); - try - { - SavePrimListToXml2(entityList, stream, Vector3.Zero, Vector3.Zero); - } - finally - { - stream.Close(); - } - } - finally - { - file.Close(); - } - } - - public static void SavePrimListToXml2(EntityBase[] entityList, TextWriter stream, Vector3 min, Vector3 max) - { - XmlTextWriter writer = new XmlTextWriter(stream); - - int primCount = 0; - stream.WriteLine("\n"); - - foreach (EntityBase ent in entityList) - { - if (ent is SceneObjectGroup) - { - SceneObjectGroup g = (SceneObjectGroup)ent; - if (!min.Equals(Vector3.Zero) || !max.Equals(Vector3.Zero)) - { - Vector3 pos = g.RootPart.GetWorldPosition(); - if (min.X > pos.X || min.Y > pos.Y || min.Z > pos.Z) - continue; - if (max.X < pos.X || max.Y < pos.Y || max.Z < pos.Z) - continue; - } - - //stream.WriteLine(SceneObjectSerializer.ToXml2Format(g)); - SceneObjectSerializer.SOGToXml2(writer, (SceneObjectGroup)ent); - stream.WriteLine(); - - primCount++; - } - } - - stream.WriteLine("\n"); - stream.Flush(); - } - + #endregion } } -- cgit v1.1 From 23ae24b4061f7c1e1bc1c0d5428374ccf4e25891 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 16 May 2012 00:10:42 +0100 Subject: Route OAR SOG loading through the common SceneObjectSerializer.FromXml2Format() rather than the functionally identical but buggy Xml2ToSOG(). Remove buggy Xml2ToSOG(). --- .../Scenes/Serialization/SceneXmlLoader.cs | 72 ++-------------------- 1 file changed, 4 insertions(+), 68 deletions(-) (limited to 'OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs') diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs index d214eba..a3485d2 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneXmlLoader.cs @@ -223,50 +223,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization public static SceneObjectGroup DeserializeGroupFromXml2(string xmlString) { - XmlDocument doc = new XmlDocument(); - XmlNode rootNode; - - XmlTextReader reader = new XmlTextReader(new StringReader(xmlString)); - reader.WhitespaceHandling = WhitespaceHandling.None; - doc.Load(reader); - reader.Close(); - rootNode = doc.FirstChild; - - // This is to deal with neighbouring regions that are still surrounding the group xml with the - // tag. It should be possible to remove the first part of this if statement once we go past 0.5.9 (or - // when some other changes forces all regions to upgrade). - // This might seem rather pointless since prim crossing from this revision to an earlier revision remains - // broken. But it isn't much work to accomodate the old format here. - if (rootNode.LocalName.Equals("scene")) - { - foreach (XmlNode aPrimNode in rootNode.ChildNodes) - { - // There is only ever one prim. This oddity should be removeable post 0.5.9 - //return SceneObjectSerializer.FromXml2Format(aPrimNode.OuterXml); - using (reader = new XmlTextReader(new StringReader(aPrimNode.OuterXml))) - { - SceneObjectGroup obj = new SceneObjectGroup(); - if (SceneObjectSerializer.Xml2ToSOG(reader, obj)) - return obj; - - return null; - } - } - - return null; - } - else - { - //return SceneObjectSerializer.FromXml2Format(rootNode.OuterXml); - using (reader = new XmlTextReader(new StringReader(rootNode.OuterXml))) - { - SceneObjectGroup obj = new SceneObjectGroup(); - if (SceneObjectSerializer.Xml2ToSOG(reader, obj)) - return obj; - - return null; - } - } + return SceneObjectSerializer.FromXml2Format(xmlString); } /// @@ -307,8 +264,8 @@ namespace OpenSim.Region.Framework.Scenes.Serialization ICollection sceneObjects = new List(); foreach (XmlNode aPrimNode in rootNode.ChildNodes) { - SceneObjectGroup obj = CreatePrimFromXml2(scene, aPrimNode.OuterXml); - if (obj != null && startScripts) + SceneObjectGroup obj = DeserializeGroupFromXml2(aPrimNode.OuterXml); + if (startScripts) sceneObjects.Add(obj); } @@ -319,27 +276,6 @@ namespace OpenSim.Region.Framework.Scenes.Serialization } } - /// - /// Create a prim from the xml2 representation. - /// - /// - /// - /// The scene object created. null if the scene object already existed - protected static SceneObjectGroup CreatePrimFromXml2(Scene scene, string xmlData) - { - //SceneObjectGroup obj = SceneObjectSerializer.FromXml2Format(xmlData); - using (XmlTextReader reader = new XmlTextReader(new StringReader(xmlData))) - { - SceneObjectGroup obj = new SceneObjectGroup(); - SceneObjectSerializer.Xml2ToSOG(reader, obj); - - if (scene.AddRestoredSceneObject(obj, true, false)) - return obj; - else - return null; - } - } - #endregion } -} +} \ No newline at end of file -- cgit v1.1