public static void SaveConfigFile(string plainText) { if (!string.IsNullOrEmpty(plainText)) { ConfigHandler.Config = DeSerializeToConfigParams(plainText); } if (ConfigHandler.ServerDetail == null) { ConfigHandler.ServerDetail = ConfigHandler.Config.ServerDetails; } if (ConfigHandler.AgentDetail == null) { ConfigHandler.AgentDetail = ConfigHandler.Config.AgentInstaller; } ConfigHandler.Config.HostInfoes = ConfigHandler.HostInfoes; ConfigHandler.Config.ServerDetails = ConfigHandler.ServerDetail; plainText = SerializeToXML(ConfigHandler.Config); if (ConstantVariables.IsInDebug) { NormalSaveConfigFile(plainText); } else { EncryptAndSave(plainText); } }
public static string SerializeToXML(ConfigParameters configParameter) { string toXML = string.Empty; XmlSerializer xsSubmit = new XmlSerializer(typeof(ConfigParameters)); using (StringWriter sww = new StringWriter()) using (XmlWriter writer = XmlWriter.Create(sww)) { xsSubmit.Serialize(writer, configParameter); toXML = sww.ToString(); } return(toXML); }
public static ConfigParameters DeSerializeToConfigParams(string xml) { XmlSerializer ser = new XmlSerializer(typeof(ConfigParameters)); StringReader stringReader; stringReader = new StringReader(xml); XmlTextReader xmlReader; xmlReader = new XmlTextReader(stringReader); ConfigParameters configParams = (ConfigParameters)ser.Deserialize(xmlReader); xmlReader.Close(); stringReader.Close(); return(configParams); }