public void SerializeXml(IList<AccreteSharp.StarSystem> starSystems) { if (starSystems != null) { MemoryStream memXmlStream = new MemoryStream(); XmlSerializer serializer = new XmlSerializer(typeof(StarSystem), null, new Type[] { typeof(Body), }, null, null, null); StarSystem ssx = new AccreteSharp.Ssx.StarSystem(); ssx.Name = "Generated"; ssx.Bodies.Add( new Body { Name = "Primary", Mass = starSystems[0].Primary.SM * PhysicalConstants.SOLAR_MASS_IN_GRAMS / 1000, Period = 10832, Radius = starSystems[0].Primary.radius * PhysicalConstants.SUN_RADIUS, XPosition = 0, YPosition = 0, ZPosition = 0, XVelocity = 0, YVelocity = 0, ZVelocity = 0 }); int c = 0; foreach (Planet p in starSystems[0].planetsList) { c++; ssx.Bodies.Add( new Body { Name = "Planet" + c.ToString(), Mass = p.mass * PhysicalConstants.EARTH_MASS_IN_GRAMS / 1000, Period = p.orb_period, Radius = p.radius, XPosition = p.X, YPosition = p.Y, ZPosition = p.Z, XVelocity = 0, YVelocity = p.Velocity, ZVelocity = 0 }); } serializer.Serialize(memXmlStream, ssx); XmlDocument xmlDoc = new XmlDocument(); memXmlStream.Seek(0, SeekOrigin.Begin); xmlDoc.Load(memXmlStream); XmlTextWriter wr = new XmlTextWriter("system.ssx", System.Text.Encoding.ASCII); wr.Formatting = Formatting.Indented; wr.IndentChar = '\t'; wr.Indentation = 1; XmlWriterSettings settings = new XmlWriterSettings(); XmlWriter writer = XmlWriter.Create(wr, settings); xmlDoc.WriteTo(writer); writer.Flush(); } }
public void SerializeXml(IList <AccreteSharp.StarSystem> starSystems) { if (starSystems != null) { MemoryStream memXmlStream = new MemoryStream(); XmlSerializer serializer = new XmlSerializer(typeof(StarSystem), null, new Type[] { typeof(Body), }, null, null, null); StarSystem ssx = new AccreteSharp.Ssx.StarSystem(); ssx.Name = "Generated"; ssx.Bodies.Add( new Body { Name = "Primary", Mass = starSystems[0].Primary.SM * PhysicalConstants.SOLAR_MASS_IN_GRAMS / 1000, Period = 10832, Radius = starSystems[0].Primary.radius * PhysicalConstants.SUN_RADIUS, XPosition = 0, YPosition = 0, ZPosition = 0, XVelocity = 0, YVelocity = 0, ZVelocity = 0 }); int c = 0; foreach (Planet p in starSystems[0].planetsList) { c++; ssx.Bodies.Add( new Body { Name = "Planet" + c.ToString(), Mass = p.mass * PhysicalConstants.EARTH_MASS_IN_GRAMS / 1000, Period = p.orb_period, Radius = p.radius, XPosition = p.X, YPosition = p.Y, ZPosition = p.Z, XVelocity = 0, YVelocity = p.Velocity, ZVelocity = 0 }); } serializer.Serialize(memXmlStream, ssx); XmlDocument xmlDoc = new XmlDocument(); memXmlStream.Seek(0, SeekOrigin.Begin); xmlDoc.Load(memXmlStream); XmlTextWriter wr = new XmlTextWriter("system.ssx", System.Text.Encoding.ASCII); wr.Formatting = Formatting.Indented; wr.IndentChar = '\t'; wr.Indentation = 1; XmlWriterSettings settings = new XmlWriterSettings(); XmlWriter writer = XmlWriter.Create(wr, settings); xmlDoc.WriteTo(writer); writer.Flush(); } }