Exemplo n.º 1
0
        protected override void OnStart(string[] args)
        {
            //Backup();
            File_Read_Write.Write_File("-----------------------------------------------------", true);
            File_Read_Write.Write_File(DateTime.Now.ToString() + ": Service Starting...", true);

            try
            {
                info_MySQL = new List <Info_MySQL>();

                info_MySQL = XML_read_write.ConvertXmlStringtoObject <List <Info_MySQL> >(System.IO.File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "MySQLDatabase_Config.xml"));

                File_Read_Write.Write_File(DateTime.Now + ": Load Config...Done!", true);

                File_Read_Write.Write_File(DateTime.Now + ": Load " + info_MySQL.Count + " MySQL instance(s), " + info_MySQL.Sum(i => i.ListJob.Count) + " job(s), " + info_MySQL.Sum(i => i.ListJob.Sum(k => k.Files.Count)) + " file(s).", true);

                timer.Start();
            }
            catch
            {
                File_Read_Write.Write_File(DateTime.Now + ": Load Config...failed!", true);
            }



            //Info_MySQL_Jobs infoJob = info_MySQL[0].ListJob[0];
            //Info_MySQL_Instansce instansce = info_MySQL[0].Instances;

            //MySQL_Running(instansce, infoJob);
        }
Exemplo n.º 2
0
        protected override void OnStart(string[] args)
        {
            File_Read_Write.Write_File(AppDomain.CurrentDomain.BaseDirectory + @"Log\Service_Log.txt", "-----------------------------------------------------", true);
            File_Read_Write.Write_File(AppDomain.CurrentDomain.BaseDirectory + @"Log\Service_Log.txt", DateTime.Now.ToString() + ": Service Starting...", true);

            timer.Start();
        }
Exemplo n.º 3
0
        private void timer_Tick(object sender, EventArgs e)
        {
            string date_time = DateTime.Now.ToString("HH:mm");

            try
            {
                info_JobMySQL = XML_read_write.ConvertXmlStringtoObject <List <Info_MySQLJob> >(System.IO.File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "MySQLDatabase_Config.xml"));

                for (int i = 0; i < info_JobMySQL.Count; i++)
                {
                    for (int j = 0; j < info_JobMySQL[i].ListDB.Count; j++)
                    {
                        if (date_time == info_JobMySQL[i].ListDB[j].Time_Running)
                        {
                            Info_MySQL_Instance instance = info_JobMySQL[i].Instances;
                            Info_MySQL_DB       inf      = info_JobMySQL[i].ListDB[j];
                            new Thread(() => DB_Backup_Running(inf, instance)).Start();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                File_Read_Write.Write_File(AppDomain.CurrentDomain.BaseDirectory + @"Log\Service_Log.txt", DateTime.Now + ": Error - " + ex.Message, true);
            }
        }
Exemplo n.º 4
0
    public Exception Excute_Backup_DB(Info_MySQL_Instance SV)
    {
        try
        {
            string constring = "server=" + SV.Server_Name + ";port=" + SV.Port + ";user="******";pwd=" + SV.Pass + ";database=" + DBName + ";";

            File_Read_Write.Create_Exits_Folder(AppDomain.CurrentDomain.BaseDirectory + @"MySQLBackup\" + DBName);

            string file = AppDomain.CurrentDomain.BaseDirectory + @"MySQLBackup\" + DBName + @"\" + DBName + ".sql";

            using (MySqlConnection conn = new MySqlConnection(constring))
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    using (MySqlBackup mb = new MySqlBackup(cmd))
                    {
                        cmd.Connection = conn;
                        conn.Open();
                        mb.ExportToFile(file);
                        conn.Close();
                    }
                }
            }
        }
        catch(Exception op)
        {
            return op;
        }
        return null;
        
    }
Exemplo n.º 5
0
        protected override void OnStop()
        {
            timer.Stop();

            File_Read_Write.Write_File(AppDomain.CurrentDomain.BaseDirectory + @"Log\Service_Log.txt", DateTime.Now.ToString() + ": Service stopped!", true);

            File_Read_Write.Write_File(AppDomain.CurrentDomain.BaseDirectory + @"Log\Service_Log.txt", DateTime.Now + ": ----------------------------------------- ", true);
        }
Exemplo n.º 6
0
        protected override void OnStop()
        {
            timer.Stop();

            File_Read_Write.Write_File("-----------------------------------------------------", true);

            File_Read_Write.Write_File(DateTime.Now.ToString() + ": Service stopped!", true);

            File_Read_Write.Write_File("-----------------------------------------------------", true);
        }
Exemplo n.º 7
0
        public void clone()
        {
            var co = new CloneOptions();

            co.CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials {
                Username = "******", Password = string.Empty
            };

            string folderName = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");

            File_Read_Write.Create_Exits_Folder(folderName);
            Repository.Clone("https://github.com/chungcien/MapReduceDemo.git", AppDomain.CurrentDomain.BaseDirectory + @"repo\" + folderName, co);
        }
Exemplo n.º 8
0
        bool MySQL_Running(Info_MySQL_Instansce instansce, Info_MySQL_Jobs job)
        {
            string        Mess = "";
            Exception     er   = null; //gán cờ er bằng null chỉ thị ko có lỗi
            List <string> logs = new List <string>();

            Thread.CurrentThread.IsBackground = true;

            er = job.Execute_DB(instansce);
            if (er != null)
            {
                Mess = er.Message + ": " + ((er.InnerException == null) ? "" : er.InnerException.Message);

                logs.Add(DateTime.Now + ": Error - " + instansce.DB_Name + ": " + Mess);
                File_Read_Write.Write_File(DateTime.Now + ": Error - " + instansce.DB_Name + ": " + Mess, true);

                SendEmail.Send_Email(instansce.To_Email, null, "Execute SQL File(s) error!", "Server: " + instansce.Server_Name + @"\nDatabase name: " + instansce.DB_Name + "\n" + Mess + "\nLog:\n" + string.Join(Environment.NewLine, logs), false);

                return(false);
            }
            else
            {
                logs.Add(DateTime.Now + ": Execute SQL File(s) " + instansce.Server_Name + @"\" + instansce.DB_Name + " done!");
                File_Read_Write.Write_File(DateTime.Now + ": Execute SQL File(s) " + instansce.Server_Name + @"\" + instansce.DB_Name + " done!", true);
            }

            try
            {
                string t = new SSHClient().SSH_Exec("cd /root/Audition/ && ./client_master restoreMetaCache");

                logs.Add(DateTime.Now + ": Restore metaCache succufully! Result: " + t);
                File_Read_Write.Write_File(DateTime.Now + ": Restore metaCache succufully! Result: " + t, true);
            }
            catch (Exception io)
            {
                logs.Add(DateTime.Now + ": Error - " + io.Message);
                File_Read_Write.Write_File(DateTime.Now + ": Error - " + io.Message, true);

                return(false);
            }

            SendEmail.Send_Email(instansce.To_Email, null, "Execute SQL File(s) succufully!", "Applied SQL File(s) to " + instansce.Server_Name + @"\" + instansce.DB_Name + " succufully!\n" + "\nLog:\n" + string.Join(Environment.NewLine, logs), false);

            logs.Clear();

            return(true);
        }
Exemplo n.º 9
0
        private void timer_Tick(object sender, EventArgs e)
        {
            string date_time = DateTime.Now.ToString("dd-MM-yyyy HH:mm");

            for (int i = 0; i < info_MySQL.Count; i++)
            {
                for (int k = 0; k < info_MySQL[i].ListJob.Count; k++)
                {
                    if (date_time == info_MySQL[i].ListJob[k].Time_Running)
                    {
                        Info_MySQL_Jobs      infoJob   = info_MySQL[i].ListJob[k];
                        Info_MySQL_Instansce instansce = info_MySQL[i].Instances;

                        File_Read_Write.Write_File(DateTime.Now + ": Start Execute - " + infoJob.Files.Count + " file(s): " + string.Join(",", infoJob.Files) + " on " + instansce.DB_Name + @"\" + instansce.DB_Name, true);

                        new Thread(() => MySQL_Running(instansce, infoJob)).Start();
                    }
                }
            }
        }
Exemplo n.º 10
0
        void Running(bool isSendLog, string time)
        {
            //timer.Stop();
            try
            {
                Initialize(time);

                List <Model.Repository> repositories = db.Repositories.ToList();
            }
            catch (Exception op)
            {
                isWarnning = 2;

                File_Read_Write.Write_File(logpath, DateTime.Now + ": Error - " + op.Message, true, ref mail_content);
            }

            // gưi log cho admin
            if (isSendLog == true)
            {
                SendEmail.Send_Email("FPM Sync Check InOut Service", admin, null, "FPM Verify Data Log", MailToAdmin.Replace("#content#", "</br>" + string.Join("</br>", mail_content) + "</br>"), true, logpath, ref mail_content);
            }

            if (isWarnning == 0)
            {
                ServiceLog.SaveLog_Result(ServiceName, DateTime.Now.ToString("yyyy/MM/dd ") + time, "Success", logpath, dataProvider);
            }
            else if (isWarnning == 1)
            {
                ServiceLog.SaveLog_Result(ServiceName, DateTime.Now.ToString("yyyy/MM/dd ") + time, "Warnning", logpath, dataProvider);
            }
            else
            {
                ServiceLog.SaveLog_Result(ServiceName, DateTime.Now.ToString("yyyy/MM/dd ") + time, "Error", logpath, dataProvider);
            }


            mail_content.Clear();

            timer.Start();
        }
Exemplo n.º 11
0
        protected override void OnStart(string[] args)
        {
            try
            {
                Initialize(DateTime.Now.ToString("HH-mm"));

                File_Read_Write.Write_File(logpath, "-----------------------------------------------------", true, ref mail_content);
                File_Read_Write.Write_File(logpath, DateTime.Now.ToString() + ": Service Starting...", true, ref mail_content);

                // load email admin để gửi thông báo
                try
                {
                    admin.AddRange(ServiceConfig.LoadConfig(ServiceName, "Email_Admin", dataProvider).Split(',').ToArray());
                }
                catch
                {
                    isWarnning = 1;
                    throw new Exception("Load Config Email_Admin failed!");
                }


                MailToAdmin = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "EmailToAdmin.htm");

                List_ScanAt.AddRange(ServiceConfig.LoadConfig(ServiceName, "ListScanAt", dataProvider).Split(',').ToList());

                File_Read_Write.Write_File(logpath, DateTime.Now.ToString() + ": Load Config...Done! - Scan at (No SendLogs): " + string.Join(", ", List_ScanAt.ToArray()), true, ref mail_content);

                timer.Start();
            }
            catch (Exception ex)
            {
                ServiceLog.SaveLog_Result(ServiceName, DateTime.Now.ToString("yyyy/MM/dd HH-mm"), "Error", logpath, dataProvider);

                File_Read_Write.Write_File(logpath, DateTime.Now + ": Error - Load Config Failed! " + ex.Message, true, ref mail_content);
            }
        }
Exemplo n.º 12
0
        void DB_Backup_Running(Info_MySQL_DB new_DB, Info_MySQL_Instance instansce)
        {
            Compression_File Comp = new Compression_File();

            string    Mess = "";
            Exception er   = null; //gán cờ er bằng null chỉ thị ko có lỗi

            try                    // bắt đầu quá trình backup
            {
                //phương thức trả về 1 exception (er == null thì ko có lỗi), nếu có lỗi thì ném ra exception và dừng công việc backup
                er = new_DB.Excute_Backup_DB(instansce);
                if (er != null)
                {
                    throw new Exception("Error Backup Database", er);
                }
                else
                {
                    File_Read_Write.Write_File(AppDomain.CurrentDomain.BaseDirectory + @"Log\Service_Log.txt", DateTime.Now + ": Backup " + instansce.Server_Name + @" - " + new_DB.DBName + " Successfully!", true);
                }


                // đóng nén file
                er = Comp.Run_DongNen_DB(new_DB.DBName);
                if (er != null)
                {
                    throw new Exception("Error Compression file", er);
                }
                else
                {
                    File_Read_Write.Write_File(AppDomain.CurrentDomain.BaseDirectory + @"Log\Service_Log.txt", DateTime.Now + ": Compression " + instansce.Server_Name + @" - " + new_DB.DBName + ".zip Successfully!", true);
                }

                // tạo folder trong FTP server



                string path_save_inFTP = "BackupDB_zip/" + instansce.DisplayName + "/" + DateTime.Now.ToString("yyyy-MM-dd");
                er = FTPClient.CreateFolder(ConfigurationManager.AppSettings["FTP_SERVER_URI"].ToString(), ConfigurationManager.AppSettings["FTP_USER"].ToString(), ConfigurationManager.AppSettings["FTP_PASSWORD"].ToString(), path_save_inFTP);
                if (er != null)
                {
                    throw new Exception("Error Create folder FTP Server", er);
                }
                //else
                //{
                //    try
                //    {
                //        File_Read_Write.Write_File(AppDomain.CurrentDomain.BaseDirectory + @"Log\Service_Log.txt", DateTime.Now + ": Create folder " +path_save_inFTP+ " in " + ConfigurationManager.AppSettings["FTP_SERVER_URI"].ToString() + " Successfully!", true);
                //    }
                //    catch { }
                //}



                // upload file
                string file = AppDomain.CurrentDomain.BaseDirectory + @"Backup_zip\" + new_DB.DBName + ".zip";

                er = FTPClient.Upload(ConfigurationManager.AppSettings["FTP_SERVER_URI"].ToString() + path_save_inFTP, ConfigurationManager.AppSettings["FTP_USER"].ToString(), ConfigurationManager.AppSettings["FTP_PASSWORD"].ToString(), file);
                if (er != null)
                {
                    throw new Exception("Error Upload file to FTP Server", er);
                }
                else
                {
                    File_Read_Write.Write_File(AppDomain.CurrentDomain.BaseDirectory + @"Log\Service_Log.txt", DateTime.Now + ": Upload " + instansce.Server_Name + @" - " + new_DB.DBName + ".zip to " + ConfigurationManager.AppSettings["FTP_SERVER_URI"].ToString() + path_save_inFTP + " Successfully!", true);
                }

                //gửi mail
                SendEmail.Send_Email(new_DB.Email, null, "[Dashboard - RTS] Backup Database succufully!", "Backup Database " + instansce.Server_Name + @" - " + new_DB.DBName + " succufully!", false);


                //quá trình hoàn tất
            }
            catch (Exception io)
            {
                try
                {
                    if (io.InnerException.Message == "" || io.InnerException.Message == null)
                    {
                        Mess = io.Message;
                    }
                    else
                    {
                        Mess = io.Message + ": " + io.InnerException.Message;
                    }
                }
                catch { }

                //gửi mail
                SendEmail.Send_Email(new_DB.Email, null, "[Dashboard - RTS] Backup Database error!", "Server: " + instansce.Server_Name + "\nDatabase name: " + new_DB.DBName + "\n" + Mess, false);


                File_Read_Write.Write_File(AppDomain.CurrentDomain.BaseDirectory + @"Log\Service_Log.txt", DateTime.Now + ": ----------------------------------------- ", true);
                File_Read_Write.Write_File(AppDomain.CurrentDomain.BaseDirectory + @"Log\Service_Log.txt", DateTime.Now + ": Error - " + new_DB.DBName + ": " + Mess, true);
                File_Read_Write.Write_File(AppDomain.CurrentDomain.BaseDirectory + @"Log\Service_Log.txt", DateTime.Now + ": ----------------------------------------- ", true);
            }
        }