public void DoBackup(string sourceFolder, string destFolder, bool doNotDeleteDestFiles)
        {
            var sourceNode = new FolderNode(new DirectoryInfo(sourceFolder));
            var destNode   = new FolderNode(new DirectoryInfo(destFolder));

            var synchronizer = new Synchronizer();
            var actions      = synchronizer.Synchronize <FolderNode, FileNodeElement>(sourceNode, destNode);

            var fileSystemActions = new FileSystemActions();

            foreach (var action in actions)
            {
                switch (action.ActionType)
                {
                case ActionType.DeleteDestNodeElement:
                    if (!doNotDeleteDestFiles)
                    {
                        OnFileDelete?.Invoke(this, action.DestinationNodeElement);
                        fileSystemActions.Remove(action.DestinationNodeElement);
                    }
                    break;

                case ActionType.CopySourceNodeElementToDestination:
                    OnFileCopy?.Invoke(this, new FileCopyArgs(action.SourceNodeElement, action.DestinationNode));
                    fileSystemActions.Add(action.DestinationNode, action.SourceNodeElement);
                    break;

                case ActionType.DeleteDestNode:
                    if (!doNotDeleteDestFiles)
                    {
                        OnFolderDelete?.Invoke(this, action.DestinationNode);
                        fileSystemActions.Remove(action.DestinationNode);
                    }
                    break;

                case ActionType.CopySourceNodeToDestination:
                    OnFolderCopy?.Invoke(this, new FolderCopyArgs(action.SourceNode, action.DestinationNode));
                    fileSystemActions.Add(action.DestinationNode, action.SourceNode);
                    break;
                }
            }
        }
Exemple #2
0
        private void FireFileCopyEvent(string file1, string file2)
        {
            var eventArgs = new DirectoryCopierCopyEventArgs(file1, file2);

            OnFileCopy?.Invoke(this, eventArgs);
        }