示例#1
0
        public void CreateArchiev(string destinationPath, string fileNameFormat = "{name}_{date}")
        {
            if (CurrentBaseType != BaseType.File)
            {
                return;
            }
            var sourceFileName = System.IO.Path.Combine(BaseName, "1Cv8.1CD");

            KickAllUsers();
            var fileNamesStruct = new FileNamesStruct(fileNameFormat, destinationPath, this, "zip");
            var backupFileName  = fileNamesStruct.BackupFileName;
            var compressResult  = CompressFileConsole(sourceFileName, backupFileName);
            var testResult      = TestArchieveConsole(backupFileName);

            if (string.IsNullOrEmpty(compressResult) || string.IsNullOrEmpty(testResult))
            {
                CurrentBackUpState = BackupState.Success;
                return;
            }
            ;
            LogResult          = $"{compressResult}\n{testResult}";
            CurrentBackUpState = BackupState.Error;
        }
示例#2
0
        public void CreateBackup(string enterprisePath, bool useArchiev, string destinationPath, string fileNameFormat = "{name}_{date}",
                                 int whaitForBackUp = 1000 * 60 * 60 * 4)
        {
            if (CurrentBackUpState != BackupState.Queued)
            {
                return;
            }

            LogResult = $"Starting backup process for base {BaseName}";

            if (CurrentBaseType == BaseType.File && useArchiev)
            {
                CreateArchiev(destinationPath, fileNameFormat);
                return;
            }

            var    startInfo = new ProcessStartInfo();
            string backupFileName;
            string dumpResultFileName;
            string logFileName;

            try
            {
                var fileNamesStruct = new FileNamesStruct(fileNameFormat, destinationPath, this);
                var fileName        = fileNamesStruct.FileName;
                var logDirectory    = fileNamesStruct.LogDirectory;
                if (!Directory.Exists(logDirectory))
                {
                    Directory.CreateDirectory(logDirectory);
                }
                backupFileName     = fileNamesStruct.BackupFileName;
                logFileName        = fileNamesStruct.LogFileName;
                dumpResultFileName = fileNamesStruct.DumpResultFileName;
                var commandArgs =
                    $"DESIGNER /IBConnectionString{Path} /DumpIB \"{backupFileName}\" /DumpResult \"{dumpResultFileName}\" /Out \"{logFileName}\"";

                startInfo.WindowStyle            = ProcessWindowStyle.Normal;
                startInfo.FileName               = System.IO.Path.Combine(enterprisePath, "1cv8.exe");
                startInfo.RedirectStandardOutput = false;
                startInfo.RedirectStandardError  = false;
                startInfo.UseShellExecute        = true;
                startInfo.Arguments              = commandArgs;
            }
            catch (Exception e)
            {
                LogResult          = "Process ended whith error";
                LogResult          = e.Message;
                CurrentBackUpState = BackupState.Error;
                return;
            }

            try
            {
                if (CurrentBaseType == BaseType.Server)
                {
                    SetSheduledJobsStatus(true);
                }
                KickAllUsers();
            }
            catch (Exception e)
            {
                LogResult = "Error while disconnecting sessions";
                LogResult = e.Message;
            }

            using (var backupProcess = Process.Start(startInfo))
            {
                if (backupProcess == null)
                {
                    return;
                }
                LogResult          = $"Process started, PID: {backupProcess.Id}";
                CurrentBackUpState = BackupState.InProgress;
                while (!backupProcess.HasExited)
                {
                    try
                    {
                        if (backupProcess.MainWindowHandle != IntPtr.Zero && GetWindowText(backupProcess.MainWindowHandle) != string.Empty)
                        {
                            backupProcess.Kill();
                            LogResult = "Auth failed"; break;
                        }
                        System.Threading.Thread.Sleep(1000);
                    }
                    catch (Exception e)
                    {
                        // ignored
                    }
                }
                //exeProcess.WaitForExit(whaitForBackUp);
                var exitCode = backupProcess.ExitCode;
                int dumpResult;
                try
                {
                    dumpResult = int.TryParse(File.ReadAllText(dumpResultFileName), out dumpResult) ? dumpResult : -1;
                }
                catch (Exception e)
                {
                    LogResult  = e.Message;
                    dumpResult = -2;
                }

                if (CurrentBaseType == BaseType.Server)
                {
                    SetSheduledJobsStatus(false);
                }

                if (!File.Exists(backupFileName) || dumpResult != 0 || exitCode != 0)
                {
                    CurrentBackUpState = BackupState.Error;
                    LogResult          = "Process ended whith error";
                    if (dumpResult != -2)
                    {
                        LogFileName = logFileName;
                    }
                }
                else
                {
                    CurrentBackUpState = BackupState.Success;
                }
            }
        }