示例#1
0
        /// <summary>
        /// Actually copy a tree; to be called by derived class
        /// </summary>
        protected void DoCopyTree(SyncDirectoryInfo from, SyncFileDirName toFullPath)
        {
            Actioner.CreateDirectory(toFullPath.FullName);
            var toCopy = new Stack <string>();

            toCopy.Push("");
            while (toCopy.Count() > 0)
            {
                string path     = toCopy.Pop();
                string fromPath = Path.Combine(from.FullName, path);
                string toPath   = Path.Combine(toFullPath.FullName, path);
                foreach (var fileName in Directory.EnumerateFiles(fromPath))
                {
                    // fileName contains full path, so need to extract filename!
                    string name = Path.GetFileName(fileName);
                    Actioner.Copy(Path.Combine(fromPath, name), Path.Combine(toPath, name));
                }
                foreach (var dirName in Directory.EnumerateDirectories(fromPath))
                {
                    var fullDirName = Path.Combine(path, Path.GetFileName(dirName));
                    Actioner.CreateDirectory(Path.Combine(toPath, fullDirName));
                    toCopy.Push(fullDirName);
                }
            }
        }
示例#2
0
 public override void DeleteTree(SyncDirectoryInfo dir)
 {
     if (Responder.SeekYes(String.Format("Delete all of tree {0}", dir.FullName)))
     {
         DoDeleteTree(dir);
     }
 }
示例#3
0
        // Useful helper functions
        /// <summary>
        /// Unconditionally delete a tree; to be called by derived class after, presumably, some sort
        /// of checking code.
        /// </summary>
        protected void DoDeleteTree(SyncDirectoryInfo dir)
        {
            var toDelete = new Stack <string>();

            toDelete.Push(dir.FullName);
            var emptyDirs = new List <string>();

            while (toDelete.Count() > 0)
            {
                string path = toDelete.Pop();
                foreach (var fileName in Directory.EnumerateFiles(path))
                {
                    Actioner.DeleteFile(fileName);
                }
                foreach (var dirName in Directory.EnumerateDirectories(path))
                {
                    toDelete.Push(Path.Combine(path, dirName));
                }
                emptyDirs.Add(path);
            }
            foreach (var dirName in emptyDirs)
            {
                Actioner.DeleteDirectory(dirName);
            }
        }
示例#4
0
 public override void CopyTree(SyncDirectoryInfo from, SyncFileDirName toFullPath)
 {
     DoCopyTree(from, toFullPath);
 }
示例#5
0
 public abstract void CopyTree(SyncDirectoryInfo from, SyncFileDirName toFullPath);
示例#6
0
 public abstract void DeleteTree(SyncDirectoryInfo dir);
示例#7
0
 public override void CopyTree(SyncDirectoryInfo from, SyncFileDirName toFullPath)
 {
     Logger.WriteLine("CopyTree '{0}' -> '{1}'", from, toFullPath);
 }
示例#8
0
 /// <summary>
 /// Take decision about sub-directory when external exists but local does not.
 /// </summary>
 public abstract void ProcessDir(SyncFileDirName localDir, SyncDirectoryInfo externalDir);
示例#9
0
 /// <summary>
 /// Local directory does not exist, so copy
 /// </summary>
 public override void ProcessDir(SyncFileDirName localDir, SyncDirectoryInfo externalDir)
 {
     mover.CopyTree(from: externalDir, toFullPath: localDir);
 }
示例#10
0
 /// <summary>
 /// Local directory exists but external does not, so delete local
 /// </summary>
 public override void ProcessDir(SyncDirectoryInfo localDir, SyncFileDirName externalDir)
 {
     mover.DeleteTree(localDir);
 }