From 20a4a402f6e3a1f914ee562f9e2d16647bcb961d Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Mon, 21 Apr 2008 04:36:32 +0000 Subject: * Written a improved self-contained version of the XML Object Serialiser for the ExportSerialisationModule. * This now outputs properly indented XML, that is sorted before construction. This produces a file which proper .diffs can be generated from - the end result being smaller more compact revisions when saving to SVN. * Files are a little heavy still however, compression looks like a good method for packing sim-states for transport outside of SVN. Zip seems to be a good candidate and is on the TODO. --- .../Modules/ExportSerialiser/SerialiseObjects.cs | 48 +++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/Environment') diff --git a/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs b/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs index ca8e51e..e413466 100644 --- a/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs +++ b/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs @@ -26,6 +26,9 @@ */ using OpenSim.Region.Environment.Scenes; +using System.IO; +using System.Collections.Generic; +using System.Xml; namespace OpenSim.Region.Environment.Modules.ExportSerialiser { @@ -33,11 +36,54 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser { #region IFileSerialiser Members + + public void SaveSerialisedToFile(string fileName, Scene scene) + { + int primCount = 0; + string xmlstream = ""; + + List EntityList = scene.GetEntities(); + List EntityXml = new List(); + + foreach (EntityBase ent in EntityList) + { + if (ent is SceneObjectGroup) + { + EntityXml.Add(((SceneObjectGroup)ent).ToXmlString2()); + primCount++; + } + } + EntityXml.Sort(); + + foreach (string xml in EntityXml) + xmlstream += xml; + + xmlstream += ""; + + MemoryStream stream = new MemoryStream(); + XmlTextWriter formatter = new XmlTextWriter(stream, System.Text.Encoding.UTF8); + XmlDocument doc = new XmlDocument(); + + doc.LoadXml(xmlstream); + formatter.Formatting = Formatting.Indented; + doc.WriteContentTo(formatter); + formatter.Flush(); + StreamReader reader = new StreamReader(stream); + + stream.Seek(0, SeekOrigin.Begin); + + FileStream objectsFile = new FileStream(fileName, FileMode.Create); + stream.WriteTo(objectsFile); + objectsFile.Flush(); + objectsFile.Close(); + + } + public string WriteToFile(Scene scene, string dir) { string targetFileName = dir + "objects.xml"; - scene.SavePrimsToXml2(targetFileName); + SaveSerialisedToFile(targetFileName, scene); return "objects.xml"; } -- cgit v1.1