Ejemplo n.º 1
0
        public ImportResultSet executeScript()
        {
            ImportResultSet result = new ImportResultSet();

            if (string.IsNullOrWhiteSpace(this.script))
            {
                result.wasSuccessful = false;
                result.errorMessage  = "Script not set";
                return(result);
            }
            try
            {
                MySqlConnection con = new MySqlConnection(connectionString);
                con.Open();

                MySqlScript script = new MySqlScript(con, this.script);
                script.Delimiter          = config.scriptDelimeter;
                script.StatementExecuted += scriptStatementExecuted;
                script.Execute();

                result.wasSuccessful = true;
            }
            catch (Exception ex)
            {
                result.wasSuccessful = false;
                result.errorMessage  = ex.Message;
            }

            return(result);
        }
Ejemplo n.º 2
0
        /*
         * private bool isServerCompatible()
         * {
         *  bool isCompatible = true;
         *  //https://stackoverflow.com/questions/17464116/how-do-i-know-a-mysql-user-has-the-maximum-privileges-possible
         *  //https://stackoverflow.com/questions/6956106/how-to-know-if-mysql-binary-log-is-enable-through-sql-command
         *  //https://www.thegeekstuff.com/2017/08/mysqlbinlog-examples/
         *  //check if the user has super priviledge and if binary logging is enabled on the server
         *  //if not stop and pop message
         *  return isCompatible;
         * }*/

        public ImportResultSet executeScript()
        {
            ImportResultSet result = new ImportResultSet();

            if (!string.IsNullOrWhiteSpace(this.scriptStatus))
            {
                result.wasSuccessful = false;
                result.errorMessage  = this.scriptStatus;
                return(result);
            }
            try
            {
                /* not needed for import only needed for dump keeping as example
                 * if (!isServerCompatible())
                 * {
                 *  result.wasSuccessful = false;
                 *  result.errorMessage = "The user has no super priviledge on the server or binary logging is not enabled.";
                 *  return result;
                 * }*/
                result = executeSQLscript();
                //result = executeSQLscript();
            }
            catch (Exception ex)
            {
                result.wasSuccessful = false;
                result.errorMessage  = "import task: " + ex.Message;
            }

            return(result);
        }
Ejemplo n.º 3
0
 private void onImportComplete(ImportResultSet result)
 {
     ImportComplete?.Invoke(result);
 }
Ejemplo n.º 4
0
 private void onImportCompleteHandler(ImportResultSet result)
 {
     deletefiles();
     onImportComplete(result);
 }
Ejemplo n.º 5
0
        /* old method using MySqlScript
         * private ImportResultSet executeSQLscript()
         * {
         *  ImportResultSet result = new ImportResultSet();
         *
         *  MySqlConnection con = new MySqlConnection(connectionString);
         *  con.Open();
         *
         *  MySqlScript script = new MySqlScript(con, this.script);
         *  script.Delimiter = config.scriptDelimeter;
         *  script.StatementExecuted += scriptStatementExecuted;
         *  script.Execute();
         *  result.wasSuccessful = true;
         *  return result;
         * }*/

        private ImportResultSet executeSQLscript()
        {
            ImportResultSet result = new ImportResultSet();

            proc = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName               = "resources/mysqldump/mysql.exe",
                    Arguments              = buildMysqlexeArguments().ToString(),
                    UseShellExecute        = false,
                    RedirectStandardOutput = true, //prepei na diavastoun me ti seira pou ginonte ta redirect alliws kolaei se endless loop
                    RedirectStandardError  = true,
                    RedirectStandardInput  = true,
                    CreateNoWindow         = true
                }
            };

            Console.WriteLine("Executing mysql.exe now.");
            proc.Start();

            try
            {
                StreamReader sr    = new StreamReader(config.scriptPath);
                int          index = 1;
                string       line  = "";
                while ((line = sr.ReadLine()) != null)
                {
                    proc.StandardInput.WriteLine(line);
                    onProgress(index);
                    index++;
                    //Console.WriteLine("Log file line: "+line);
                }
                proc.StandardInput.Close(); //ama den ginei auto perimenei endlessly gia input
                sr.Close();
            }catch (Exception ex)
            {
                result.wasSuccessful = false;
                if (proc == null || proc.HasExited)
                {
                    result.errorMessage = "Mysql.exe import proccess was killed.";
                }
                else
                {
                    result.errorMessage = "Mysql import: " + ex.Message;
                }
            }


            try
            {
                while (!proc.StandardOutput.EndOfStream)
                {
                    string line = proc.StandardOutput.ReadLine();
                    Console.WriteLine("Mysql.exe output:" + line);
                }

                while (!proc.StandardError.EndOfStream)
                {
                    string line = proc.StandardError.ReadLine();
                    result.errorMessage += line + "\n";
                    Console.WriteLine("Mysql.exe error:" + line);
                }
                proc.WaitForExit();
            }
            catch (NullReferenceException ex)
            {
                Console.WriteLine("Mysql.exe null reference exception on proccess: " + ex.Message);
            }

            if (proc == null || proc.ExitCode != 0)
            {
                result.wasSuccessful = false;
                if (proc == null)
                {
                    result.errorMessage = "Mysql.exe import proccess was killed.";
                }
            }
            else
            {
                result.wasSuccessful = true;
            }

            return(result);
        }