/// <summary> /// Calculates the diffs asynchronous. /// </summary> /// <param name="projectedEntity">The projected entity.</param> /// <returns></returns> private async Task <CalculatedDiffsFeedback> CalculateDiffsAsync(ProjectedDiffParts projectedEntity) { CheckValidationForCalculatedDiffsParamter(projectedEntity); var leftFileInfo = new FileInfo(projectedEntity.LeftPartFilePath); leftFileInfo.Refresh(); long leftPartLength = leftFileInfo.Length; var rightFileInfo = new FileInfo(projectedEntity.RightPartFilePath); rightFileInfo.Refresh(); long rightFileLength = rightFileInfo.Length; if (leftPartLength != rightFileLength) { return(new CalculatedDiffsFeedback { OperationSucceeded = true, LeftPartSize = leftPartLength.ToString(), RightPartSize = rightFileLength.ToString(), PartsAreEqual = false }); } CalculatedDiffsFeedback calculatedDiffs = await CalculateDiffsForEqualSizeFilesContent(projectedEntity.LeftPartFilePath, projectedEntity.RightPartFilePath, rightFileLength); return(calculatedDiffs); }
/// <summary> /// Calculates the content of the diffs for equal size files. /// </summary> /// <param name="leftPartFilePath">The left part file path.</param> /// <param name="rightPartFilePath">The right part file path.</param> /// <param name="sizeOfContentToBeProcessed">The size of content to be processed.</param> /// <returns></returns> private async Task <CalculatedDiffsFeedback> CalculateDiffsForEqualSizeFilesContent(string leftPartFilePath, string rightPartFilePath, long sizeOfContentToBeProcessed) { using (var blockingCollection = ProduceBufferBlocksCollection(leftPartFilePath, rightPartFilePath)) { var differencesCountsByOffset = await ProcessSegmentsOfDataByConsumingFromrCollectionAsync(blockingCollection); var normalizedDiffDetails = GetNormalizedDiffDetails(differencesCountsByOffset); CalculatedDiffsFeedback feedback = new CalculatedDiffsFeedback { OperationSucceeded = true, LeftPartSize = sizeOfContentToBeProcessed.ToString(), RightPartSize = sizeOfContentToBeProcessed.ToString(), }; if (normalizedDiffDetails != null && normalizedDiffDetails.Count > 0) { feedback.PartsAreEqual = false; feedback.DiffsMetadata = normalizedDiffDetails; } else { feedback.PartsAreEqual = true; } return(feedback); } }