Beispiel #1
0
 public ItemHandlingErrorArgs(string path,
                              MirrorAction actionThatWasBeingAttempted,
                              Exception error)
     : base(path, MirrorSituation.Error, actionThatWasBeingAttempted)
 {
     Exception = error;
 }
Beispiel #2
0
        private void RaiseItemHandlingError(string path, MirrorAction action, Exception error)
        {
            var args = new ItemHandlingErrorArgs(path, action, error);
            EventHandler <ItemHandlingErrorArgs> handler = ItemHandlingError;

            if (handler != null)
            {
                handler(this, args);
            }
        }
Beispiel #3
0
        private void HandleFile(string source, string dest)
        {
            MirrorAction action = GetActionForFile(source);

            try
            {
                switch (action)
                {
                case MirrorAction.Delete:
                    if (SafeIO.File.Exists(dest))
                    {
                        SafeIO.File.Delete(dest);
                        ++DeletedCount;
                    }
                    break;

                case MirrorAction.DoNothing:
                case MirrorAction.Skip:
                    break;

                case MirrorAction.Create:
                    if (SafeIO.File.Exists(dest))
                    {
                        SafeIO.File.Delete(dest);
                    }
                    SafeIO.File.Copy(source, dest, true);
                    ++CreatedCount;
                    break;

                case MirrorAction.Update:
                    ++UpdatedCount;
                    SafeIO.File.Copy(source, dest, true);
                    SafeIO.File.SetLastWriteTimeUtc(dest, SafeIO.File.GetLastWriteTimeUtc(source));
                    //always fails. Ah well. Debug.Assert(File.GetLastWriteTimeUtc(dest) == File.GetLastWriteTimeUtc(source));
                    break;

                default:
                    ThrowProgramError("Unexpected enumeration in switch: {0}", source);
                    break;
                }
            }
            catch (Exception error)
            {
                RaiseItemHandlingError(source, action, error);
            }
        }
Beispiel #4
0
 public MirrorEventArgs(string path, MirrorSituation situation, MirrorAction defaultAction)
 {
     Situation     = situation;
     Path          = path;
     PendingAction = defaultAction;
 }
Beispiel #5
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);
        }
Beispiel #6
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);
        }