private static void RunCompare(Opts opts, CancellationToken CtrlCEvent, TextWriter errWriter) { DateTime start = DateTime.Now; using (DiffWriter diffWriters = new DiffWriter()) { Stats stats = new Stats(); var enumOpts = new EnumOptions() { followJunctions = opts.FollowJunctions, maxDepth = opts.Depth, forceSortSource = opts.forceSortSource, forceSortTarget = opts.forceSortTarget }; DiffProcessing diffProcessor = new DiffProcessing(stats, diffWriters, opts.reportSameFile); string src = Spi.Long.GetLongFilenameNotation(opts.sourceDir.TrimEnd('\\')); string trg = Spi.Long.GetLongFilenameNotation(opts.targetDir.TrimEnd('\\')); Console.Error.WriteLine($"source: {src}\ntarget: {trg}"); var paraCmp = new CmpDirsParallel( sourceDir: src, targetDir: trg, opts: enumOpts, diffHandler: diffProcessor.DiffCallback, errorHandler: (int RetCode, string Message) => { Interlocked.Increment(ref stats.Errors); errWriter.WriteLine($"E: rc={RetCode}\t{Message}"); }, CtrlCEvent: CtrlCEvent, maxThreadsToRun: opts.MaxThreads); paraCmp.Start(); StatusLineWriter statWriter = new StatusLineWriter(); using (Process currProc = System.Diagnostics.Process.GetCurrentProcess()) { Misc.ExecUtilWaitHandleSet(paraCmp.Finished, 2000, () => WriteProgress(stats, currProc, paraCmp.Queued, paraCmp.Running, paraCmp.Done, statWriter)); } WriteStatistics(new TimeSpan(DateTime.Now.Ticks - start.Ticks), paraCmp.Done, stats); if (stats.Errors > 0) { Console.Error.WriteLine($"{stats.Errors} erros occoured. please see file {opts.errorFilename}."); } } }
public CmpDirsParallel(string sourceDir, string targetDir, EnumOptions opts, DiffHandler diffHandler, ErrorHandler errorHandler, CancellationToken CtrlCEvent, int maxThreadsToRun) { _opts = opts; _diffHandler = diffHandler; _errorHandler = errorHandler; _CtrlCEvent = CtrlCEvent; _executor = new Spi.ParallelExecutor <ParallelCtx, object, RootDirs>( initTL: () => new RootDirs(sourceDir, targetDir) , func: CompareTwoDirectories , freeTL: null , context: null , maxThreads: maxThreadsToRun , cancel: CtrlCEvent ); }