public void Create(AppConfigurationType type, string name, string value, bool encrypt, string comment = null) { if (type == AppConfigurationType.Parameter) { XmlElement parametro = _xml.CreateElement(CONF_Parameter); parametro.SetAttribute(CONF_Parameter_Name, name); parametro.SetAttribute(CONF_Parameter_Value, encrypt ? _encrypter.Encrypt(value) : value); _xml.DocumentElement.GetElementsByTagName(CONF_Parameters)[0].AppendChild(parametro); if (comment != null) { _xml.DocumentElement.GetElementsByTagName(CONF_Parameters)[0].InsertBefore(_xml.CreateComment(comment), parametro); } _xml.Save(this.Path); } else { XmlElement parametro = _xml.CreateElement(CONF_ConnectionString); parametro.SetAttribute(CONF_ConnectionString_Name, name); parametro.SetAttribute(CONF_ConnectionString_Value, encrypt ? _encrypter.Encrypt(value) : value); _xml.DocumentElement.GetElementsByTagName(CONF_Connections)[0].AppendChild(parametro); if (comment != null) { _xml.DocumentElement.GetElementsByTagName(CONF_Connections)[0].InsertBefore(_xml.CreateComment(comment), parametro); } _xml.Save(Path); } }
public List <AppConfigurationItemModel> ListAll(AppConfigurationType type, bool decrypt = false) { if (type == AppConfigurationType.ConexionString) { var result = new List <AppConfigurationItemModel>(); XmlNodeList nodes = _xml.DocumentElement.GetElementsByTagName(CONF_Connections)[0].SelectNodes(CONF_ConnectionString); foreach (XmlNode nod in nodes) { var name = nod.Attributes[CONF_ConnectionString_Name].Value; var value = decrypt ? _encrypter.Decrypt(nod.Attributes[CONF_ConnectionString_Value].Value) : nod.Attributes[CONF_ConnectionString_Value].Value; var item = new AppConfigurationItemModel(AppConfigurationType.ConexionString, name, value); result.Add(item); } return(result); } else { var result = new List <AppConfigurationItemModel>(); XmlNodeList nodes = _xml.DocumentElement.GetElementsByTagName(CONF_Parameters)[0].SelectNodes(CONF_Parameter); foreach (XmlNode nod in nodes) { var name = nod.Attributes[CONF_Parameter_Name].Value; var value = decrypt ? _encrypter.Decrypt(nod.Attributes[CONF_Parameter_Value].Value) : nod.Attributes[CONF_Parameter_Value].Value; var item = new AppConfigurationItemModel(AppConfigurationType.Parameter, name, value); result.Add(item); } return(result); } }
public AppConfigurationItemModel(AppConfigurationType type, string name, string value) { Type = type; Name = name; Value = new Castable(value); }
public void Update(AppConfigurationType type, string name, string value, bool encrypt, string comment = null) { bool finded = false; if (type == AppConfigurationType.Parameter) { var nodes = _xml.DocumentElement.GetElementsByTagName(CONF_Parameters)[0].SelectNodes(CONF_Parameter); foreach (XmlNode nod in nodes) { if (nod.Attributes[CONF_Parameter_Name].Value == name) { nod.Attributes[CONF_Parameter_Value].Value = value; finded = true; if (comment != null) { XmlComment prevComment = (XmlComment)nod.PreviousSibling; if (prevComment == null) { _xml.InsertBefore(_xml.CreateComment(comment), nod); } else { prevComment.Value = comment; } } break; } } if (!finded) { throw new Exception($"the parameter {name} was not found"); } _xml.Save(this.Path); } else { var nodes = _xml.DocumentElement.GetElementsByTagName(CONF_Connections)[0].SelectNodes(CONF_ConnectionString); foreach (XmlNode nod in nodes) { if (nod.Attributes[CONF_ConnectionString_Name].Value == name) { nod.Attributes[CONF_ConnectionString_Value].Value = value; finded = true; if (comment != null) { _xml.InsertBefore(_xml.CreateComment(comment), nod); } break; } } if (!finded) { throw new Exception($"the parameter {name} was not found"); } _xml.Save(this.Path); } }