Esempio n. 1
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));
        }
Esempio n. 2
0
        private void StartInVscSession()
        {
            string sourceVolume = PathHelper.RemoveTrailingSeparator(Path.GetPathRoot(SourceFolder));

            _vscSession        = new VolumeShadowCopySession();
            _vscSession.Error += VscSession_Error;
            _vscSession.Ready += VscSession_Ready;

            _status.OnEnterNewStage("Preparing...", string.Format("Creating shadow copy of volume {0} ...", PathHelper.Quote(sourceVolume)));

            // create and mount the shadow copy
            _vscSession.Start(SourceFolder);

            _status.IsAbortingSupported = true;
        }
Esempio n. 3
0
        /// <param name="task">Task to be backed up/restored.</param>
        /// <param name="expectedNumOutputLines">
        /// Expected total number of output lines for progress estimation, e.g.,
        /// obtained by a prior simulation run.
        /// Required for the ProgressChanged event to be fired.
        /// </param>
        public RobocopyProcess(MirrorTask task, string sourceFolder, string destinationFolder, int expectedNumOutputLines = -1)
        {
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }
            if (string.IsNullOrEmpty(sourceFolder))
            {
                throw new ArgumentNullException("sourceFolder");
            }
            if (string.IsNullOrEmpty(destinationFolder))
            {
                throw new ArgumentNullException("destinationFolder");
            }

            if (!Directory.Exists(sourceFolder))
            {
                throw new InvalidOperationException(string.Format("The source folder {0} does not exist.", PathHelper.Quote(sourceFolder)));
            }
            if (!Directory.Exists(destinationFolder))
            {
                throw new InvalidOperationException(string.Format("The destination folder {0} does not exist.", PathHelper.Quote(destinationFolder)));
            }

            // only use the bundled Robocopy version if the system does not ship with one
            string exePath = Path.Combine(Environment.SystemDirectory, "Robocopy.exe");

            if (!File.Exists(exePath))
            {
                exePath = Path.Combine(System.Windows.Forms.Application.StartupPath, @"Tools\Robocopy.exe");

                if (!File.Exists(exePath))
                {
                    throw new InvalidOperationException(string.Format("{0} does not exist.", PathHelper.Quote(exePath)));
                }
            }

#if DEBUG
            //		exePath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "DummyConsoleProcess.exe");
#endif

            SourceFolder      = sourceFolder;
            DestinationFolder = destinationFolder;
            PurgeExtraItems   = task.DeleteExtraItems;

            _expectedNumOutputLines = expectedNumOutputLines;

            StartInfo.FileName  = exePath;
            StartInfo.Arguments = string.Format("{0} {1} {2}", PathHelper.QuoteForRobocopy(SourceFolder),
                                                PathHelper.QuoteForRobocopy(DestinationFolder), BuildSwitches(task, SourceFolder));
        }
Esempio n. 4
0
 public FileLockedException(string path, Exception innerException)
     : base(string.Format("The file {0} is locked.", PathHelper.Quote(path)), innerException)
 {
 }