Example #1
0
        public void Write(string key, string value)
        {
            string         sectionName = "antd.config";
            List <param>   tList;
            param          tItem;
            List <section> readList  = ReadAll();
            List <param>   paramList = new List <param>();

            if (readList != null)
            {
                paramList.AddRange(from sect in readList
                                   where sect.param != null
                                   select sect.param);
            }

            var oldItem = (from i in paramList
                           where i.key == key
                           select i).FirstOrDefault();

            if (oldItem == null)
            {
                param item = new param {
                    key   = key,
                    value = value
                };
                tItem = item;
            }
            else
            {
                tItem       = oldItem;
                tItem.value = value;
            }
            if (paramList.ToArray().Length < 1)
            {
                List <param> list = new List <param> {
                    tItem
                };
                tList = list;
            }
            else
            {
                paramList.Remove(oldItem);
                paramList.Add(tItem);
                tList = paramList;
            }

            XDocument document = new XDocument(
                new XDeclaration("1.0", "utf-8", "yes"),
                new XElement("section", new XAttribute("section", sectionName),
                             from el in tList
                             select new XElement("param",
                                                 new XAttribute("key", el.key),
                                                 new XAttribute("value", el.value)
                                                 )));

            foreach (string p in path)
            {
                document.Save(p);
            }
        }
Example #2
0
        public string ReadValue(string key)
        {
            List <section> list = ReadAll();

            if (list == null)
            {
                return(null);
            }
            List <param> parList = (from p in list
                                    where p.param != null
                                    select p.param).ToList();
            param param = (from v in parList
                           where v.key == key
                           select v).FirstOrDefault();

            if (param == null)
            {
                return(null);
            }
            return(param.value);
        }
Example #3
0
        public void Write(string key, string value)
        {
            string sectionName = "antd.config";
            List<param> tList;
            param tItem;
            List<section> readList = ReadAll();
            List<param> paramList = new List<param>();
            if (readList != null) {
                paramList.AddRange(from sect in readList
                                   where sect.param != null
                                   select sect.param);
            }

            var oldItem = (from i in paramList
                           where i.key == key
                           select i).FirstOrDefault();
            if (oldItem == null) {
                param item = new param {
                    key = key,
                    value = value
                };
                tItem = item;
            }
            else {
                tItem = oldItem;
                tItem.value = value;
            }
            if (paramList.ToArray().Length < 1) {
                List<param> list = new List<param> {tItem};
                tList = list;
            }
            else {
                paramList.Remove(oldItem);
                paramList.Add(tItem);
                tList = paramList;
            }

            XDocument document = new XDocument(
                new XDeclaration("1.0", "utf-8", "yes"),
                new XElement("section", new XAttribute("section", sectionName),
                            from el in tList
                            select new XElement("param",
                            new XAttribute("key", el.key),
                            new XAttribute("value", el.value)
            )));
            foreach (string p in path) {
                document.Save(p);
            }
        }