From a0b8c46ef37f6bf44de36ab60fae741076d8a3bf Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Mon, 21 Apr 2008 09:38:51 +0000 Subject: [PATCH] * Various refactorings. --- .../Modules/AsteriskVoiceModule.cs | 6 +-- .../ExportSerialiser/SerialiseObjects.cs | 48 ++++++++++++++----- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/OpenSim/Region/Environment/Modules/AsteriskVoiceModule.cs b/OpenSim/Region/Environment/Modules/AsteriskVoiceModule.cs index 1b537c20a2..38c0c1d7a6 100644 --- a/OpenSim/Region/Environment/Modules/AsteriskVoiceModule.cs +++ b/OpenSim/Region/Environment/Modules/AsteriskVoiceModule.cs @@ -163,7 +163,7 @@ namespace OpenSim.Region.Environment.Modules // setup response to client Hashtable creds = new Hashtable(); creds["channel_uri"] = String.Format("sip:{0}@{1}", - m_scene.RegionInfo.RegionID.ToString(), m_sipDomain); + m_scene.RegionInfo.RegionID, m_sipDomain); string regionName = m_scene.RegionInfo.RegionName; ScenePresence avatar = m_scene.GetScenePresence(agentID); @@ -207,8 +207,6 @@ namespace OpenSim.Region.Environment.Modules return "undef"; } - - return null; } /// @@ -282,8 +280,6 @@ namespace OpenSim.Region.Environment.Modules return "undef"; } - - return null; } } } diff --git a/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs b/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs index 7e5cf47a19..277370da14 100644 --- a/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs +++ b/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs @@ -50,6 +50,32 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser #endregion 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 = ""; @@ -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();