Esempio n. 1
0
 public void SyncDirectory(DirectoryInfo pDir, DirectoryInfo sDir, DirectoryNumbers dirNums, IProgramArgs progArgs)
 {
     try
     {
         ++_dirCount;
         if (progArgs.IsSkipDirCopy(pDir))
         {
             Log.Info($"Skip \"{pDir.FullName}\" and all its subdirectories");
             return;
         }
         UnsafeSyncDirectory(pDir, sDir, dirNums, progArgs);
     }
     catch (Exception ex)
     {
         //_log.Log<Sync>(LogLevel.Error, $"Error while Syncing directories:  {ex.Message}", ex);
         Log.Error($"Error while Syncing directories:  {ex.Message}", ex);
     }
 }
Esempio n. 2
0
        private void UnsafeSyncDirectory(DirectoryInfo pDir, DirectoryInfo sDir, DirectoryNumbers dirNums, IProgramArgs progArgs)
        {
            if (progArgs.IsSkipFileCopy(pDir))
            {
                Log.Info($"({_dirCount:#,##0}).  Skipping \"{pDir.FullName}\"");
            }
            else
            {
                if (_isCopy)
                {
                    var sw = new Stopwatch();
                    CopyFiles(pDir, sDir);
                    sw.Stop();
                    Log.Info($"({_copyFileCount:#,##0}/{_copyDirCount:#,##0}/{_dirCount:#,##0}).  P-Dir: \"{pDir.FullName}\"\tS-Dir: \"{sDir.FullName}\"\t{sw.Elapsed.TotalSeconds} [sec].  ({dirNums.NestingLevel}/{dirNums.DirectoryCount}/{dirNums.TotalDirectoryCount})");
                }
                else
                {
                    Log.Info($"({_dirCount:#,##0}, {dirNums.NestingLevel}/{dirNums.DirectoryCount}/{dirNums.TotalDirectoryCount}).  P-Dir: \"{pDir.FullName}\"\tS-Dir: \"{sDir.FullName}\"");
                }

                CopyFiles(pDir, sDir);
            }

            // Directories
            DirectoryInfo[] pDis = pDir.GetDirectories();
            DirectoryInfo[] sDis = sDir.GetDirectories();
            Array.Sort(pDis, (e1, e2) => string.Compare(e1.Name, e2.Name, StringComparison.OrdinalIgnoreCase));
            Array.Sort(sDis, (e1, e2) => string.Compare(e1.Name, e2.Name, StringComparison.OrdinalIgnoreCase));

            int dirCnt    = 0;
            int totDirCnt = pDis.Length;

            foreach (var pDi in pDis)
            {
                CopyDirectory(pDi, sDir, sDis, dirNums.NextNumbers(++dirCnt, totDirCnt), progArgs);
            }
        }
Esempio n. 3
0
        private void CopyDirectory(DirectoryInfo pDi, DirectoryInfo sDir, DirectoryInfo[] sDis, DirectoryNumbers dirNums, IProgramArgs progArgs)
        {
            if (_excludeDirectoriesStartingWith.Any(e => pDi.Name.StartsWith(e, StringComparison.InvariantCultureIgnoreCase)))
            {
                return;
            }

            //Log.Info($"{MethodBase.GetCurrentMethod().Name}: Primary: \"{pDi.FullName}\".\tSecondary: \"{sDir.FullName}\"");
            var sDi = sDis.FirstOrDefault(s => string.Compare(s.Name, pDi.Name, StringComparison.InvariantCultureIgnoreCase) == 0);

            if (sDi == null)
            {
                //_log.Log<Sync>(LogLevel.Info, $"[PD]\t{pDi.FullName}");
                string destination = Path.Combine(sDir.FullName, Path.GetFileName(pDi.FullName));
                if (_isCopy)
                {
                    var sw = new Stopwatch();
                    sw.Start();
                    _fs.CopyDirectory(pDi.FullName, destination);
                    ++_copyDirCount;
                    sw.Stop();
                    Log.Info($"[PD]\t\"{pDi.FullName}\"\t{sw.Elapsed.TotalSeconds} [sec], ({dirNums.NestingLevel}/{dirNums.DirectoryCount}/{dirNums.TotalDirectoryCount})");
                }
                else
                {
                    Log.Info($"[PD]\t\"{pDi.FullName}\"\t(Report only), ({dirNums.NestingLevel}/{dirNums.DirectoryCount}/{dirNums.TotalDirectoryCount})");
                }
            }
            else
            {
                SyncDirectory(pDi, sDi, dirNums, progArgs);
            }
        }