/// <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> /// Determines whether [is cached calculated diffs valid] [the specified projected entity]. /// </summary> /// <param name="projectedEntity">The projected entity.</param> /// <returns> /// <c>true</c> if [is cached calculated diffs valid] [the specified projected entity]; otherwise, <c>false</c>. /// </returns> private bool IsCachedCalculatedDiffsValid(ProjectedDiffParts projectedEntity) { return (!string.IsNullOrWhiteSpace(projectedEntity?.CalculatedDiffsMetadata) && projectedEntity.ParsedCalculatedDiffsMetadataTimestamp.HasValue && projectedEntity.ParsedLeftPartTimestamp.HasValue && projectedEntity.ParsedRightPartTimestamp.HasValue && projectedEntity.ParsedCalculatedDiffsMetadataTimestamp.Value > projectedEntity.ParsedLeftPartTimestamp.Value && projectedEntity.ParsedCalculatedDiffsMetadataTimestamp.Value > projectedEntity.ParsedRightPartTimestamp.Value); }
/// <summary> /// Checks the validation for calculated diffs paramter. /// </summary> /// <param name="projectedEntity">The projected entity.</param> /// <exception cref="System.ArgumentNullException"></exception> /// <exception cref="System.ArgumentException"></exception> private void CheckValidationForCalculatedDiffsParamter(ProjectedDiffParts projectedEntity) { if (projectedEntity == null) { throw new ArgumentNullException($"'{nameof(projectedEntity)}' parameter is null"); } if (string.IsNullOrEmpty(projectedEntity.LeftPartFilePath) || string.IsNullOrEmpty(projectedEntity.RightPartFilePath)) { throw new ArgumentException($"'{nameof(projectedEntity)}' parameter has invalid properties"); } if (!File.Exists(projectedEntity.LeftPartFilePath)) { throw new ArgumentException($"File {projectedEntity.LeftPartFilePath} could not be found"); } if (!File.Exists(projectedEntity.RightPartFilePath)) { throw new ArgumentException($"File {projectedEntity.RightPartFilePath} could not be found"); } }