Пример #1
0
        private void StartSimulationProcess()
        {
            _process = new RobocopyProcess(Task, SourceFolder, DestinationFolder);
            _process.StartInfo.Arguments += " /l";
            _process.Exited += SimulationProcess_Exited;

            if (!TryStartRobocopy(_process))
            {
                return;
            }

            _status.OnEnterNewStage("Analyzing...", "Pending changes are being identified...");
            _status.IsAbortingSupported = true;
        }
Пример #2
0
        public void Dispose()
        {
            if (_process != null)
            {
                _process.Dispose();                 // incl. killing it if currently running + waiting for it to exit and the Exited event handler to complete
                _process = null;
            }

            if (_vscSession != null)
            {
                _vscSession.Dispose();
                _vscSession = null;
            }
        }
Пример #3
0
        /// <summary>
        /// Tries to start the specified process and returns true if successful.
        /// If the process could not be started, a message box is displayed
        /// and then the operation is finished.
        /// </summary>
        private bool TryStartRobocopy(RobocopyProcess process)
        {
            try
            {
                process.Start();
                return(true);
            }
            catch (Exception e)
            {
                MessageBox.Show("Robocopy could not be started:\n\n" + e.Message,
                                "RoboMirror", MessageBoxButtons.OK, MessageBoxIcon.Error);

                Finish(false);
                return(false);
            }
        }
Пример #4
0
        /// <summary>Starts the actual (non-simulation) Robocopy process.</summary>
        private void StartProcess(string sourceFolder)
        {
            _process         = new RobocopyProcess(Task, sourceFolder, DestinationFolder, _simulationProcessOutputLinesCount);
            _process.Exited += Process_Exited;
            if (_simulationProcessOutputLinesCount > 0)
            {
                _process.ProgressChanged += Process_ProgressChanged;
            }

            if (!TryStartRobocopy(_process))
            {
                return;
            }

            _status.OnEnterNewStage("Mirroring...", string.Format("to {0}", PathHelper.Quote(DestinationFolder)));
            _status.IsAbortingSupported = true;
        }
Пример #5
0
        private void SimulationProcess_Exited(object sender, EventArgs e)
        {
            _status.IsAbortingSupported = false;

            bool aborted = (_process.ExitCode == -1 || IsFinished);

            // alert if Robocopy could not be started normally
            bool fatalError = (!aborted && _process.IsAnyExitFlagSet(RobocopyExitCodes.FatalError));

            if (fatalError)
            {
                Alert("A fatal Robocopy error has occurred.", MessageBoxIcon.Error);
            }

            if (aborted || fatalError)
            {
                Finish(false);
                return;
            }

            // prompt the user to commit the pending changes
            using (var dialog = new GUI.SimulationResultDialog(_process))
            {
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    Finish(false);
                    return;
                }
            }

            _simulationProcessOutputLinesCount = _process.Output.Count;
            _process.Dispose();
            _process = null;

            LaunchActualOperation();
        }
Пример #6
0
        /// <summary>Logs a Robocopy run.</summary>
        /// <param name="process">Terminated Robocopy process.</param>
        public static LogEntry LogRun(string taskGuid, RobocopyProcess process, string sourceFolder,
                                      string destinationFolder, bool updateLastSuccessTimeStamp)
        {
            if (string.IsNullOrEmpty(taskGuid))
            {
                throw new ArgumentNullException("taskGuid");
            }
            if (process == null)
            {
                throw new ArgumentNullException("process");
            }
            if (string.IsNullOrEmpty(sourceFolder))
            {
                throw new ArgumentNullException("sourceFolder");
            }
            if (string.IsNullOrEmpty(destinationFolder))
            {
                throw new ArgumentNullException("destinationFolder");
            }

            EventLogEntryType type;
            string            messageFormat;

            if (process.ExitCode == -1)
            {
                type          = EventLogEntryType.Error;
                messageFormat = "Operation aborted while mirroring {0} to {1}.";
            }
            else if (process.ExitCode == 0)
            {
                type          = EventLogEntryType.Information;
                messageFormat = "Already in sync: {0} and {1}";
            }
            else if (process.IsAnyExitFlagSet(RobocopyExitCodes.FatalError))
            {
                type          = EventLogEntryType.Error;
                messageFormat = "A fatal error occurred while trying to mirror {0} to {1}.";
            }
            else if (process.IsAnyExitFlagSet(RobocopyExitCodes.CopyErrors))
            {
                type          = EventLogEntryType.Error;
                messageFormat = "Some items could not be mirrored from {0} to {1}.";
            }
            else if (process.IsAnyExitFlagSet(RobocopyExitCodes.MismatchedItems))
            {
                type          = EventLogEntryType.Warning;
                messageFormat = "Some file <-> folder mismatches while mirroring {0} to {1}.";
            }
            else
            {
                type          = EventLogEntryType.Information;
                messageFormat = "Success: {0} mirrored to {1}";
            }

            string message = string.Format(messageFormat,
                                           PathHelper.Quote(sourceFolder),
                                           PathHelper.Quote(destinationFolder));

            return(WriteEntry(taskGuid, type, message, process.FullOutput,
                              updateLastSuccessTimeStamp));
        }