Ejemplo n.º 1
0
        private XmlAnnotationFile ParseAnnotationFile(
            [NotNull] Type benchmarkType,
            [NotNull] string resourceFileName,
            [NotNull] IMessageLogger messageLogger)
        {
            var resourceKey      = GetResourceKey(benchmarkType);
            var resourceChecksum = AnnotationHelpers.TryGetChecksum(resourceKey, ChecksumAlgorithm.Sha1);
            var fileChecksum     = AnnotationHelpers.TryGetChecksum(resourceFileName, ChecksumAlgorithm.Sha1);

            if (!resourceChecksum.EqualsTo(fileChecksum))
            {
                var expected = resourceChecksum.ToHexString();
                var actual   = fileChecksum.ToHexString();
                messageLogger.WriteSetupErrorMessage(
                    $"{ChecksumAlgorithm.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));
        }
Ejemplo n.º 2
0
        private static XDocument TryParseXmlAnnotationDoc(
            string resourcePath,
            IMessageLogger messageLogger)
        {
            try
            {
                using (var stream = File.OpenRead(resourcePath))
                {
                    return(XmlAnnotationHelpers.TryParseXmlAnnotationDoc(
                               stream,
                               $"XML annotation '{resourcePath}'",
                               messageLogger));
                }
            }
            catch (IOException ex)
            {
                messageLogger.WriteExceptionMessage(
                    MessageSeverity.SetupError,
                    $"Could not access file '{resourcePath}'.", ex);

                return(null);
            }
            catch (UnauthorizedAccessException ex)
            {
                messageLogger.WriteExceptionMessage(
                    MessageSeverity.SetupError,
                    $"Could not access file '{resourcePath}'.", ex);

                return(null);
            }
        }
Ejemplo n.º 3
0
        /// <summary>Retrieves stored info for competition targets.</summary>
        /// <param name="targets">Competition targets the metrics are retrieved for.</param>
        /// <param name="analysis">State of the analysis.</param>
        /// <returns>Stored info for competition targets.</returns>
        protected override IReadOnlyDictionary <Target, StoredTargetInfo> GetStoredTargets(
            Target[] targets, Analysis analysis)
        {
            var resourceKey = GetResourceKey(analysis.RunState.BenchmarkType);

            var xmlAnnotationDoc = XmlAnnotationHelpers.TryParseXmlAnnotationDoc(resourceKey, analysis);

            if (xmlAnnotationDoc == null)
            {
                return(new Dictionary <Target, StoredTargetInfo>());
            }

            var metrics = analysis.Config.GetMetrics();
            var result  = XmlAnnotationHelpers.TryGetStoredTargets(
                targets, metrics,
                xmlAnnotationDoc,
                UseFullTypeName,
                analysis);

            return(result);
        }