Example #1
0
        private static void CreateIni(IniItem[] items = null, string p = "")
        {
            IniItemCollection cls = new IniItemCollection();

            if (items == null)
            {
                IniItem itm = new IniItem();
                itm.Key   = "CrawlerDefault";
                itm.Value = "http://media.kisline.com/fininfo/mainFininfo.nice?paper_stock={0}&nav=4&header=N";
                items     = new IniItem[] { itm };

                p = Properties.Settings.Default.ini;
            }
            else
            {
                if (items.Length == 0)
                {
                    throw new ArgumentException("Items length zero", "Length");
                }
                if (p == string.Empty)
                {
                    throw new ArgumentException("File path null", "Path");
                }
            }
            cls.Items = items;

            StreamWriter  objStreamWriter = new StreamWriter(p);
            XmlSerializer x = new XmlSerializer(cls.GetType());

            x.Serialize(objStreamWriter, cls);
            objStreamWriter.Close();
        }
Example #2
0
        public static Dictionary <string, string> ReadIni(string p)
        {
            if (!File.Exists(p))
            {
                throw new ArgumentException("File not exist: " + p);
            }

            Dictionary <string, string> itms = new Dictionary <string, string>();
            XmlDocument    doc = new XmlDocument();
            XPathNavigator nav;

            try
            {
                doc.Load(p);
                nav = doc.CreateNavigator();
                nav.MoveToChild("IniItemCollection", string.Empty);
                nav.MoveToChild("Items", string.Empty);

                if (nav.HasChildren)
                {
                    XmlSerializer ser = new XmlSerializer(typeof(IniItem));
                    XmlReader     rdr = default(XmlReader);

                    nav.MoveToFirstChild();
                    do
                    {
                        IniItem itm = default(IniItem);
                        if (nav.Value == string.Empty)
                        {
                            continue;
                        }

                        rdr           = nav.ReadSubtree();
                        itm           = (IniItem)ser.Deserialize(rdr);
                        itms[itm.Key] = itm.Value;
                    } while (nav.MoveToNext());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception at ApplicationSettings.LoadAPIKeys()\r\n" + ex.Message, Properties.Settings.Default.tm, MessageBoxButtons.OK);
            }

            return(itms);
        }
Example #3
0
        public void Add(string k, string v)
        {
            Dictionary <string, IniItem> dic = itms.ToList().ToDictionary(p => p.Key);

            if (dic.ContainsKey(k))
            {
                throw new ConstraintException("Duplicate Key " + k);
            }
            else
            {
                IniItem itm = new IniItem();
                itm.Key   = k;
                itm.Value = v;

                Array.Resize(ref itms, itms.Length + 1);
                itms[itms.Length - 1] = itm;
            }
        }
Example #4
0
        public void Replace(string k, string v)
        {
            Dictionary <string, IniItem> dic = itms.ToList().ToDictionary(p => p.Key);

            if (!dic.ContainsKey(k))
            {
                throw new KeyNotFoundException("Key " + k + " not found");
            }
            else
            {
                IniItem        itm = dic[k];
                List <IniItem> lst = itms.ToList();

                lst.Remove(itm);
                itm       = new IniItem();
                itm.Key   = k;
                itm.Value = v;
                lst.Add(itm);
                itms = lst.ToArray();
            }
        }
Example #5
0
        public static void CreateAPIKeysIni(string provider)
        {
            IniItem        itm   = default(IniItem);
            List <IniItem> items = new List <IniItem>();
            string         p     = APIIniPath(provider, IniCategory.APIKeys); if (File.Exists(p))

            {
                File.Delete(p);
            }

            foreach (CommodityType t in Enum.GetValues(typeof(CommodityType)))
            {
                if ((int)t < 0)
                {
                    continue;
                }
                itm = new IniItem(); itm.Key = ((int)t).ToString(); itm.Value = string.Empty;
                items.Add(itm);
            }

            CreateIni(items.ToArray(), p);
        }