public bool LoadData() { lock (this) { Keys.Clear(); } // Checking if db isn't broken Core.RecoverFile(datafile_xml, pChannel.Name); if (LoadAncientDB()) { Parent.Log("Obsolete database found for " + pChannel.Name + " converting to new format"); Save(); File.Delete(datafile_raw); return(true); } if (!File.Exists(datafile_xml)) { // Create db Save(); return(true); } try { XmlDocument data = new XmlDocument(); if (!File.Exists(datafile_xml)) { lock (this) { Keys.Clear(); } return(true); } data.Load(datafile_xml); lock (this) { Keys.Clear(); Aliases.Clear(); } foreach (XmlNode xx in data.ChildNodes[0].ChildNodes) { if (xx.Name == "alias") { InfobotAlias _Alias = new InfobotAlias(xx.Attributes[0].Value, xx.Attributes[1].Value); lock (this) { Aliases.Add(_Alias); } continue; } bool raw = false; string name = ""; string value = ""; string user = "******"; string date = ""; string time = ""; bool is_act = false; int number = 0; foreach (XmlAttribute x in xx.Attributes) { switch (x.Name) { case "key_name": name = x.Value; break; case "data": value = x.Value; break; case "created_date": date = x.Value; break; case "nickname": user = x.Value; break; case "touched": time = x.Value; break; case "triggered": number = int.Parse(x.Value); break; case "raw": raw = bool.Parse(x.Value); break; case "is_act": is_act = bool.Parse(x.Value); break; } } InfobotKey _key = new InfobotKey(name, value, user, "false", date, time, number, raw, is_act); lock (this) { Keys.Add(_key); } } } catch (Exception fail) { Parent.HandleException(fail, "infobot"); } return(true); }
public bool LoadData() { Keys.Clear(); // Checking if db isn't broken core.recoverFile(datafile_xml, Channel); if (Load()) { core.Log("Obsolete database found for " + Channel + " converting to new format"); Save(); File.Delete(datafile_raw); return true; } if (!File.Exists(datafile_xml)) { // Create db Save(); return true; } try { System.Xml.XmlDocument data = new System.Xml.XmlDocument(); if (!File.Exists(datafile_xml)) { Keys.Clear(); return true; } data.Load(datafile_xml); lock (Keys) { lock (Alias) { Keys.Clear(); Alias.Clear(); foreach (System.Xml.XmlNode xx in data.ChildNodes[0].ChildNodes) { if (xx.Name == "alias") { InfobotAlias _Alias = new InfobotAlias(xx.Attributes[0].Value, xx.Attributes[1].Value); Alias.Add(_Alias); continue; } bool raw = false; if (xx.Attributes.Count > 6) { raw = bool.Parse(xx.Attributes[6].Value); } InfobotKey _key = new InfobotKey(xx.Attributes[0].Value, xx.Attributes[1].Value, xx.Attributes[2].Value, "false", xx.Attributes[3].Value, xx.Attributes[4].Value, int.Parse(xx.Attributes[5].Value), raw); Keys.Add(_key); } } } } catch (Exception fail) { core.handleException(fail); } return true; }
public bool LoadData() { lock (this) { Keys.Clear(); } // Checking if db isn't broken Core.RecoverFile(datafile_xml, pChannel.Name); if (LoadAncientDB()) { Parent.Log("Obsolete database found for " + pChannel.Name + " converting to new format"); Save(); File.Delete(datafile_raw); return true; } if (!File.Exists(datafile_xml)) { // Create db Save(); return true; } try { XmlDocument data = new XmlDocument(); if (!File.Exists(datafile_xml)) { lock (this) { Keys.Clear(); } return true; } data.Load(datafile_xml); lock (this) { Keys.Clear(); Aliases.Clear(); } foreach (XmlNode xx in data.ChildNodes[0].ChildNodes) { if (xx.Name == "alias") { InfobotAlias _Alias = new InfobotAlias(xx.Attributes[0].Value, xx.Attributes[1].Value); lock (this) { Aliases.Add(_Alias); } continue; } bool raw = false; string name = ""; string value = ""; string user = "******"; string date = ""; string time = ""; bool is_act = false; int number = 0; foreach (XmlAttribute x in xx.Attributes) { switch (x.Name) { case "key_name": name = x.Value; break; case "data": value = x.Value; break; case "created_date": date = x.Value; break; case "nickname": user = x.Value; break; case "touched": time = x.Value; break; case "triggered": number = int.Parse(x.Value); break; case "raw": raw = bool.Parse(x.Value); break; case "is_act": is_act = bool.Parse(x.Value); break; } } InfobotKey _key = new InfobotKey(name, value, user, "false", date, time, number, raw, is_act); lock (this) { Keys.Add(_key); } } } catch (Exception fail) { Parent.HandleException(fail, "infobot"); } return true; }