internal void GetUsedFactDomainNamespaces(List <string> used, FactCollection Facts) { var factNamespaces = new HashSet <string>(); foreach (var fact in Facts.Where(f => !string.IsNullOrEmpty(f.Value) || f.Facts.Count > 0)) { if (fact.Value.Contains(':')) { var prefix = fact.Value.Split(':')[0]; var ns = Namespaces.LookupNamespace(prefix); if (ns != null) { factNamespaces.Add(ns); } } else { var prefix = fact.Metric.Name.Split(':')[0]; var ns = Namespaces.LookupNamespace(prefix); if (ns != null) { factNamespaces.Add(ns); } GetUsedFactDomainNamespaces(used, fact.Facts); } } used.AddRange(factNamespaces); }
public static void ParseFacts(XDocument report, Instance instance) { var factElements = FindFacts(report); var facts = new FactCollection(instance); foreach (var factElement in factElements) { var name = factElement.Attribute("name").Value; var prefix = name.Split(':').First(); var ns = report.Root.GetNamespaceOfPrefix(prefix).ToString(); var unitRef = factElement.Attribute("unitRef")?.Value; var decimals = factElement.Attribute("decimals")?.Value; var value = factElement.Value; var scale = factElement.Attribute("scale")?.Value; if (!string.IsNullOrWhiteSpace(scale)) { var power = int.Parse(scale); var v = decimal.Parse(value.Replace(" ", "")); var multiplier = (decimal)Math.Pow(10, power); v *= multiplier; value = v.ToString(); } var contextRef = factElement.Attribute("contextRef").Value; var fact = new Fact(name, ns, unitRef, decimals, contextRef, value); facts.Add(fact); } foreach (var fact in facts) { instance.Facts.Add(fact); } }
public Instance() { Namespaces = new XmlNamespaceManager(new NameTable()); AddDefaultNamespaces(); SchemaReference = new SchemaReference(); FilingIndicators = new FilingIndicatorCollection(); Units = new UnitCollection(this); Contexts = new ContextCollection(this); Facts = new FactCollection(this); Comments = new Collection <string>(); }
internal void GetUsedContexts(FactCollection Facts, HashSet <string> usedIds) { var facts = Facts.Where(f => f.Context != null || f.Facts.Count > 0); foreach (var fact in facts) { if (fact.Facts.Count == 0) { usedIds.Add(fact.Context.Id); } else { GetUsedContexts(fact.Facts, usedIds); } } }
internal void GetElementTree(FactCollection Facts, XmlElement[] value) { if (value != null) { foreach (var element in value) { var fact = Fact.FromXmlElement(element); Facts.Add(fact); if (element.InnerXml != element.InnerText) { GetElementTree(fact.Facts, element.ChildNodes.Cast <XmlElement>().ToArray <XmlElement>()); } } } }
public Fact(Context context, string metric, Unit unit, string decimals, string value, Uri namespaceUri, string prefix) { if (context == null) { throw new ArgumentNullException("context"); } if (namespaceUri == null) { throw new ArgumentNullException("namespaceUri"); } Facts = new FactCollection(null); Metric = new XmlQualifiedName(prefix + ":" + metric, namespaceUri.ToString()); Unit = unit; Decimals = decimals; Context = context; Value = value; }
void SetUnitReferences(FactCollection Facts) { foreach (var fact in Facts) { if (fact.Unit == null) { var unitRef = fact.UnitRef; if (!string.IsNullOrEmpty(unitRef)) { if (!Units.Contains(unitRef)) { throw new KeyNotFoundException(string.Format(ic, "Referenced unit '{0}' does not exist", unitRef)); } fact.Unit = Units[unitRef]; } } if (fact.Facts.Count > 0) { SetUnitReferences(fact.Facts); } } }
void SetContextReferences(FactCollection Facts) { foreach (var filingIndicator in FilingIndicators) { if (filingIndicator.Context == null) { var contextRef = filingIndicator.ContextRef; if (!string.IsNullOrEmpty(contextRef)) { if (!Contexts.Contains(contextRef)) { throw new KeyNotFoundException(string.Format(ic, "Referenced context '{0}' does not exist", contextRef)); } filingIndicator.Context = Contexts[contextRef]; } } } foreach (var fact in Facts) { if (fact.Context == null) { var contextRef = fact.ContextRef; if (!string.IsNullOrEmpty(contextRef)) { if (!Contexts.Contains(contextRef)) { throw new KeyNotFoundException(string.Format(ic, "Referenced context '{0}' does not exist", contextRef)); } fact.Context = Contexts[contextRef]; } } if (fact.Facts.Count > 0) { SetContextReferences(fact.Facts); } } }
public Fact() { Facts = new FactCollection(null); }