Beispiel #1
0
        public CompressionResultSet decompress7z()
        {
            Directory.CreateDirectory(config.decompressDirectory);
            proc = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = configurationManagerInstance.compressConfigInstance.getSettings().use32bit ? "resources\\7z\\7z.exe"
                        : "resources\\7z64\\7z.exe",
                    Arguments              = calculateArgumentsDecompress().ToString(),
                    UseShellExecute        = false,
                    RedirectStandardOutput = true, //prepei na diavastoun me ti seira pou ginonte ta redirect alliws kolaei se endless loop
                    RedirectStandardError  = true,
                    CreateNoWindow         = true,
                }
            };
            Console.WriteLine("Executing 7zip now.");
            CompressionResultSet result = new CompressionResultSet();

            proc.Start();
            onCompressStart();
            try
            {
                while (!proc.StandardOutput.EndOfStream)
                {
                    string line = proc.StandardOutput.ReadLine();
                    if (line.Contains("%"))
                    {
                        int per = 0;
                        int.TryParse(line.Substring(0, 3), out per);
                        onCompressProgress(per);
                    }
                }

                while (!proc.StandardError.EndOfStream)
                {
                    result.standardError += proc.StandardError.ReadLine() + "\n";
                }
                proc.WaitForExit();
            }
            catch (NullReferenceException ex)
            {
                Console.WriteLine("Compression null reference exception on proccess: " + ex.Message);
                File.Delete(config.absolutePath);
                Directory.Delete(config.decompressDirectory, true);
            }

            if (proc == null || proc.ExitCode != 0)
            {
                result.wasSuccessful = false;
                if (proc == null)
                {
                    result.standardError = "Compression proccess was killed.";
                }
                //delete
                File.Delete(config.absolutePath);
                Directory.Delete(config.decompressDirectory, true);
            }
            return(result);
        }
Beispiel #2
0
        public CompressionResultSet doCompress7z()
        {
            StringBuilder arguments = calculateArguments();

            Console.WriteLine("Compression7z arguments: " + arguments.ToString());

            string f7zip = "resources\\7z64\\7z.exe";

            if (IsTest)
            {
                if (OS.IsWindowsServer())
                {
                    f7zip = BUILD_SERVER_ZIP_PATH64;
                }
            }

            if (configurationManagerInstance.compressConfigInstance.use32bit)
            {
                f7zip = "resources\\7z\\7z.exe";
                if (IsTest)
                {
                    if (OS.IsWindowsServer())
                    {
                        f7zip = BUILD_SERVER_ZIP_PATH32;
                    }
                }
            }

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

            Console.WriteLine("Executing 7zip now.");
            CompressionResultSet result = new CompressionResultSet();

            proc.Start();

            onCompressStart();

            try
            {
                while (!proc.StandardOutput.EndOfStream)
                {
                    string line = proc.StandardOutput.ReadLine();
                    //Console.WriteLine("Comp:" + line);


                    if (line.Contains("%"))
                    {
                        int per = 0;
                        int.TryParse(line.Substring(0, 3), out per);
                        onCompressProgress(per);
                    }
                }

                while (!proc.StandardError.EndOfStream)
                {
                    string line = proc.StandardError.ReadLine();
                    result.standardError += line + "\n";
                    Console.WriteLine(line);
                }

                proc.WaitForExit();
            }
            catch (NullReferenceException ex)
            {
                Console.WriteLine("Compression null reference exception on proccess: " + ex.Message);
                File.Delete(absolutePath);
                File.Delete(absolutePath.Replace(".sql", fileType));
            }

            if (proc == null || proc.ExitCode != 0)
            {
                result.wasSucessful = false;
                if (proc == null)
                {
                    result.standardError = "Compression proccess was killed.";
                }
                //delete
                File.Delete(absolutePath);
                File.Delete(absolutePath.Replace(".sql", fileType));
            }
            else
            {
                result.wasSucessful = true;
            }

            result.resultAbsPath = absolutePath.Replace(".sql", fileType);

            return(result);
        }
 private void onCompressComplete(CompressionResultSet result)
 {
     CompressComplete?.Invoke(result);
 }
Beispiel #4
0
        public BinlogDumpResultset executeDump()
        {
            result = new BinlogDumpResultset();
            result.wasSuccessful = true;
            StringBuilder arguments = calculateArguments();

            if (!result.wasSuccessful)
            {
                return(result);
            }

            // dump execution
            Console.WriteLine(arguments.ToString());

            string binlogexefile = "resources/mysqldump/mysqlbinlog.exe";

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

            Console.WriteLine("BinlogDump: Dump starting now");
            proc.Start();

            Random rnd      = new Random();
            string fileExt  = ".sql";
            String filename = "binlogdump" + rnd.Next(1000000, 9999999) + fileExt;

            Directory.CreateDirectory(configurationManagerInstance.mysqlDumpConfigInstance.tempSavePath);
            while (File.Exists(configurationManagerInstance.mysqlDumpConfigInstance.tempSavePath + filename))
            {
                filename = "binlogdump" + rnd.Next(10000000, 99999999) + fileExt;
            }

            try
            {
                StreamWriter filewriter = new StreamWriter(@configurationManagerInstance.mysqlDumpConfigInstance.tempSavePath + filename);
                while (!proc.StandardOutput.EndOfStream)
                {
                    filewriter.WriteLine(proc.StandardOutput.ReadLine());
                }
                filewriter.Close();
                result.mysqlbinlogexeStandardError = "";
                while (!proc.StandardError.EndOfStream)
                {
                    result.mysqlbinlogexeStandardError += proc.StandardError.ReadLine() + "\n";
                }
                result.mysqlbinlogexeStandardError = result.mysqlbinlogexeStandardError.Replace("Warning: Using a password on the command line interface can be insecure.\n", "");
                Console.WriteLine(result.mysqlbinlogexeStandardError); //for testing

                proc.WaitForExit();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                File.Delete(configurationManagerInstance.mysqlDumpConfigInstance.tempSavePath + filename);
            }

            if (proc == null || proc.ExitCode != 0)
            {
                result.wasSuccessful = false;
                result.errorNumber   = -2;
                if (proc == null)
                {
                    result.mysqlbinlogexeStandardError = "MySQL binlog proccess was killed.";
                }
                File.Delete(configurationManagerInstance.mysqlDumpConfigInstance.tempSavePath + filename);
            }
            else
            {
                result.wasSuccessful = true;
                result.fileAbsPath   = configurationManagerInstance.mysqlDumpConfigInstance.tempSavePath + filename;

                //compression
                if (configurationManagerInstance.compressConfigInstance.enableCompression)
                {
                    comp = new Compression();

                    comp.absolutePath      = result.fileAbsPath;
                    comp.CompressProgress += onCompressProgressHandler;
                    comp.CompressStart    += onCompressStartHandler;

                    CompressionResultSet compResult = comp.doCompress7z(); //edw kaleitai to compression

                    if (!compResult.wasSucessful)
                    {
                        result.wasSuccessful = false;
                        result.errorNumber   = -3;
                        result.mysqlbinlogexeStandardError = compResult.standardError;
                    }
                    File.Delete(result.fileAbsPath); //delete to sketo .sql
                    result.fileAbsPath = compResult.resultAbsPath;
                }
            }
            result.incrementalFormatPrefix = config.prefix;
            return(result);
        }
Beispiel #5
0
        public DumpResultSet executeDump()
        {
            //to espasa se 2 methodous
            StringBuilder arguments = calculateArguments();

            if (!resultObj.wasSuccessful)
            {
                return(resultObj);
            }

            //dump execution
            Console.WriteLine(arguments.ToString());

            string mysqldumpfile = "resources/mysqldump/mysqldump.exe";

            //now we can run test localy and on server
            //localy visual studio test suite will handle process mapping
            if (IsTest)
            {
                if (OS.IsWindowsServer())
                {
                    mysqldumpfile = BUILD_SERVER_MYSQLDUMP_PATH;
                }
            }

            proc = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName               = mysqldumpfile,//AppDomain.CurrentDomain.BaseDirectory.Replace("bin\\Debug\\", "mysqldump.exe") ,
                    Arguments              = arguments.ToString(),
                    UseShellExecute        = false,
                    RedirectStandardOutput = true, //prepei na diavastoun me ti seira pou ginonte ta redirect alliws kolaei se endless loop
                    RedirectStandardError  = true,
                    CreateNoWindow         = true
                }
            };

            Console.WriteLine("MySqlDump: Dump starting now");
            proc.Start();

            Random rnd = new Random();
            string fileExt;

            if (configurationManagerInstance.mysqlDumpConfigInstance.xml)
            {
                fileExt = ".xml";
            }
            else
            {
                fileExt = ".sql";
            }
            String filename = "dump" + rnd.Next(1000000, 9999999) + fileExt;

            Directory.CreateDirectory(configurationManagerInstance.mysqlDumpConfigInstance.tempSavePath);


            //checking if file exists
            while (File.Exists(configurationManagerInstance.mysqlDumpConfigInstance.tempSavePath + filename))
            {
                filename = "Dump" + rnd.Next(10000000, 99999999) + fileExt;
            }

            try
            {
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(@configurationManagerInstance.mysqlDumpConfigInstance.tempSavePath + filename))
                {
                    //addCustomCommentInHeader
                    if (!string.IsNullOrEmpty(configurationManagerInstance.mysqlDumpConfigInstance.addCustomCommentInHeader))
                    {
                        file.WriteLine("-- Custom comment: " + configurationManagerInstance.mysqlDumpConfigInstance.addCustomCommentInHeader);
                    }


                    while (!proc.StandardOutput.EndOfStream)
                    {
                        string line = proc.StandardOutput.ReadLine();
                        file.WriteLine(line);
                        handleLineOutput(line);
                    }
                }


                resultObj.mysqldumpexeStandardError = "";
                while (!proc.StandardError.EndOfStream)
                {
                    resultObj.mysqldumpexeStandardError += proc.StandardError.ReadLine() + "\n";
                }

                if (resultObj.mysqldumpexeStandardError.StartsWith("Warning: Using a password"))
                {
                    resultObj.mysqldumpexeStandardError = resultObj.mysqldumpexeStandardError.Replace("Warning: Using a password on the command line interface can be insecure.\n", "");
                }

                Console.WriteLine(resultObj.mysqldumpexeStandardError); //for testing

                proc.WaitForExit();
            }
            catch (NullReferenceException ex)
            {
                Console.WriteLine("MySQLdump null reference exception on proccess: " + ex.Message);
                File.Delete(configurationManagerInstance.mysqlDumpConfigInstance.tempSavePath + filename);
            }
            if (proc == null || proc.ExitCode != 0)
            {
                resultObj.wasSuccessful = false;
                resultObj.errorNumber   = -2;
                if (proc == null)
                {
                    resultObj.mysqldumpexeStandardError = "MySQL dump proccess was killed.";
                }
                File.Delete(configurationManagerInstance.mysqlDumpConfigInstance.tempSavePath + filename);
            }
            else
            {
                resultObj.wasSuccessful = true;
                resultObj.fileAbsPath   = configurationManagerInstance.mysqlDumpConfigInstance.tempSavePath + filename;

                //compression
                if (configurationManagerInstance.compressConfigInstance.enableCompression)
                {
                    comp = new Compression();
                    if (IsTest)
                    {
                        if (OS.IsWindowsServer())
                        {
                            comp.IsTest = true;
                        }
                    }

                    comp.absolutePath      = resultObj.fileAbsPath;
                    comp.CompressProgress += onCompressProgressHandler;
                    comp.CompressStart    += onCompressStartHandler;

                    CompressionResultSet compResult = comp.doCompress7z(); //edw kaleitai to compression

                    if (!compResult.wasSucessful)
                    {
                        resultObj.wasSuccessful             = false;
                        resultObj.errorNumber               = -3;
                        resultObj.mysqldumpexeStandardError = compResult.standardError;
                    }
                    File.Delete(resultObj.fileAbsPath); //delete to sketo .sql
                    resultObj.fileAbsPath = compResult.resultAbsPath;
                }
            }

            return(resultObj);
        }