RecoverFile() 공개 정적인 메소드

Recover a file that was previously stored
public static RecoverFile ( string name, string ch = "unknown object" ) : bool
name string
ch string
리턴 bool
예제 #1
0
        public WMIBMySQL()
        {
            string file = Variables.ConfigurationDirectory + Path.DirectorySeparatorChar + "unwrittensql.xml";

            Core.RecoverFile(file);
            if (File.Exists(file))
            {
                Syslog.WarningLog("There is a mysql dump file from previous run containing mysql rows that were never successfuly inserted, trying to recover them");
                XmlDocument document = new XmlDocument();
                using (TextReader sr = new StreamReader(file))
                {
                    document.Load(sr);
                    using (XmlNodeReader reader = new XmlNodeReader(document.DocumentElement))
                    {
                        XmlSerializer xs = new XmlSerializer(typeof(Unwritten));
                        Unwritten     un = (Unwritten)xs.Deserialize(reader);
                        lock (unwritten.PendingRows)
                        {
                            unwritten.PendingRows.AddRange(un.PendingRows);
                        }
                    }
                }
            }
            Thread reco = new Thread(Exec)
            {
                Name = "MySQL/Recovery"
            };

            Core.ThreadManager.RegisterThread(reco);
            reco.Start();
        }
예제 #2
0
 private void FlushRows()
 {
     if (Recovering)
     {
         return;
     }
     // prevent multiple threads calling this function at same time
     lock (this)
     {
         string file = Variables.ConfigurationDirectory + Path.DirectorySeparatorChar + "unwrittensql.xml";
         if (File.Exists(file))
         {
             Core.BackupData(file);
             if (!File.Exists(Configuration.TempName(file)))
             {
                 Syslog.WarningLog("Unable to create backup file for " + file);
                 return;
             }
         }
         try
         {
             File.Delete(file);
             XmlSerializer xs     = new XmlSerializer(typeof(Unwritten));
             StreamWriter  writer = File.AppendText(file);
             lock (unwritten)
             {
                 xs.Serialize(writer, unwritten);
             }
             writer.Close();
             if (File.Exists(Configuration.TempName(file)))
             {
                 File.Delete(Configuration.TempName(file));
             }
         } catch (Exception fail)
         {
             Core.HandleException(fail);
             Syslog.WarningLog("Recovering the mysql unwritten dump because of exception to: " + file);
             Core.RecoverFile(file);
         }
     }
 }
예제 #3
0
 /// <summary>
 /// Load all roles
 /// </summary>
 public static void Init()
 {
     Core.RecoverFile(Configuration.Paths.Security);
     if (File.Exists(Configuration.Paths.Security))
     {
         DumpableDict  dict          = new DumpableDict();
         XmlSerializer xmlSerializer = new XmlSerializer(dict.GetType());
         using (StreamReader reader = new StreamReader(Variables.ConfigurationDirectory + Path.DirectorySeparatorChar + "security.xml"))
         {
             dict = (DumpableDict)xmlSerializer.Deserialize(reader);
         }
         // first we need to create all roles in the file, that is important
         foreach (DumpableDict.RoleInfo ri in dict.Roles)
         {
             Roles.Add(ri.Name, new Role(ri.Level));
         }
         foreach (DumpableDict.RoleInfo ri in dict.Roles)
         {
             // now give this role all permissions and roles it had
             foreach (string permission in ri.Permissions)
             {
                 Roles[ri.Name].Grant(permission);
             }
             foreach (string role in ri.Roles)
             {
                 if (!Roles.ContainsKey(role))
                 {
                     Syslog.WarningLog("There is no role " + role + " that could be granted to " + ri.Name + " skipping it");
                 }
                 Roles[ri.Name].Grant(Roles[role]);
             }
         }
         return;
     }
     // let's assume there is no role definition file, so we create some initial, built-in roles
     Roles.Add("null", new Role(0));
     Roles.Add("trusted", new Role(100));
     Roles.Add("operator", new Role(1000));
     Roles.Add("admin", new Role(20000));
     Roles.Add("root", new Role(65535));
     Roles["trusted"].Grant("trust");
     // trusted users can add users to trust list
     Roles["trusted"].Grant("trustadd");
     Roles["trusted"].Grant("trustdel");
     Roles["operator"].Grant(Roles["trusted"]);
     Roles["operator"].Grant("join");
     Roles["admin"].Grant("admin");
     Roles["admin"].Grant("drop");
     Roles["admin"].Grant("suppress");
     Roles["admin"].Grant("unsuppress");
     Roles["admin"].Grant("part");
     Roles["admin"].Grant(Roles["operator"]);
     // admins have all privileges as trusted users
     Roles["admin"].Grant(Roles["trusted"]);
     Roles["root"].Grant("root");
     foreach (Module module in ExtensionHandler.ExtensionList)
     {
         try
         {
             module.RegisterPermissions();
         }
         catch (Exception fail)
         {
             Core.HandleException(fail, module.Name);
         }
     }
 }
예제 #4
0
        /// <summary>
        /// Save config
        /// </summary>
        public void SaveConfig()
        {
            string fn = GetConfigFilePath();

            try
            {
                XmlDocument data    = new XmlDocument();
                XmlNode     xmlnode = data.CreateElement("channel");
                InsertData("talkmode", Suppress.ToString(), ref data, ref xmlnode);
                InsertData("langcode", Language, ref data, ref xmlnode);
                InsertData("respond_message", RespondMessage.ToString(), ref data, ref xmlnode);
                InsertData("ignore-unknown", IgnoreUnknown.ToString(), ref data, ref xmlnode);
                InsertData("suppress-warnings", SuppressWarnings.ToString(), ref data, ref xmlnode);
                InsertData("respond_wait", RespondWait.ToString(), ref data, ref xmlnode);
                InsertData("sharedinfo", SharedDB, ref data, ref xmlnode);
                if (!String.IsNullOrEmpty(this.Password))
                {
                    InsertData("password", Password, ref data, ref xmlnode);
                }
                InsertData("defaultbot", DefaultInstance, ref data, ref xmlnode);
                if (!(SharedLinkedChan.Count < 1))
                {
                    foreach (Channel current in SharedLinkedChan)
                    {
                        InsertData("name", current.Name, ref data, ref xmlnode, "sharedch");
                    }
                }

                if (!(Infobot_IgnoredNames.Count < 1))
                {
                    foreach (string curr in Infobot_IgnoredNames)
                    {
                        InsertData("name", curr, ref data, ref xmlnode, "ignored");
                    }
                }

                if (ExtensionData.Count > 0)
                {
                    foreach (KeyValuePair <string, string> item in ExtensionData)
                    {
                        InsertData(item.Key, item.Value, ref data, ref xmlnode, "extension");
                    }
                }

                lock (this.SystemUsers.Users)
                {
                    foreach (SystemUser user in this.SystemUsers.Users)
                    {
                        XmlAttribute name = data.CreateAttribute("regex");
                        name.Value = user.Name;
                        XmlAttribute kk = data.CreateAttribute("role");
                        kk.Value = user.Role;
                        XmlNode db = data.CreateElement("user");
                        db.Attributes.Append(name);
                        db.Attributes.Append(kk);
                        xmlnode.AppendChild(db);
                    }
                }
                if (File.Exists(fn))
                {
                    Core.BackupData(fn);
                    if (!File.Exists(Configuration.TempName(fn)))
                    {
                        Syslog.WarningLog("Unable to create backup file for " + Name);
                    }
                }
                data.AppendChild(xmlnode);
                data.Save(fn);
                if (File.Exists(Configuration.TempName(fn)))
                {
                    File.Delete(Configuration.TempName(fn));
                }
            }
            catch (Exception)
            {
                Core.RecoverFile(fn, Name);
            }
        }
예제 #5
0
        public void LoadConfig()
        {
            string conf_file = GetConfigFilePath();

            Core.RecoverFile(conf_file, Name);
            try
            {
                XmlDocument data = new XmlDocument();
                if (!File.Exists(conf_file))
                {
                    SaveConfig();
                    return;
                }
                data.Load(conf_file);
                foreach (XmlNode xx in data.ChildNodes[0].ChildNodes)
                {
                    switch (xx.Name)
                    {
                    case "user":
                        this.SystemUsers.InsertUser(xx);
                        continue;

                    case "extension":
                        if (ExtensionData.ContainsKey(xx.Attributes[0].Value))
                        {
                            ExtensionData[xx.Attributes[0].Value] = xx.Attributes[1].Value;
                        }
                        else
                        {
                            ExtensionData.Add(xx.Attributes[0].Value, xx.Attributes[1].Value);
                        }
                        continue;

                    case "ignored":
                        Infobot_IgnoredNames.Add(xx.Attributes[1].Value);
                        continue;

                    case "sharedch":
                        SharedChans.Add(xx.Attributes[1].Value);
                        continue;
                    }
                    switch (xx.Attributes[0].Value)
                    {
                    case "talkmode":
                        Suppress = bool.Parse(xx.Attributes[1].Value);
                        break;

                    case "langcode":
                        Language = xx.Attributes[1].Value;
                        break;

                    case "respond_message":
                        RespondMessage = bool.Parse(xx.Attributes[1].Value);
                        break;

                    case "ignore-unknown":
                        IgnoreUnknown = bool.Parse(xx.Attributes[1].Value);
                        break;

                    case "suppress-warnings":
                        SuppressWarnings = bool.Parse(xx.Attributes[1].Value);
                        break;

                    case "respond_wait":
                        RespondWait = int.Parse(xx.Attributes[1].Value);
                        break;

                    case "sharedinfo":
                        SharedDB = xx.Attributes[1].Value;
                        break;

                    case "defaultbot":
                        DefaultInstance = xx.Attributes[1].Value;
                        break;

                    case "password":
                        Password = xx.Attributes[1].Value;
                        break;
                    }
                }
            }
            catch (Exception fail)
            {
                Syslog.Log("Unable to load the config of " + Name, true);
                Core.HandleException(fail);
            }
        }