Exemple #1
0
        private static int AddSourceOnlyFiles(FolderDiffBase folderDiff, ProgressReporter progressReporter, int reportCount)
        {
            // Add source only files to target
            ProgressReporter.Logger.WriteLine("Copying " + folderDiff.SourceOnlyFiles.Length + " new files");

            int consoleTh  = folderDiff.SourceOnlyFiles.Length / reportCount;
            int k          = 0;
            int errorCount = 0;

            Parallel.For(0, folderDiff.SourceOnlyFiles.Length, new ParallelOptions()
            {
                MaxDegreeOfParallelism = Program.MaxDegreeOfParallelism
            }, i =>
            {
                string sourcePath = Path.Combine(folderDiff.SourcePath, folderDiff.SourceOnlyFiles[i]);
                string targetPath = Path.Combine(folderDiff.TargetPath, folderDiff.SourceOnlyFiles[i]);

                // read https://stackoverflow.com/questions/265953/how-can-you-easily-check-if-access-is-denied-for-a-file-in-net
                try
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(targetPath));
                    File.Copy(sourcePath, targetPath);
                }
                catch (Exception e)
                {
                    Interlocked.Increment(ref errorCount);
                    ProgressReporter.Logger.WriteLine("\r\nERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR\r\nERROR : " + e.ToString() + "\r\nERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR\r\n");
                }
                progressReporter.AddNewFileProgress(i);

                int progress = Interlocked.Increment(ref k);
                progressReporter.WriteDetailedNewFileReport(sourcePath, targetPath, i, LogLevel.File);
                if (consoleTh == 0 || progress % consoleTh == 0)
                {
                    progressReporter.WriteReport(LogLevel.Console);
                }
            });
            progressReporter.WriteReport(LogLevel.Console | LogLevel.File);
            return(errorCount);
        }
Exemple #2
0
        private static int OverwriteModifiedFiles(FolderDiffBase folderDiff, ProgressReporter progressReporter, int reportCount)
        {
            // Replace target files that have been edited in source with their new version
            ProgressReporter.Logger.WriteLine("Overwritting " + folderDiff.ModifiedFiles.Length + " modified files");

            int consoleTh  = folderDiff.ModifiedFiles.Length / reportCount;
            int k          = 0;
            int errorCount = 0;

            Parallel.For(0, folderDiff.ModifiedFiles.Length, new ParallelOptions()
            {
                MaxDegreeOfParallelism = Program.MaxDegreeOfParallelism
            }, i =>
            {
                string sourcePath = Path.Combine(folderDiff.SourcePath, folderDiff.ModifiedFiles[i]);
                string targetPath = Path.Combine(folderDiff.TargetPath, folderDiff.ModifiedFiles[i]);

                // read https://stackoverflow.com/questions/265953/how-can-you-easily-check-if-access-is-denied-for-a-file-in-net
                try
                {
                    File.Copy(sourcePath, targetPath, true);
                }
                catch (Exception e)
                {
                    Interlocked.Increment(ref errorCount);
                    ProgressReporter.Logger.WriteLine("\r\nERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR\r\nERROR : " + e.ToString() + "\r\nERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR\r\n");
                }

                progressReporter.AddModifiedFileProgress(i);

                int progress = Interlocked.Increment(ref k);
                progressReporter.WriteDetailedModifiedFileReport(sourcePath, targetPath, i, LogLevel.File);
                if (consoleTh == 0 || progress % consoleTh == 0)
                {
                    progressReporter.WriteReport(LogLevel.Console);
                }
            });
            progressReporter.WriteReport(LogLevel.Console | LogLevel.File);
            return(errorCount);
        }
Exemple #3
0
        private static int DeleteSourceOnlyFiles(FolderDiffBase folderDiff, int reportCount)
        {
            // Remove target only files
            ProgressReporter.Logger.WriteLine(folderDiff.TargetOnlyFiles.Length + " files will be removed");

            int k          = 0;
            int consoleTh  = folderDiff.TargetOnlyFiles.Length / reportCount;
            int errorCount = 0;

            Parallel.For(0, folderDiff.TargetOnlyFiles.Length, new ParallelOptions()
            {
                MaxDegreeOfParallelism = Program.MaxDegreeOfParallelism
            }, i =>
            {
                string path = Path.Combine(folderDiff.TargetPath, folderDiff.TargetOnlyFiles[i]);

                // read https://stackoverflow.com/questions/265953/how-can-you-easily-check-if-access-is-denied-for-a-file-in-net
                try
                {
                    File.Delete(path);
                }
                catch (Exception e)
                {
                    Interlocked.Increment(ref errorCount);
                    ProgressReporter.Logger.WriteLine("\r\nERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR\r\nERROR : " + e.ToString() + "\r\nERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR\r\n");
                }

                int progress = Interlocked.Increment(ref k);
                ProgressReporter.Logger.WriteLine("Deleted " + path + " --- " + progress + " / " + folderDiff.TargetOnlyFiles.Length + " files", LogLevel.File);
                if (consoleTh == 0 || progress % consoleTh == 0)
                {
                    ProgressReporter.Logger.WriteLine("Deleted " + progress + " / " + folderDiff.TargetOnlyFiles.Length + " files", LogLevel.Console);
                }
            });
            return(errorCount);
        }