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(); }
public void SaveConfig(string ipath) { if (File.Exists(ipath)) { XmlDocument doc = new XmlDocument(); XPathNavigator nav = default(XPathNavigator); doc.Load(ipath); nav = doc.CreateNavigator(); nav.MoveToChild("IniItemCollection", string.Empty); nav.MoveToChild("Items", string.Empty); XmlNode node = doc.SelectSingleNode("//IniItem[Key = '" + _key + "']"); if (node != null) { node.SelectSingleNode("Value").InnerText = _value; } else { using (XmlWriter writer = nav.AppendChild()) { XmlSerializer serializer = new XmlSerializer(this.GetType()); writer.WriteComment(""); serializer.Serialize(writer, this); } } doc.Save(ipath); } else { StreamWriter objStreamWriter = new StreamWriter(ipath); IniItemCollection cls = new IniItemCollection(); XmlSerializer x = new XmlSerializer(cls.GetType()); cls.Items = new IniItem[] { this }; x.Serialize(objStreamWriter, cls); objStreamWriter.Close(); } }
public static Dictionary <int, string> LoadAPIKeys(string p) { Dictionary <int, string> apikeys = new Dictionary <int, string>(); Dictionary <string, string> dic; int key = -1; string msg = string.Empty; try { dic = IniItemCollection.ReadIni(p); foreach (string k in dic.Keys) { if (int.TryParse(k, out key)) { if (!string.IsNullOrEmpty(dic[k])) { apikeys[key] = dic[k]; } } else { msg += (msg != string.Empty ? "\r\n" : string.Empty) + "Error reading an int " + k; } } } catch (Exception ex) { MessageBox.Show("Error reading file " + p + "\r\n" + ex.Message, Properties.Settings.Default.tm, MessageBoxButtons.OK); } if (msg != string.Empty) { MessageBox.Show(msg, Properties.Settings.Default.tm, MessageBoxButtons.OK); } return(apikeys); }
public static bool LoadIni() { string qsrc = string.Empty; Dictionary <string, string> itms = IniItemCollection.ReadIni(Properties.Settings.Default.ini); if (itms == null) { throw new InvalidOperationException("Check ini file " + Properties.Settings.Default.ini); } if (itms.Count == 0) { throw new InvalidOperationException("Check ini file " + Properties.Settings.Default.ini); } foreach (string k in itms.Keys) { switch (k) { case "CrawlerDefault": Properties.Settings.Default.crawler = itms[k]; break; case "QuoteSource": qsrc = itms[k]; break; case "FilteringScheduledAt": Properties.Settings.Default.fltr_schedule = itms[k]; break; case "FilteringPassiveCollection": Properties.Settings.Default.fltr_passive = bool.Parse(itms[k]); break; case "TaskRemoteFeedType": Properties.Settings.Default.task_feed_type = int.Parse(itms[k]); break; case "FilterResultWrapper": Properties.Settings.Default.fltr_wrap = itms[k]; break; } } if (qsrc != QuandlAPI._PROVIDER /* && more */) { qsrc = string.Empty; } if (qsrc == string.Empty && Properties.Settings.Default.qsource == string.Empty) { Properties.Settings.Default.qsource = QuandlAPI._PROVIDER; } if (Properties.Settings.Default.qsource == QuandlAPI._PROVIDER) { if (!CreateDefaultDbConfig()) { MessageBox.Show("Error creating default DB config.", Properties.Settings.Default.tm, MessageBoxButtons.OK); return(false); } } else { throw new NotImplementedException(); } return(true); }