public void Restore(Stream stream, Uri projecturi) //public void Restore( StringReader stringreader, Uri projecturi ) { WorldModel worldmodel = MetaverseClient.GetInstance().worldstorage; // note to self: should make these types a publisher/subscriber thing //XmlSerializer serializer = new XmlSerializer( typeof( World ), new Type[]{ // typeof( Avatar ), // typeof( FractalSplineCylinder ), // typeof( FractalSplineRing ), // typeof( FractalSplineBox ), // typeof( FractalSplineTorus ), // typeof( FractalSplinePrism ), // typeof( FractalSplineTube ) // } ); //DialogHelpers.ShowInfoMessage( null, serializer.Deserialize(filestream).GetType().ToString()); ProjectFileController.GetInstance().SetProjectPath(projecturi); StreamReader sr = new StreamReader(stream); string contents = sr.ReadToEnd(); sr.Close(); StringReader stringreader = new StringReader(contents); OsmpXmlSerializer.GetInstance().RegisterType(typeof(World)); World world = (World)OsmpXmlSerializer.GetInstance().Deserialize(stringreader); stringreader.Close(); //World world = (World)serializer.Deserialize( stream ); worldmodel.Clear(); foreach (Entity entity in world.Entities) { if (entity.GetType() != typeof(Avatar)) { LogFile.WriteLine("WorldPersistToXml, restoring: " + entity); worldmodel.AddEntity(entity); } } if (world.TerrainModel.HeightmapFilename != "") { HeightMapPersistence.GetInstance().Load(world.TerrainModel.HeightmapFilename); } worldmodel.terrainmodel.texturestagesarray = world.TerrainModel.texturestagesarray; LogFile.WriteLine(worldmodel); worldmodel.terrainmodel.MinHeight = world.TerrainModel.MinHeight; worldmodel.terrainmodel.MaxHeight = world.TerrainModel.MaxHeight; worldmodel.terrainmodel.OnTerrainModified(); }
public void Store(string filename) { LogFile.WriteLine("store " + filename); WorldModel worldmodel = MetaverseClient.GetInstance().worldstorage; ArrayList types = new ArrayList(); foreach (Entity entity in worldmodel.entities) { if (!types.Contains(entity.GetType())) { types.Add(entity.GetType()); } } //XmlSerializer serializer = new XmlSerializer( worldmodel.entities.GetType(), (Type[])types.ToArray( typeof( Type ) ) ); //XmlSerializer serializer = new XmlSerializer( typeof( World), //(Type[])types.ToArray( typeof( Type ) ) ); //StreamWriter streamwriter = new StreamWriter( filename ); ProjectFileController.GetInstance().SetProjectPath(new Uri(Path.GetDirectoryName(filename) + "/")); List <Entity> entitiestoserialize = new List <Entity>(); foreach (Entity entity in worldmodel.entities) { // note to self: need to check root entity in fact // doesnt matter yet because no linking if (entity.GetType() != typeof(Avatar)) { entitiestoserialize.Add(entity); } } World world = new World(); world.Entities = entitiestoserialize.ToArray(); world.TerrainModel = MetaverseClient.GetInstance().worldstorage.terrainmodel; StringWriter stringwriter = new StringWriter(); OsmpXmlSerializer.GetInstance().RegisterType(typeof(World)); OsmpXmlSerializer.GetInstance().Serialize(stringwriter, world); stringwriter.Close(); StreamWriter sw = new StreamWriter(filename, false); sw.WriteLine(stringwriter.ToString()); sw.Close(); //serializer.Serialize( streamwriter, world ); //streamwriter.Close(); }