From a0b8c46ef37f6bf44de36ab60fae741076d8a3bf Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Mon, 21 Apr 2008 09:38:51 +0000 Subject: * Various refactorings. --- .../Modules/ExportSerialiser/SerialiseObjects.cs | 48 ++++++++++++++++------ 1 file changed, 35 insertions(+), 13 deletions(-) (limited to 'OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs') diff --git a/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs b/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs index 7e5cf47..277370d 100644 --- a/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs +++ b/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs @@ -51,6 +51,32 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser public void SaveSerialisedToFile(string fileName, Scene scene) { + string xmlstream = GetObjectXml(scene); + + MemoryStream stream = ReformatXmlString(xmlstream); + + stream.Seek(0, SeekOrigin.Begin); + CreateXmlFile(stream, fileName); + + stream.Seek(0, SeekOrigin.Begin); + CreateCompressedXmlFile(stream, fileName); + } + + private static MemoryStream ReformatXmlString(string xmlstream) + { + MemoryStream stream = new MemoryStream(); + XmlTextWriter formatter = new XmlTextWriter(stream, Encoding.UTF8); + XmlDocument doc = new XmlDocument(); + + doc.LoadXml(xmlstream); + formatter.Formatting = Formatting.Indented; + doc.WriteContentTo(formatter); + formatter.Flush(); + return stream; + } + + private static string GetObjectXml(Scene scene) + { string xmlstream = ""; List EntityList = scene.GetEntities(); @@ -69,29 +95,25 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser xmlstream += xml; xmlstream += ""; + return xmlstream; + } - MemoryStream stream = new MemoryStream(); - XmlTextWriter formatter = new XmlTextWriter(stream, Encoding.UTF8); - XmlDocument doc = new XmlDocument(); - - doc.LoadXml(xmlstream); - formatter.Formatting = Formatting.Indented; - doc.WriteContentTo(formatter); - formatter.Flush(); - - stream.Seek(0, SeekOrigin.Begin); - + private static void CreateXmlFile(MemoryStream xmlStream, string fileName) + { FileStream objectsFile = new FileStream(fileName, FileMode.Create); - stream.WriteTo(objectsFile); + xmlStream.WriteTo(objectsFile); objectsFile.Flush(); objectsFile.Close(); + } + private static void CreateCompressedXmlFile(MemoryStream xmlStream, string fileName) + { #region GZip Compressed Version FileStream objectsFileCompressed = new FileStream(fileName + ".gzs", FileMode.Create); MemoryStream gzipMSStream = new MemoryStream(); GZipStream gzipStream = new GZipStream(gzipMSStream, CompressionMode.Compress); - stream.WriteTo(gzipStream); + xmlStream.WriteTo(gzipStream); gzipMSStream.WriteTo(objectsFileCompressed); objectsFileCompressed.Flush(); objectsFileCompressed.Close(); -- cgit v1.1