/// <summary> /// Initializes a new instance of the <see cref="OpenCoverParser"/> class. /// </summary> /// <param name="report">The report file as XContainer.</param> internal OpenCoverParser(XContainer report) { if (report == null) { throw new ArgumentNullException(nameof(report)); } this.modules = report.Descendants("Module") .Where(m => m.Attribute("skippedDueTo") == null) .ToArray(); this.files = report.Descendants("File").ToArray(); this.trackedMethods = report.Descendants("TrackedMethod") .ToDictionary(t => t.Attribute("uid").Value, t => t.Attribute("name").Value); var assemblyNames = this.modules .Select(m => m.Element("ModuleName").Value) .Distinct() .OrderBy(a => a) .ToArray(); Parallel.ForEach(assemblyNames, assemblyName => this.AddAssembly(this.ProcessAssembly(assemblyName))); this.modules = null; this.files = null; this.trackedMethods = null; }
/// <summary> /// Initializes a new instance of the <see cref="PartCover22Parser"/> class. /// </summary> /// <param name="report">The report file as XContainer.</param> public PartCover22Parser(XContainer report) : base(report) { // Init the HashSet containing the covered assemblies this.assembliesHashSet = new HashSet<string>(report.Descendants("type").Select(type => type.Attribute("asm").Value).Distinct()); var fileIdByFilenameDictionary = report.Descendants("file").ToDictionary(f => f.Attribute("url").Value, f => f.Attribute("id").Value); AddCoverageDataOfAutoProperties(report); // Init the Dictionary containing the line coverage information Parallel.ForEach( this.Assemblies(), assembly => { logger.DebugFormat(" Current Assembly: {0}", assembly); Parallel.ForEach( this.ClassesInAssembly(assembly), clazz => { Parallel.ForEach( this.FilesOfClass(assembly, clazz), file => { string fileId = fileIdByFilenameDictionary[file]; var seqpntsOfFile = report.Descendants("type") .Where(type => type.Attribute("asm").Value.Equals(assembly) && type.Attribute("name").Value.StartsWith(clazz, StringComparison.Ordinal)) .Descendants("pt") .Where(seqpnt => seqpnt.HasAttributeWithValue("fid", fileId)) .OrderBy(seqpnt => int.Parse(seqpnt.Attribute("sl").Value, CultureInfo.InvariantCulture)) .ToArray(); if (seqpntsOfFile.Length > 0) { var coverage = new int[int.Parse(seqpntsOfFile.Last().Attribute("sl").Value, CultureInfo.InvariantCulture) + 1]; for (int i = 0; i < coverage.Length; i++) { coverage[i] = -1; } foreach (var seqpnt in seqpntsOfFile) { var index = int.Parse(seqpnt.Attribute("sl").Value, CultureInfo.InvariantCulture); var value = int.Parse(seqpnt.Attribute("visit").Value, CultureInfo.InvariantCulture); coverage[index] = coverage[index] == -1 ? value : coverage[index] + value; } this.LineCoverageByFileDictionary.TryAdd(assembly + "_" + clazz + "_" + file, coverage); } }); }); }); }
public AclEntry(XContainer element) { AclPermission permission; Permission = Enum.TryParse(element.Descendants("Permission").Select(e => e.Value).FirstOrDefault() ?? String.Empty, out permission) ? permission : AclPermission.READ; Scope = ScopeBuilder.CreateScope(element.Descendants("Scope").First()); }
void ReadResults(XContainer reader) { IEnumerable<XElement> modules = reader.Descendants("Module").Where(m => m.Attribute("skippedDueTo") == null); foreach (XElement file in reader.Descendants("File")) { AddFileName(file); } foreach (XElement assembly in modules) { AddAssembly(assembly); RegisterAssembly(assembly); } }
/// <summary> /// Initializes a new instance of the <see cref="NCoverParser"/> class. /// </summary> /// <param name="report">The report file as XContainer.</param> public NCoverParser(XContainer report) : base(report) { // Init the HashSet containing the covered assemblies this.assembliesHashSet = new HashSet<string>(report.Descendants("module").Select(module => module.Attribute("assembly").Value)); // Init the Dictionary containing the line coverage information Parallel.ForEach( this.Assemblies(), (assembly) => { logger.DebugFormat(" Current Assembly: {0}", assembly); Parallel.ForEach( this.ClassesInAssembly(assembly), (clazz) => { Parallel.ForEach( this.FilesOfClass(assembly, clazz), (file) => { var seqpntsOfFile = report.Descendants("module") .Where(type => type.Attribute("assembly").Value.Equals(assembly)) .Elements("method").Where(method => method.Attribute("class").Value.StartsWith(clazz, StringComparison.Ordinal)) .Descendants("seqpnt") .Where(seqpnt => seqpnt.Attribute("document").Value.Equals(file) && seqpnt.Attribute("line").Value != "16707566") .OrderBy(seqpnt => int.Parse(seqpnt.Attribute("line").Value, CultureInfo.InvariantCulture)) .ToArray(); if (seqpntsOfFile.Length > 0) { var coverage = new int[int.Parse(seqpntsOfFile.Last().Attribute("line").Value, CultureInfo.InvariantCulture) + 1]; for (int i = 0; i < coverage.Length; i++) { coverage[i] = -1; } foreach (var seqpnt in seqpntsOfFile) { var index = int.Parse(seqpnt.Attribute("line").Value, CultureInfo.InvariantCulture); var value = int.Parse(seqpnt.Attribute("visitcount").Value, CultureInfo.InvariantCulture); coverage[index] = coverage[index] == -1 ? value : coverage[index] + value; } this.LineCoverageByFileDictionary.TryAdd(assembly + "_" + clazz + "_" + file, coverage); } }); }); }); }
public static bool TryParse(XContainer xml, out GoodreadsBook result) { result = null; var bookNode = (xml is XElement && (xml as XElement).Name == "best_book") ? xml as XElement : xml.Descendants("best_book").FirstOrDefault(); var idNode = (bookNode.Element("id")?.FirstNode as XText)?.Value; var titleNode = bookNode.Element("title"); var authorNode = bookNode.Element("author"); var title = titleNode?.Value; if (string.IsNullOrEmpty(title)) { return false; } int id; if (idNode == null || !int.TryParse(idNode, out id)) { id = int.MinValue; } GoodreadsAuthor author; if (authorNode == null || !GoodreadsAuthor.TryParse(authorNode, out author)) { result = new GoodreadsBook(id, title); } else { result = new GoodreadsBook(id, title, author); } return true; }
public static IEnumerable<UserSettings> DeserializeAll(XContainer container) { if (container == null) throw new ArgumentNullException("xml"); return from x in container.Descendants("UserSettings") select Deserialize(x); }
public static void SetStaticProfiles(XContainer transform, XContainer presentation) { string baseUri = "http://www.w3.org/ns/ttml/feature"; var features = from f in transform.Descendants("{http://www.w3.org/ns/ttml#parameter}feature") select new FeatureValue { Required = f.Attribute("value").Value == "required", Label = f.Value }; m_transformProfile.Clear(); foreach (var f in features) { m_transformProfile.Add(baseUri + f.Label, f.Required); } features = from f in presentation.Descendants("{http://www.w3.org/ns/ttml#parameter}feature") select new FeatureValue { Required = f.Attribute("value").Value == "required", Label = f.Value }; m_presentationProfile.Clear(); foreach (var f in features) { m_presentationProfile.Add(baseUri + f.Label, f.Required); } }
private List<ValidationIssue> ParseIssues(XContainer document, string rootName, string listName, string tagName, Severity severity) { var elements = from e in document.Descendants(_namespace + rootName) select e; var issues = new List<ValidationIssue>(); foreach (var element in elements) { foreach (var list in element.Descendants(_namespace + listName)) { foreach (var errorElement in list.Descendants(_namespace + tagName)) { var issue = new ValidationIssue { Severity = severity }; if (errorElement.Descendants(_namespace + "line").Any()) issue.Row = int.Parse(errorElement.Descendants(_namespace + "line").First().Value); if (errorElement.Descendants(_namespace + "col").Any()) issue.Column = int.Parse(errorElement.Descendants(_namespace + "col").First().Value); if (errorElement.Descendants(_namespace + "message").Any()) { issue.Title = errorElement.Descendants(_namespace + "message").First().Value; issue.MessageId = Encoding.UTF8.GetString(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(issue.Title))); } issues.Add(issue); } } } return issues; }
private void InitRssItems(XContainer doc) { var items = doc.Descendants(@"item"); foreach (var item in items) { var title = item.Element("title"); var date = item.Element("pubDate"); var link = item.Element("link"); if (title == null) { throw new XmlException("Xml schema has changed: missing '//item/title' node"); } if (date == null) { throw new XmlException("Xml schema has changed: missing '//item/pubDate' node"); } if (link == null) { throw new XmlException("Xml schema has changed: missing '//item/link' node"); } _rssVm.Items.Add(new RssItemVm(title.Value, ParseTime(date), link.Value)); } }
private void ParseDimensions(XContainer xReader) { IEnumerable<XElement> dimensions = xReader.Descendants("Dimensions").Elements(); Dictionary<string, int> mapDimensionsDictionary = new Dictionary<string, int>(); foreach (XElement e in dimensions) { string elementName = e.Name.ToString(); int elementValue; if (int.TryParse(e.Value, out elementValue)) mapDimensionsDictionary[elementName] = elementValue; else throw new FormatException("The map file could not be read because its " + elementName.ToLower() + " is not an integer."); } if (mapDimensionsDictionary.ContainsKey("Width")) mapDimensions.Width = mapDimensionsDictionary["Width"]; else throw new KeyNotFoundException("The map file could not be read because the map's width was not found."); if (mapDimensionsDictionary.ContainsKey("Height")) mapDimensions.Height = mapDimensionsDictionary["Height"]; else throw new KeyNotFoundException("The map file could not be read because the map's height was not found."); if (mapDimensionsDictionary.ContainsKey("TileSize")) mapDimensions.TileSize = mapDimensionsDictionary["TileSize"]; else throw new KeyNotFoundException("The map file could not be read because the map's tile size was not found."); if (mapDimensionsDictionary.ContainsKey("LayerCount")) mapDimensions.LayerCount = mapDimensionsDictionary["LayerCount"]; else throw new KeyNotFoundException("The map file could not be read because the map's layer count was not found."); }
public static IEnumerable<ClientVersion> DeserializeAll(XContainer container) { if (container == null) throw new ArgumentNullException("container"); return from x in container.Descendants("ClientVersion") select Deserialize(x); }
public AccessControlList(XContainer document, IAclSetup ownerObject) { _ownerObject = ownerObject; var element = document.Descendants("Owner").FirstOrDefault(); if (element != null) { Owner = new SharpGs.Internal.Owner(null) { ID = element.Descendants("ID").Select(e => e.Value).FirstOrDefault(), DisplayName = element.Descendants("Name").Select(e => e.Value).FirstOrDefault() }; } foreach (var aclEntry in document.Descendants("Entry")) _entries.Add(new AclEntry(aclEntry)); }
private static dynamic GetSubmission(XContainer doc) { return (from element in doc.Descendants(Namespaces.XForms + "submission") let resource = element.Attribute("resource") where resource != null select new {Element = element, TargetUri = resource.Value}).FirstOrDefault(); }
//todo: this can become private when we remove the template rule public static ImmutableList<RuleParameterValues> ParseParameters(XContainer xml) { var builder = ImmutableList.CreateBuilder<RuleParameterValues>(); foreach (var rule in xml.Descendants("Rule").Where(e => e.Elements("Parameters").Any())) { var analyzerId = rule.Elements("Key").Single().Value; var parameterValues = rule .Elements("Parameters").Single() .Elements("Parameter") .Select(e => new RuleParameterValue { ParameterKey = e.Elements("Key").Single().Value, ParameterValue = e.Elements("Value").Single().Value }); var pvs = new RuleParameterValues { RuleId = analyzerId }; pvs.ParameterValues.AddRange(parameterValues); builder.Add(pvs); } return builder.ToImmutable(); }
/// <exclude /> public static void Parse(XContainer container) { IEnumerable<XElement> elements = container.Descendants().ToList(); foreach (XElement element in elements) { if (element.Name.Namespace == LocalizationXmlConstants.XmlNamespace) { if (element.Name.LocalName == "string") { HandleStringElement(element); } else if (element.Name.LocalName == "switch") { HandleSwitchElement(element); } } IEnumerable<XAttribute> attributes = element.Attributes().ToList(); foreach (XAttribute attribute in attributes) { Match match = _attributRegex.Match(attribute.Value); if ((match.Success) && (match.Groups["type"].Value == "lang")) { string newValue = StringResourceSystemFacade.ParseString(string.Format("${{{0}}}", match.Groups["id"].Value)); attribute.SetValue(newValue); } } } }
private static string GetFormContents(XContainer doc) { var formContents = (from instance in doc.Descendants(Namespaces.XForms + "instance") let contents = instance.Elements().FirstOrDefault() select contents != null ? contents.ToString(SaveOptions.DisableFormatting) : string.Empty).FirstOrDefault(); return formContents ?? string.Empty; }
public static void FixBadTextElementsInXContainer(XContainer parentElement) { foreach (var misnamedElement in parentElement.Descendants("element")) { misnamedElement.Name = "text"; misnamedElement.Attribute("name").Remove(); } }
public static IEnumerable<CoverageResult> GetStatistics(XContainer xdoc, string source) { var allPoints = xdoc.Descendants("seqpnt"); var statistics = allPoints.Where(s => Path.GetFullPath(s.Attributes("document").FirstOrDefault().Value).ToLower() == source.ToLower()); return TransformToCoverageResults(statistics); }
public Configuration(XContainer xml) { var settings = xml .Descendants("Setting") .Select(e => { var keyElement = e.Element("Key"); var valueElement = e.Element("Value"); if (valueElement != null && keyElement != null) { return new { Key = keyElement.Value, Value = valueElement.Value }; } return null; }) .Where(e => e != null) .ToImmutableDictionary(e => e.Key, e => e.Value); IgnoreHeaderComments = "true".Equals(settings["sonar.cs.ignoreHeaderComments"]); Files = xml.Descendants("File").Select(e => e.Value).ToImmutableList(); AnalyzerIds = xml.Descendants("Rule").Select(e => e.Elements("Key").Single().Value).ToImmutableHashSet(); var builder = ImmutableDictionary.CreateBuilder<string, List<IImmutableDictionary<string, string>>>(); foreach (var rule in xml.Descendants("Rule").Where(e => e.Elements("Parameters").Any())) { var analyzerId = rule.Elements("Key").Single().Value; var parameters = rule .Elements("Parameters").Single() .Elements("Parameter") .ToImmutableDictionary(e => e.Elements("Key").Single().Value, e => e.Elements("Value").Single().Value); if (!builder.ContainsKey(analyzerId)) { builder.Add(analyzerId, new List<IImmutableDictionary<string, string>>()); } builder[analyzerId].Add(parameters); } Parameters = builder.ToImmutable(); }
public static IEnumerable<CoverageResult> GetStatistics(XContainer document, string source) { XElement doc = document.Descendants("doc").Where( d => Path.GetFullPath(d.Attributes("url").FirstOrDefault().Value).ToLower() == Path.GetFullPath(source).ToLower()). FirstOrDefault(); if(doc == null) return new List<CoverageResult>(); string docid = doc.Attributes("id").FirstOrDefault().Value; IEnumerable<XElement> statistics = document.Descendants("seqpnt").Where(s => { string docAttributeId = s.Attributes("doc").FirstOrDefault().Value; return docAttributeId == docid; }); return TransformToCoverageResults(statistics); }
private static DateTime GetEndDate(XContainer node) { var endDate = new DateTime(2015, 12, 31); if (node.Descendants("end-date").Any()) { endDate = DateTime.Parse(node.Descendants("end-date").Single().Value); } return endDate; }
public JenkinsBuildInformation(XContainer document) { var firstElement = document.Descendants().First<XElement>(); Timestamp = Epoch.AddMilliseconds((long) firstElement.Element("timestamp")); Number = (string) firstElement.Element("number"); Duration = (int) firstElement.Element("duration"); EstimatedDuration = (int) firstElement.Element("estimatedDuration"); FullDisplayName = (string) firstElement.Element("fullDisplayName"); Id = (string) firstElement.Element("id"); Building = (bool) firstElement.Element("building"); }
private RunInfo CreateRunInfo(XContainer doc, Report report) { // run-info & environment values -> RunInfo var runInfo = new RunInfo { TestRunner = report.TestRunner }; runInfo.Info.Add("TestRunner Version", ""); runInfo.Info.Add("File", report.FileName); runInfo.Info.Add("Machine Name", doc.Descendants(_xns + "UnitTestResult").First().Attribute("computerName").Value); return runInfo; }
/// <summary> /// Initializes a new instance of the <see cref="VisualStudioParser"/> class. /// </summary> /// <param name="report">The report file as XContainer.</param> internal VisualStudioParser(XContainer report) { if (report == null) { throw new ArgumentNullException("report"); } this.modules = report.Descendants("Module").ToArray(); this.files = report.Descendants("SourceFileNames").ToArray(); var assemblyNames = this.modules .Select(m => m.Element("ModuleName").Value) .Distinct() .OrderBy(a => a) .ToArray(); Parallel.ForEach(assemblyNames, assemblyName => this.AddAssembly(this.ProcessAssembly(assemblyName))); this.modules = null; this.files = null; }
public static string GetXmlContent(XContainer xml) { var sb = new StringBuilder(); foreach (var node in xml.Descendants()) { if (!node.HasElements) sb.AppendLine(node.Value); } return sb.ToString(); }
private void LoadFile( XContainer file, byte[] data, ADDR start ) { // Grab all the <Pattern /> elements from the XML. IEnumerable<XElement> pats = from p in file.Descendants( "Pattern" ) select p; // Each Pattern element needs to be handled seperately. // The enumeration we're goinv over, is in document order, so attributes such as 'start' // should work perfectly fine. foreach( XElement pat in pats ) { ADDR tmpStart = 0; string name = pat.Attribute( "desc" ).Value; string mask = pat.Attribute( "mask" ).Value; byte[] patternBytes = GetBytesFromPattern( pat.Attribute( "pattern" ).Value ); // Make sure we're not getting some sort of screwy XML data. if( mask.Length != patternBytes.Length ) throw new Exception( "Pattern and mask lengths do not match!" ); // If we run into a 'start' attribute, we need to remember that we're working from a 0 // based 'memory pool'. So we just remove the 'start' from the address we found earlier. if( pat.Attribute( "start" ) != null ) tmpStart = (ADDR)( this[ pat.Attribute( "start" ).Value ].ToInt32() - start + 1 ); // Actually search for the pattern match... ADDR found = Find( data, mask, patternBytes, tmpStart ); if( found == 0 ) throw new Exception( "FindPattern failed... figure it out ****tard!" ); // Handle specific child elements for the pattern. // <Lea> <Rel> <Add> <Sub> etc foreach( XElement e in pat.Elements() ) { switch( e.Name.LocalName ) { case "Lea": found = BitConverter.ToUInt32( data, (int)found ); break; case "Rel": int instructionSize = int.Parse( e.Attribute( "size" ).Value, NumberStyles.HexNumber ); int operandOffset = int.Parse( e.Attribute( "offset" ).Value, NumberStyles.HexNumber ); found = (ADDR)( BitConverter.ToUInt32( data, (int)found ) + found + instructionSize - operandOffset ); break; case "Add": found += ADDR.Parse( e.Attribute( "value" ).Value, NumberStyles.HexNumber ); break; case "Sub": found -= ADDR.Parse( e.Attribute( "value" ).Value, NumberStyles.HexNumber ); break; } } mPatterns.Add( name, (IntPtr)( found + start ) ); } }
protected void ValidateTagsRemoved(XContainer document) { Assert.IsFalse( document.Descendants(WordMl.SdtName) .Any( element => !element.Element(WordMl.SdtPrName) .Element(WordMl.TagName) .Attribute(WordMl.ValAttributeName) .Value.ToLower() .Equals("dynamiccontent"))); }
/// <summary> /// Initializes a new instance of the <see cref="DotCoverParser"/> class. /// </summary> /// <param name="report">The report file as XContainer.</param> internal DotCoverParser(XContainer report) { if (report == null) { throw new ArgumentNullException(nameof(report)); } this.modules = report.Descendants("Assembly") .ToArray(); this.files = report.Descendants("File").ToArray(); var assemblyNames = this.modules .Select(m => m.Attribute("Name").Value) .Distinct() .OrderBy(a => a) .ToArray(); Parallel.ForEach(assemblyNames, assemblyName => this.AddAssembly(this.ProcessAssembly(assemblyName))); this.modules = null; this.files = null; }
/// <summary> /// Initializes a new instance of the <see cref="DynamicCodeCoverageParser"/> class. /// </summary> /// <param name="report">The report file as XContainer.</param> internal DynamicCodeCoverageParser(XContainer report) { if (report == null) { throw new ArgumentNullException(nameof(report)); } var modules = report.Descendants("module") .OrderBy(m => m.Attribute("name").Value) .ToArray(); Parallel.ForEach(modules, assembly => this.AddAssembly(ProcessAssembly(assembly))); }