/// <summary> /// 添加一个类命名空间 /// </summary> /// <param name="cns"></param> public bool Add(Model.ConfigServers cns) { try { //先删除 Delete(cns.Name); XElement xelem = XElement.Load(XmlFile); XElement newLog = new XElement("server", new XElement("name", cns.Name), new XElement("type", cns.Type), new XElement("servername", cns.ServerName), new XElement("database", cns.Database), new XElement("uid", cns.Uid), new XElement("pwd", cns.Pwd.IsNullOrEmpty() ? "" : Common.Encryption.DesEncrypt(cns.Pwd)), new XElement("port", cns.Port), new XElement("file", cns.file) ); xelem.Add(newLog); xelem.Save(XmlFile); return(true); } catch { return(false); } }
/// <summary> /// 保存类命名空间 /// </summary> /// <param name="cns"></param> /// <returns></returns> public bool Save(Model.ConfigServers cns, string oldmodel = "") { if (!oldmodel.IsNullOrEmpty()) { Delete(oldmodel); } return(Add(cns)); }
/// <summary> /// 查询一个命名空间 /// </summary> /// <param name="namespace1"></param> /// <returns></returns> public Model.ConfigServers Get(string name) { try { XElement xelem = XElement.Load(XmlFile); var queryXML = from xele in xelem.Elements("namespaceclass") where xele.Element("model").Value == name select new { name = xele.Element("name").Value, type = xele.Element("type").Value, servername = xele.Element("servername").Value, database = xele.Element("database").Value, uid = xele.Element("uid").Value, pwd = xele.Element("pwd").Value, port = xele.Element("port").Value, file = xele.Element("file").Value }; Model.ConfigServers cns = new Model.ConfigServers(); if (queryXML.Count() > 0) { var q = queryXML.First(); cns.Name = q.servername + q.type; cns.Database = q.database; cns.file = q.file; cns.Port = q.port; cns.Pwd = q.pwd.IsNullOrEmpty() ? "" : Common.Encryption.DesDecrypt(q.pwd); cns.Uid = q.uid; cns.Type = q.type; cns.ServerName = q.servername; } return(cns); } catch { return(null); } }
/// <summary> /// 查询一个命名空间 /// </summary> /// <param name="namespace1"></param> /// <returns></returns> public Model.ConfigServers Get(string name) { try { XElement xelem = XElement.Load(XmlFile); var queryXML = from xele in xelem.Elements("namespaceclass") where xele.Element("model").Value == name select new { name = xele.Element("name").Value, type = xele.Element("type").Value, servername = xele.Element("servername").Value, database = xele.Element("database").Value, uid = xele.Element("uid").Value, pwd = xele.Element("pwd").Value, port = xele.Element("port").Value, file = xele.Element("file").Value }; Model.ConfigServers cns = new Model.ConfigServers(); if (queryXML.Count() > 0) { var q = queryXML.First(); cns.Name = q.servername + q.type; cns.Database = q.database; cns.file = q.file; cns.Port = q.port; cns.Pwd = q.pwd.IsNullOrEmpty() ? "" : Common.Encryption.DesDecrypt(q.pwd); cns.Uid = q.uid; cns.Type = q.type; cns.ServerName = q.servername; } return cns; } catch { return null; } }