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); }
public async Task Test04_FileHashCompareTest() { //first test the individual component, then the task FileHashComparer fileHashComparer = new FileHashComparer(); string fileAPath = Path.Combine(UnitTestHelper.ResourcesFolder, "battleAtlas.dds"); string fileACorrectHashPath = Path.Combine(UnitTestHelper.ResourcesFolder, "battleAtlas.dds.md5"); string fileACorrectHash = File.ReadAllText(fileACorrectHashPath); await fileHashComparer.ComputeHashA(fileAPath); Assert.IsTrue(fileHashComparer.HashACalculated); Assert.IsNotNull(fileHashComparer.HashAStringBuilder); Assert.AreEqual(fileACorrectHash.ToLower(), fileHashComparer.HashAStringBuilder.ToString().ToLower()); }
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); }