private XmlAnnotationFile ParseAnnotationFile( [NotNull] Type benchmarkType, [NotNull] string resourceFileName, [NotNull] IMessageLogger messageLogger) { var resourceKey = GetResourceKey(benchmarkType); var resourceChecksum = PdbHelpers.TryGetChecksum(resourceKey, PdbChecksumAlgorithm.Sha1); var fileChecksum = PdbHelpers.TryGetChecksum(resourceFileName, PdbChecksumAlgorithm.Sha1); if (!resourceChecksum.EqualsTo(fileChecksum)) { var expected = resourceChecksum.ToHexString(); var actual = fileChecksum.ToHexString(); messageLogger.WriteSetupErrorMessage( $"{PdbChecksumAlgorithm.Sha1} checksum validation failed. File '{resourceFileName}'." + $"{Environment.NewLine}\tActual: 0x{actual}" + $"{Environment.NewLine}\tExpected: 0x{expected}"); return(new XmlAnnotationFile(resourceFileName, null)); } var xmlAnnotationDoc = XmlAnnotationHelpers.TryParseXmlAnnotationDoc(resourceFileName, messageLogger); return(new XmlAnnotationFile(resourceFileName, xmlAnnotationDoc)); }
private static bool TryValidate(SourceAnnotationInfo documentInfo, IMessageLogger messageLogger) { bool result = true; if (documentInfo.SourceLanguage != SourceLanguage.CSharp) { messageLogger.WriteSetupErrorMessage( $"Document language {documentInfo.SourceLanguage} is unsupported. File '{documentInfo.Path}'."); result = false; } if (documentInfo.MethodLinesMap.IsEmpty) { // TODO: improve message messageLogger.WriteSetupErrorMessage( $"No methods found in document '{documentInfo.Path}'."); result = false; } if (!documentInfo.MethodLinesMap.IsMerged) { var methodsIntersection = documentInfo.MethodLinesMap .GetIntersections() .FirstOrDefault(i => i.Ranges.Count > 1); DebugCode.BugIf(methodsIntersection.IsEmpty, "methodsIntersection.IsEmpty"); var methodNames = methodsIntersection.Ranges.Select(r => r.Key.Name).Join(", "); // TODO: improve message messageLogger.WriteSetupErrorMessage( $"Some of methods in document share same source lines {methodsIntersection.IntersectionRange}: " + $"{methodNames}. Document '{documentInfo.Path}'."); result = false; } var symbolsChecksum = documentInfo.Checksum; var fileChecksum = PdbHelpers.TryGetChecksum(documentInfo.Path, documentInfo.ChecksumAlgorithm); if (!symbolsChecksum.EqualsTo(fileChecksum)) { var expected = symbolsChecksum.ToHexString(); var actual = fileChecksum.ToHexString(); messageLogger.WriteSetupErrorMessage( $"{PdbChecksumAlgorithm.Sha1} checksum validation failed. File '{documentInfo.Path}'." + $"{Environment.NewLine}\tActual: 0x{actual}" + $"{Environment.NewLine}\tExpected: 0x{expected}"); result = false; } return(result); }