public void TestSerializeModelObject() { var s = new ModelSerializer(StringSerializer.Create(), new LoadedTypeSerializer()); object1.Object = null; // Remove unresolvable dependency var strm = new MemoryStream(); streamWriter = new StreamWriter(strm); var writer = new SectionedStreamWriter(streamWriter); s.SerializeAttributes(object1, writer); streamWriter.Flush(); strm.Position = 0; // For testing string serialized = getStringFromStream(strm); var deserialized = new TestObject(); s.DeserializeAttributes(deserialized, new SectionedStreamReader(new StreamReader(strm))); Assert.AreEqual(object1.ToString(), deserialized.ToString()); }
public void TestSerializeCustomStringSerializerAttribute() { var model = new ModelContainer(); SimpleModelObject.CurrentModelContainer = model; var obj = new TestCustomObject(); obj.Text = "Hello "; var strm = new MemoryStream(); var writer = new StreamWriter(strm); var serializer = new ModelSerializer(StringSerializer.Create(), new LoadedTypeSerializer()); serializer.QueueForSerialization(obj); serializer.Serialize(writer); writer.Flush(); strm.Position = 0; var str = getStringFromStream(strm); var objects = serializer.Deserialize(new StreamReader(strm)); Assert.AreEqual(obj, objects[0]); }
public void TestPersistAttributeTypeScope() { var s = new ModelSerializer(StringSerializer.Create(), new LoadedTypeSerializer()); // Add a new entity to the original model, it should not be serialized! new Engine.WorldRendering.Entity(); var strm = new MemoryStream(); var writer = new StreamWriter(strm); s.Serialize(model, writer); var deserialized = new Data.ModelContainer(); writer.Flush(); strm.Position = 0; // For testing string serialized = getStringFromStream(strm); SimpleModelObject.CurrentModelContainer = deserialized; s.Deserialize(new StreamReader(strm)); Assert.AreNotEqual(model.Objects.Count, deserialized.Objects.Count); Assert.AreEqual(model.Objects[0].ToString(), deserialized.Objects[0].ToString()); Assert.AreEqual(model.Objects[1].ToString(), deserialized.Objects[1].ToString()); }
public void TestSerializeObjectsTree() { var model = new ModelContainer(); SimpleModelObject.CurrentModelContainer = model; var array1 = new TestObjectArray(); var array2 = new TestObjectArray(); var obj1 = new TestObject { Getal = 1 }; var obj2 = new TestObject { Getal = 2 }; var obj3 = new TestObject { Getal = 3 }; var obj4 = new TestObject { Getal = 4 }; var obj5 = new TestObject { Getal = 5 }; array1.Objects.Add(obj1); array2.Objects.Add(obj2); array2.Objects.Add(obj3); obj3.Object = obj4; obj4.Object = obj4; obj5.Object = obj5; var strm = new MemoryStream(); var writer = new StreamWriter(strm); var serializer = new ModelSerializer(StringSerializer.Create(), new LoadedTypeSerializer()); serializer.QueueForSerialization(array2); serializer.Serialize(writer); writer.Flush(); strm.Position = 0; var str = getStringFromStream(strm); }
public EngineTWContext(TWEngine engine) { this.engine = engine; Context = new TW.Context(); game = new GraphicsWrapper(); // TODO: make better setting resolution game.Form.FormSize = new Size(1280, 720); game.InitDirectX(); // TODO: more resolution sjit game.SpectaterCamera.AspectRatio = (float)game.Form.Form.ClientSize.Width / game.Form.Form.ClientSize.Height; typeSerializer = new TypeSerializer(engine); var container = new DataWrapper(engine.TraceLogger); physX = new PhysicsWrapper(); physX.Initialize(); setTWGlobals(container); //updateActiveGameplayAssembly(); //createSimulators(); var stringSerializer = StringSerializer.Create(); stringSerializer.AddConditional(new FilebasedAssetSerializer()); TW.Data.ModelSerializer = new ModelSerializer(stringSerializer, typeSerializer); TW.Data.TypeSerializer = typeSerializer; }
public void TestSerializeArray() { var array = new TestObjectArray(); array.Objects = new List <TestObject>(); array.Objects.Add(object1); array.Objects.Add(object2); var s = new ModelSerializer(StringSerializer.Create(), new LoadedTypeSerializer()); var strm = new MemoryStream(); var writer = new StreamWriter(strm); s.Serialize(model, writer); var deserialized = new Data.ModelContainer(); writer.Flush(); strm.Position = 0; // For testing string serialized = getStringFromStream(strm); SimpleModelObject.CurrentModelContainer = deserialized; s = new ModelSerializer(StringSerializer.Create(), new LoadedTypeSerializer()); s.Deserialize(new StreamReader(strm)); Assert.AreEqual(model.Objects.Count, deserialized.Objects.Count); Assert.AreEqual(model.Objects[0].ToString(), deserialized.Objects[0].ToString()); Assert.AreEqual(model.Objects[1].ToString(), deserialized.Objects[1].ToString()); Assert.AreEqual(model.Objects[2].ToString(), deserialized.Objects[2].ToString()); }