Ejemplo n.º 1
0
 public void InvokeProgress(MirrorEventArgs args)
 {
     if (FileProgress != null)
     {
         if (FileProgress(args))
         {
             _cancelRequested = true;
             _engine.Cancel();
         }
     }
 }
Ejemplo n.º 2
0
        void OnStartingFile(object sender, MirrorEventArgs args)
        {
            if (ShouldSkip("Backup", args))
            {
                args.PendingAction = MirrorAction.Skip;
                InvokeProgress(args);
                return;
            }

            switch (args.Situation)
            {
            case MirrorSituation.FileIsSame:
                _alreadyAccountedFor.Add(args.Path);
                break;

            case MirrorSituation.FileMissing:
                _files++;
                InvokeProgress(args);
                _progress.WriteVerbose("[{0}] Will create on backup: {1}", _currentGroup.Name, args.GetDestinationPathForDisplay());
                _alreadyAccountedFor.Add(args.Path);
                break;

            case MirrorSituation.SourceFileOlder:
            case MirrorSituation.SourceFileNewer:
                _files++;
                InvokeProgress(args);
                _progress.WriteVerbose("[{0}] Updating {1}", _currentGroup.Name, args.GetDestinationPathForDisplay());
                break;

            case MirrorSituation.DirectoryOnDestinationButNotSource:
            case MirrorSituation.FileOnDestinationButNotSource:
                if (!_currentGroup.NormallyPropogateDeletions &&
                    !args.Path.Contains(".hg"))                                //always propogate deletions inside the mercurial folder
                {
                    args.PendingAction = MirrorAction.Skip;
                    _progress.WriteVerbose("[{0}] Because of group policy, will not propagate deletion of {1}", _currentGroup.Name, args.GetDestinationPathForDisplay());
                }
                else
                {
                    args.PendingAction = MirrorAction.Delete;
                    _progress.WriteVerbose("[{0}] Deleting {1}", _currentGroup.Name, args.Path);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            //review: does this really mean success?
            _errorCountSinceLastSuccess = 0;
        }
Ejemplo n.º 3
0
        private MirrorAction GetDirectoryActionFromClient(FileOrDirectory directory, MirrorSituation situation, MirrorAction action)
        {
            var args = new MirrorEventArgs(directory.Path, situation, action);
            EventHandler <MirrorEventArgs> handler = StartingDirectory;

            if (handler != null)
            {
                handler(this, args);
            }
            if (args.PendingAction == MirrorAction.Skip || args.PendingAction == MirrorAction.Delete)
            {
                _skippedOrRemovedDirectories.Add(directory.Path);
            }
            return(args.PendingAction);
        }
Ejemplo n.º 4
0
        private MirrorAction GetFileActionFromClient(string path, MirrorSituation situation, MirrorAction action)
        {
            //note... this is needed only because we don't currently have a
            //hierarchical list of things to walk, such that we trim in a more
            //effecient way
            if (_skippedOrRemovedDirectories.Any(d => path.StartsWith(d)))
            {
                return(MirrorAction.Skip);
            }

            var args = new MirrorEventArgs(path, situation, action);
            EventHandler <MirrorEventArgs> handler = StartingFile;

            if (handler != null)
            {
                handler(this, args);
            }
            return(args.PendingAction);
        }
Ejemplo n.º 5
0
        /*
         * private void OnDestinationPreviewChange(object provider, ApplyingChangeEventArgs args)
         * {
         *      if(ShouldSkip("Preview", (FileSyncProvider)provider,args))
         *      {
         *              args.SkipChange = true;
         *              return;
         *      }
         *      if(args.CurrentFileData !=null)
         *      {
         *              _currentGroup.NetChangeInBytes -= args.CurrentFileData.Size;
         *              //below, we'll add back the new size, giving us the correct net change
         *      }
         *      string rootDirectoryPath = ((FileSyncProvider)provider).RootDirectoryPath;
         *      switch (args.ChangeType)
         *      {
         *              case ChangeType.Create:
         *                      _progress.WriteVerbose("[{0}] Preview Create {1}", _currentGroup.Name, args.Path);
         *                      _currentGroup.NewFileCount++;
         *                      _currentGroup.NetChangeInBytes += args.NewFileData.Size;
         *                      _alreadyAccountedFor.Add(args.NewFileData.RelativePath);
         *                      break;
         *              case ChangeType.Update:
         *                      _progress.WriteVerbose("[{0}] Preview Update {1}", _currentGroup.Name, args.Path);
         *                      _currentGroup.UpdateFileCount++;
         *                      _currentGroup.NetChangeInBytes += args.NewFileData.Size;
         *                      _alreadyAccountedFor.Add(args.CurrentFileData.RelativePath);
         *                      break;
         *              case ChangeType.Delete:
         *                      if (!_currentGroup.NormallyPropogateDeletions)
         *                      {
         *                              args.SkipChange = true;
         *                              _progress.WriteVerbose("[{0}] Because of group policy, would not propagate deletion of {1}", _currentGroup.Name, args.Path);
         *                      }
         *                      else
         *                      {
         *                              _progress.WriteVerbose("[{0}] Preview Delete {1}", _currentGroup.Name, args.Path);
         *                              _currentGroup.DeleteFileCount++;
         *                      }
         *                      break;
         *      }
         *      InvokeProgress(args);
         * }*/

        private bool ShouldSkip(string mode, MirrorEventArgs args)
        {
            try
            {
                if (args.Situation == MirrorSituation.DirectoryMissing)
                {
                    string reasonForSkiping;
                    if (_currentGroup.ShouldSkipSubDirectory(args.Path, out reasonForSkiping))
                    {
                        _progress.WriteVerbose("{0} [{1}] Skipping folder '{2}' because {3}", mode, _currentGroup.Name, args.Path, reasonForSkiping);
                        return(true);
                    }
                    //TODO: what about if it is not missing, but should be removed ?
                    return(false);
                }

                if (_alreadyAccountedFor.Contains(args.Path))
                {
                    _progress.WriteVerbose(
                        "[{0}] Skipping '{1}' because it was already backed up by a previous group",
                        _currentGroup.Name, args.Path);
                    return(true);
                }
                string reasonForSkipping;
                if (_currentGroup.ShouldSkipFile(args.Path, out reasonForSkipping))
                {
                    _progress.WriteVerbose("[{0}] Skipping '{1}' because {2}", _currentGroup.Name, args.Path, reasonForSkipping);
                    return(true);
                }
            }
            catch (Exception e)
            {
                _progress.WriteException(e);
            }
            return(false);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// returns true if we want to cancel
        /// </summary>
        /// <returns></returns>
        public bool OnFileProgress(MirrorEventArgs args)
        {
            InvokeIfRequired(() =>
            {
                if (_controller.FilesCopiedThusFar >= syncProgressBar.Minimum &&
                    _controller.FilesCopiedThusFar <= syncProgressBar.Maximum)
                {
                    syncProgressBar.Value = _controller.FilesCopiedThusFar;
                }
                var max        = 40;
                string display = "";
                var parts      = args.Path.Split(new char[] { Path.DirectorySeparatorChar });
                //in case the neame itself is too long...
                if (parts.Length == 0)
                {
                    return;
                }
                if (parts[parts.Length - 1].Length > max)
                {
                    var length = args.Path.Length;
                    var start  = length > max ? length - max : 0;
                    length     = length > max ? max : length;
                    display    = args.Path.Substring(start, length);
                }
                else
                {
                    for (int i = parts.Length - 1; i >= 0; i--)
                    {
                        var potential = parts[i] + "/" + display;
                        if (potential.Length > max)
                        {
                            break;
                        }
                        display = potential;
                    }
                }
                display = display.TrimEnd(new char [] { '/' });

                switch (args.PendingAction)
                {
                case MirrorAction.Skip:
                    _status.Text = string.Format("Skipping {0}", display);
                    break;

                case MirrorAction.Create:
                    if (args.Situation == MirrorSituation.DirectoryMissing)
                    {
                        break;                         // don't make it look like we're copying a directory which we may later delete (because it ends up empty), which is then confusing "Why does it keep copying that thing over and over?"
                    }
                    _status.Text = string.Format("Copying {0}", display);
                    break;

                case MirrorAction.Delete:
                    _status.Text = string.Format("Processing {0}", display);                                         //nb "deleting" would scare people
                    break;

                case MirrorAction.DoNothing:
                    _status.Text = string.Format("Checking {0}", display);                          //another euphemism
                    break;

                case MirrorAction.Update:
                    _status.Text = string.Format("Updating {0}", display);
                    break;

                default:
                    break;
                }
            });
            return(GetIsCancellationPending(args));
        }
Ejemplo n.º 7
0
 bool GetIsCancellationPending(MirrorEventArgs unused)
 {
     return(_preparationWorker.CancellationPending || (_backupWorker != null && _backupWorker.CancellationPending));
 }