public void CreateXML(Template template) { XmlDocument xmlDoc = new XmlDocument(); //Represents an XML document, // Initializes a new instance of the XmlDocument class. XmlSerializer xmlSerializer = new XmlSerializer(template.GetType()); // Creates a stream whose backing store is memory. string XMLString = String.Empty; using (MemoryStream xmlStream = new MemoryStream()) { xmlSerializer.Serialize(xmlStream, template); xmlStream.Position = 0; //Loads the XML document from the specified string. xmlDoc.Load(xmlStream); XMLString = xmlDoc.InnerXml; } // create an xml file string templatefilepath = TemplateAbsolutePath + TemplateFileName; Directory.CreateDirectory(TemplateAbsolutePath); FileStream stream = File.Open(templatefilepath, FileMode.OpenOrCreate); byte[] data = new UTF8Encoding(false).GetBytes(XMLString); stream.Write(data, 0, data.Length); stream.Close(); stream.Dispose(); }
public Template LoadTemplateFromFile(string XMLfile, Template template) { XmlSerializer oXmlSerializer = new XmlSerializer(template.GetType()); //The StringReader will be the stream holder for the existing XML file string XMLString = File.ReadAllText(XMLfile); template = (Template) oXmlSerializer.Deserialize(new StringReader(XMLString)); //initially deserialized, the data is represented by an object without a defined type return template; }
internal Template GenetareDefaultTemplate() { //TemplateAbsolutePath = @"C:\Users\ttomar\Documents\CSSTerminal\DailyPPCSanity\"; //TemplateFileName = "DailyPPCSanity.xml"; Template template = new Template(); //template.Builds = new List<Build>(); //template.Name = "Daily Sanity PPC"; //Build Build_153 = Create153Build(); //Build Build_154 = Create154Build(); //Build Build_161 = Create161Build(); //template.Builds.Add(Build_153); //template.Builds.Add(Build_154); //template.Builds.Add(Build_161); template.ServerSessions = new List<ServerSession>(); //template.ServerSessions.Add(new ServerSession() { Name = "74-TL1", ServerIP = "10.220.17.74", SessionProtocol="TL1", Port =9090,LoadOnStartup=true }); //template.ServerSessions.Add(new ServerSession() { Name = "74-Telnet", ServerIP = "10.220.17.74", SessionProtocol = "Telnet", Port = 23, LoadOnStartup = true }); //template.ServerSessions.Add(new ServerSession() { Name = "74-Serial", ServerIP = "10.220.17.13", SessionProtocol = "Telnet", Port =10015, LoadOnStartup = true }); //template.ServerSessions.Add(new ServerSession() { Name = "174-TL1", ServerIP = "10.220.16.174", SessionProtocol = "TL1", Port = 9090, LoadOnStartup = true }); //template.ServerSessions.Add(new ServerSession() { Name = "174-Telnet", ServerIP = "10.220.16.174", SessionProtocol = "Telnet", Port = 23, LoadOnStartup = true }); //template.ServerSessions.Add(new ServerSession() { Name = "174-Serial", ServerIP = "10.220.17.13", SessionProtocol = "Telnet", Port = 10016, LoadOnStartup = true }); //template.NEs = new List<Entities.InfineraProductLine.NetworkElement>(); //template.NEs.Add(new Entities.InfineraProductLine.NetworkElement() { Name = "NE_74",IP="10.220.17.74" }); //template.NEs.Add(new Entities.InfineraProductLine.NetworkElement() { Name = "NE_174",IP="10.220.16.174" }); template.Name = "New Template*"; CurrentTemplate = template; return template; //CreateXML(template); }