public static DirectoryDifference FromJObject(JObject source) { string dataCommonSubdir = source.GetValue(nameof(DataCommonSubdir)).ToString(); DirectoryDifference deserialized = new DirectoryDifference(dataCommonSubdir); foreach (JObject fileInfo in source.GetValue(nameof(FileResults))) { FileDifference fileDiff = FileDifference.FromJObject(fileInfo); deserialized.AddFileResult(fileDiff); } return(deserialized); }
public static FileDifference FromJObject(JObject source) { string filename = source.GetValue(nameof(File)).ToString(); FileDifference fileDifference = new FileDifference(filename); if (source.TryGetValue(nameof(Differences), out JToken differenceJToken)) { foreach (JObject diffInfo in (JArray)differenceJToken) { PositionalDifference positionalDiff = PositionalDifference.FromJObject(diffInfo); fileDifference.AddDifference(positionalDiff); } } return(fileDifference); }
public DirectoryDifference Compare() { DirectoryDifference allResults = new DirectoryDifference(_commonSubdir); HashSet <string> baselineFilenameLookup = new HashSet <string>(); List <string> baselineOnly = new List <string>(); foreach (string baselineFilename in Directory.EnumerateFiles(_baselineDataDir, "*.*", SearchOption.AllDirectories)) { string relativeFilename = baselineFilename.Substring(_baselineDataDir.Length); baselineFilenameLookup.Add(relativeFilename); string secondaryFilename = Path.Combine(_secondaryDataDir, relativeFilename); FileDifference fileDifference = new FileDifference(relativeFilename); allResults.AddFileResult(fileDifference); if (!File.Exists(secondaryFilename)) { fileDifference.MissingSecondaryFile = true; } else { FileComparer fileComparer = new FileComparer(baselineFilename, secondaryFilename); IReadOnlyList <PositionalDifference> differenceList = fileComparer.Compare(); if (differenceList.Count > 0) { fileDifference.AddDifferences(differenceList); } } } foreach (string secondaryFilename in Directory.EnumerateFiles(_secondaryDataDir, "*.*", SearchOption.AllDirectories)) { string relativeFilename = secondaryFilename.Substring(_secondaryDataDir.Length); if (!baselineFilenameLookup.Contains(relativeFilename)) { string baselineFilename = Path.Combine(_baselineDataDir, relativeFilename); FileDifference fileDifference = new FileDifference(relativeFilename); fileDifference.MissingBaselineFile = true; allResults.AddFileResult(fileDifference); } } return(allResults); }
public void AddFileResult(FileDifference fileDiff) { _fileResults.Add(fileDiff); }