28 using System.Collections.Generic;
30 using System.IO.Compression;
33 using OpenSim.Region.Framework.Scenes;
34 using OpenSim.Region.Framework.Scenes.Serialization;
36 namespace OpenSim.
Region.CoreModules.
World.Serialiser
38 internal class SerialiseObjects : IFileSerialiser
40 #region IFileSerialiser Members
42 public string WriteToFile(
Scene scene,
string dir)
44 string targetFileName = Path.Combine(dir,
"objects.xml");
46 SaveSerialisedToFile(targetFileName, scene);
53 public void SaveSerialisedToFile(
string fileName,
Scene scene)
55 string xmlstream = GetObjectXml(scene);
57 using (MemoryStream stream = ReformatXmlString(xmlstream))
59 stream.Seek(0, SeekOrigin.Begin);
60 CreateXmlFile(stream, fileName);
62 stream.Seek(0, SeekOrigin.Begin);
63 CreateCompressedXmlFile(stream, fileName);
67 private static MemoryStream ReformatXmlString(
string xmlstream)
69 MemoryStream stream =
new MemoryStream();
70 XmlTextWriter formatter =
new XmlTextWriter(stream, Encoding.UTF8);
71 XmlDocument doc =
new XmlDocument();
73 doc.LoadXml(xmlstream);
74 formatter.Formatting = Formatting.Indented;
75 doc.WriteContentTo(formatter);
80 private static string GetObjectXml(
Scene scene)
82 string xmlstream =
"<scene>";
85 List<string> EntityXml =
new List<string>();
91 EntityXml.Add(SceneObjectSerializer.ToXml2Format((SceneObjectGroup)ent));
96 foreach (
string xml
in EntityXml)
99 xmlstream +=
"</scene>";
103 private static void CreateXmlFile(MemoryStream xmlStream,
string fileName)
105 FileStream objectsFile =
new FileStream(fileName, FileMode.Create);
107 xmlStream.WriteTo(objectsFile);
112 private static void CreateCompressedXmlFile(MemoryStream xmlStream,
string fileName)
114 #region GZip Compressed Version
116 using (FileStream objectsFileCompressed =
new FileStream(fileName +
".gzs", FileMode.Create))
117 using (MemoryStream gzipMSStream =
new MemoryStream())
121 xmlStream.WriteTo(gzipStream);
124 gzipMSStream.WriteTo(objectsFileCompressed);
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
Ionic.Zlib.GZipStream GZipStream
Ionic.Zlib.CompressionMode CompressionMode