Beispiel #1
0
        protected virtual async Task <bool> RunFileHashing()
        {
            calculationProgress     = new Progress <RelhaxProgress>();
            cancellationTokenSource = new CancellationTokenSource();
            progress = new RelhaxProgress()
            {
                ChildCurrentProgress = "barWithTextChild", ChildCurrent = 0, ChildTotal = directoryFilesA.Length
            };
            fileHashComparer = new FileHashComparer()
            {
                CancellationTokenA = cancellationTokenSource.Token,
                CancellationTokenB = cancellationTokenSource.Token,
            };

            if (DatabaseAutomationRunner != null)
            {
                calculationProgress.ProgressChanged += DatabaseAutomationRunner.RelhaxProgressChanged;
            }

            try
            {
                for (int i = 0; i < directoryFilesA.Length; i++)
                {
                    await fileHashComparer.ComputeHashA(directoryFilesA[i]);

                    await fileHashComparer.ComputeHashB(directoryFilesB[i]);

                    string fileAHash = fileHashComparer.HashAStringBuilder?.ToString();
                    string fileBHash = fileHashComparer.HashBStringBuilder?.ToString();
                    Logging.Debug("File A hash: {0}", fileAHash);
                    Logging.Debug("File B hash: {0}", fileBHash);

                    AutomationCompareTracker.AddCompare(this, directoryFilesA[i], fileAHash, directoryFilesB[i], fileBHash, AutomationCompareMode.NoMatchContinue);
                    progress.ChildCurrent++;
                    (calculationProgress as IProgress <RelhaxProgress>).Report(progress);

                    if (cancellationTokenSource.Token.IsCancellationRequested)
                    {
                        cancellationTokenSource.Cancel();
                    }
                }
            }
            catch (OperationCanceledException) { }
            catch (Exception ex)
            {
                Logging.Exception(ex.ToString());
                return(false);
            }
            finally
            {
                cancellationTokenSource.Dispose();
                if (DatabaseAutomationRunner != null)
                {
                    calculationProgress.ProgressChanged -= DatabaseAutomationRunner.RelhaxProgressChanged;
                }
            }
            return(true);
        }
Beispiel #2
0
        public override async Task RunTask()
        {
            calculationProgress     = new Progress <RelhaxProgress>();
            cancellationTokenSource = new CancellationTokenSource();
            fileHashComparer        = new FileHashComparer()
            {
                CancellationTokenA = cancellationTokenSource.Token,
                CancellationTokenB = cancellationTokenSource.Token,
                ProgressA          = calculationProgress,
                ProgressB          = calculationProgress
            };

            if (DatabaseAutomationRunner != null)
            {
                calculationProgress.ProgressChanged += DatabaseAutomationRunner.RelhaxProgressChanged;
            }

            try
            {
                await fileHashComparer.ComputeHashA(FileA);

                await fileHashComparer.ComputeHashB(FileB);
            }
            catch (OperationCanceledException) { }
            catch (Exception ex)
            {
                Logging.Exception(ex.ToString());
            }
            finally
            {
                cancellationTokenSource.Dispose();
                if (DatabaseAutomationRunner != null)
                {
                    calculationProgress.ProgressChanged -= DatabaseAutomationRunner.RelhaxProgressChanged;
                }
            }

            fileAHash = fileHashComparer.HashAStringBuilder?.ToString();
            fileBHash = fileHashComparer.HashBStringBuilder?.ToString();
            Logging.Debug("File A hash: {0}", fileAHash);
            Logging.Debug("File B hash: {0}", fileBHash);
        }