public async override Task RunTask()
        {
            RunSearch();

            //check that the same number of files was returned to check for hashing
            if (directoryFilesA.Length != directoryFilesB.Length)
            {
                Logging.Info("The number of files between directory a ({0}) and directory b ({1}) do not match, update needed", directoryFilesA.Length, directoryFilesB.Length);
                AutomationCompareTracker.AddCompare(this, DirectoryComparePathA, DirectoryComparePathB, directoryFilesA.Length.ToString(), directoryFilesB.Length.ToString(), AutomationCompareMode.NoMatchContinue);
                operationFinished = true;
                return;
            }

            //check that the relative paths match between the folders
            for (int i = 0; i < directoryFilesA.Length; i++)
            {
                string relativePathA = directoryFilesA[i].Replace(DirectoryComparePathA, "");
                string relativePathB = directoryFilesB[i].Replace(DirectoryComparePathB, "");

                if (!relativePathA.Equals(relativePathB))
                {
                    Logging.Info("At index {0}, relative path a ({1}) does not match relative path b ({2})", i, relativePathA, relativePathB);
                    Logging.Info("The paths have changed, update needed");
                    AutomationCompareTracker.AddCompare(this, DirectoryComparePathA, DirectoryComparePathB, relativePathA, relativePathB, AutomationCompareMode.NoMatchContinue);
                    operationFinished = true;
                    return;
                }
            }

            //actually run the hashing
            operationFinished = await RunFileHashing();
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public override void ProcessTaskResults()
        {
            if (ProcessTaskResultTrue(!fileHashComparer.HashACalculated, "Hash A failed to calculate"))
            {
                return;
            }
            if (ProcessTaskResultTrue(!fileHashComparer.HashBCalculated, "Hash B failed to calculate"))
            {
                return;
            }

            //getting to here means that successful hashes were calculated
            AutomationCompareTracker.AddCompare(this, FileA, fileAHash, FileB, fileBHash, AutomationCompareMode.NoMatchContinue);
        }
Exemplo n.º 4
0
 public override async Task RunTask()
 {
     Logging.Info("Clear previous compares");
     AutomationCompareTracker.Reset();
 }