Пример #1
0
            /// <summary>Tries lo load the xml annotation document.</summary>
            /// <param name="file">The file with xml annotation.</param>
            /// <param name="useFullTypeName">Use full type name in XML annotations.</param>
            /// <param name="competitionState">State of the run.</param>
            /// <returns>The document with competition limits for the benchmark or <c>null</c> if none.</returns>
            public XDocument TryGetXmlAnnotation(
                [NotNull] string file,
                bool useFullTypeName,
                [NotNull] CompetitionState competitionState)
            {
                Code.NotNullNorEmpty(file, nameof(file));
                Code.NotNull(competitionState, nameof(competitionState));
                Code.AssertState(!_sourceLines.ContainsKey(file), $"File '{file}' already loaded as source lines.");

                return(_xmlAnnotations.GetOrAdd(
                           file, f =>
                {
                    try
                    {
                        using (var reader = File.OpenText(f))
                        {
                            return XmlAnnotations.TryParseXmlAnnotationDoc(
                                reader, useFullTypeName, competitionState,
                                $"XML annotation '{file}'");
                        }
                    }
                    catch (IOException ex)
                    {
                        competitionState.WriteExceptionMessage(
                            MessageSource.Analyser, MessageSeverity.SetupError,
                            $"Could not access file '{file}'.", ex);

                        return null;
                    }
                }));
            }
Пример #2
0
            /// <summary>Saves modified files.</summary>
            public void Save()
            {
                if (!HasChanges)
                {
                    return;
                }

                foreach (var pair in _sourceLines)
                {
                    if (_changedFiles.Contains(pair.Key))
                    {
                        BenchmarkHelpers.WriteFileContent(pair.Key, pair.Value);
                    }
                }

                foreach (var pair in _xmlAnnotations)
                {
                    if (_changedFiles.Contains(pair.Key))
                    {
                        using (var writer = new StreamWriter(pair.Key))
                        {
                            XmlAnnotations.Save(pair.Value, writer);
                        }
                    }
                }
            }
Пример #3
0
        private static bool TryFixBenchmarkXmlAnnotation(
            AnnotateContext annotateContext, string xmlFileName,
            CompetitionTarget competitionTarget,
            CompetitionState competitionState)
        {
            Code.AssertArgument(
                competitionTarget.CompetitionMetadata != null, nameof(competitionTarget),
                "Competition metadata cannot be null for xml annotations.");

            var xmlAnnotationDoc = annotateContext.TryGetXmlAnnotation(
                xmlFileName,
                competitionTarget.CompetitionMetadata.UseFullTypeName,
                competitionState);

            if (xmlAnnotationDoc == null)
            {
                return(false);
            }

            XmlAnnotations.AddOrUpdateXmlAnnotation(xmlAnnotationDoc, competitionTarget);
            annotateContext.MarkAsChanged(xmlFileName);

            return(true);
        }