private void AddExtensionTaxonomy(DiscoverableTaxonomySet dts)
        {
            XNamespace bSharpNamespace = "http://banan-it.com/taxonomy/2018-07-05/bsharp";
            XNamespace ifrsNamespace   = "http://xbrl.ifrs.org/taxonomy/2017-03-09/ifrs-full";

            var extension = new TaxonomyExtension("banan", bSharpNamespace);

            var concept1 = new ExtensionConcept("ComputerEquipment", DataTypeRegistry.Monetary, BalanceTypes.Debit, PeriodTypes.Instant);

            concept1.AddLabel("Computer equipment", "en");
            concept1.AddLocation(new Uri("http://xbrl.ifrs.org/role/ifrs/ias_1_2017-03-09_role-800100"), ifrsNamespace + "PropertyPlantAndEquipmentAbstract", ifrsNamespace + "OfficeEquipment");
            extension.ExtensionItems.Add(concept1);

            var member1 = new ExtensionMember("BestPaintMember");

            member1.AddLabel("Best Paint", "en");
            member1.AddLocation(
                ifrsNamespace + "DisclosureOfOperatingSegmentsTable", ifrsNamespace + "SegmentsAxis",
                ifrsNamespace + "ReportableSegmentsMember", null);
            extension.ExtensionItems.Add(member1);

            var member2 = new ExtensionMember("BestPlasticMember");

            member2.AddLabel("Best Plastic", "en");
            member2.AddLocation(
                ifrsNamespace + "DisclosureOfOperatingSegmentsTable", ifrsNamespace + "SegmentsAxis",
                ifrsNamespace + "ReportableSegmentsMember", bSharpNamespace + "BestPaintMember");
            extension.ExtensionItems.Add(member2);

            dts.AddTaxonomy(new Uri("banan-20180710.xsd", UriKind.Relative), extension);
        }
        private Linkbase CreateLabelLinkbase(Taxonomy taxonomy, DiscoverableTaxonomySet dts)
        {
            var linkbase = new Linkbase(GetLinkbaseFileName(taxonomy, "lab"));

            var labelLink = new LabelLink(LinkbaseXNames.Label, LinkRoles.Generic);

            linkbase.AddLink(labelLink, dts);

            var locCount = 0;
            var labCount = 0;

            foreach (var extensionItem in ExtensionItems)
            {
                var locLabel = $"loc{locCount}";
                locCount += 1;
                var locNode = CreateLocatorNode(locLabel, extensionItem, dts);
                labelLink.AddNode(locNode);

                foreach (var extensionLabel in extensionItem.Labels)
                {
                    var labLabel = $"lab{labCount}";
                    labCount += 1;
                    var labNode = new LabelNode(labLabel, extensionLabel.Role, extensionLabel.Text, extensionLabel.Language);
                    labelLink.AddNode(labNode);

                    var arc = new LabelArc(locNode, labNode);
                    labelLink.AddArc(arc);
                }
            }

            return(linkbase);
        }
Exemple #3
0
        public void AddFromExtension()
        {
            // Arrange
            var zipArchive     = ZipFile.Open(@"Samples\IFRST_2017-03-09.zip", ZipArchiveMode.Read);
            var fileReader     = new ZipArchiveReader(zipArchive);
            var taxonomySource = new TaxonomyFileSet(fileReader);

            var dts          = new DiscoverableTaxonomySet();
            var baseTaxonomy = dts.AddTaxonomy(new Uri("http://xbrl.ifrs.org/taxonomy/2017-03-09/full_ifrs_entry_point_2017-03-09.xsd"), taxonomySource);

            XNamespace bSharpNamespace = "http://banan-it.com/taxonomy/2018-07-05/bsharp";
            XNamespace ifrsNamespace   = "http://xbrl.ifrs.org/taxonomy/2017-03-09/ifrs-full";

            var extension = new TaxonomyExtension("banan", bSharpNamespace);

            var concept1 = new ExtensionConcept("ComputerEquipment", DataTypeRegistry.Monetary, BalanceTypes.Debit, PeriodTypes.Instant);

            concept1.AddLabel("Computer equipment", "en");
            concept1.AddLocation(new Uri("http://xbrl.ifrs.org/role/ifrs/ias_1_2017-03-09_role-800100"), ifrsNamespace + "PropertyPlantAndEquipmentAbstract", ifrsNamespace + "OfficeEquipment");
            extension.ExtensionItems.Add(concept1);

            var member1 = new ExtensionMember("BestPaintMember");

            member1.AddLabel("Best Paint", "en");
            member1.AddLocation(
                ifrsNamespace + "DisclosureOfOperatingSegmentsTable", ifrsNamespace + "SegmentsAxis",
                ifrsNamespace + "ReportableSegmentsMember", null);
            extension.ExtensionItems.Add(member1);

            // Act
            var extensionTaxonomy = dts.AddTaxonomy(new Uri("banan-20180710.xsd", UriKind.Relative), extension);
        }
        public void Fill(Taxonomy taxonomy, DiscoverableTaxonomySet dts)
        {
            var taxonomyDagProcessor = new TaxonomyDagProcessor(dts, _fileReader);

            var entryFileName = new Uri(taxonomy.EntryPointUri.Segments.Last(), UriKind.Relative);

            taxonomyDagProcessor.Process(entryFileName, taxonomy);
        }
Exemple #5
0
        public Instance()
        {
            Dts = new DiscoverableTaxonomySet();

            Entities = new List <Entity>();
            Periods  = new List <Period>();
            Units    = new List <Unit>();
            Facts    = new List <Fact>();
        }
Exemple #6
0
        public void AddFromFileSet()
        {
            // Arrange
            var zipArchive     = ZipFile.Open(@"Samples\IFRST_2017-03-09.zip", ZipArchiveMode.Read);
            var fileReader     = new ZipArchiveReader(zipArchive);
            var taxonomySource = new TaxonomyFileSet(fileReader);

            // Act
            var dts      = new DiscoverableTaxonomySet();
            var taxonomy = dts.AddTaxonomy(new Uri("http://xbrl.ifrs.org/taxonomy/2017-03-09/full_ifrs_entry_point_2017-03-09.xsd"), taxonomySource);
        }
Exemple #7
0
        public void WriteBaseTaxonomy()
        {
            // Arrange
            var zipArchive     = ZipFile.Open(@"Samples\IFRST_2017-03-09.zip", ZipArchiveMode.Read);
            var fileReader     = new ZipArchiveReader(zipArchive);
            var taxonomySource = new TaxonomyFileSet(fileReader);

            var dts          = new DiscoverableTaxonomySet();
            var baseTaxonomy = dts.AddTaxonomy(new Uri("http://xbrl.ifrs.org/taxonomy/2017-03-09/full_ifrs_entry_point_2017-03-09.xsd"), taxonomySource);

            // Act
            var writer = new ZipArchiveWriter();

            baseTaxonomy.Save(writer);

            // Assert
            File.WriteAllBytes(@"C:\temp\IFRST_2017-03-09-exported.zip", writer.ZipArchiveBytes);
        }
        internal void EnsureConsistentPeriodTypes(DiscoverableTaxonomySet dts)
        {
            var periodAspect   = Aspects.OfType <PeriodAspect>().Single();
            var factPeriodType = periodAspect.Period.PeriodType;

            var conceptAspect = Aspects.OfType <ConceptAspect>().Single();
            var concept       = dts.FindItem(conceptAspect.ConceptName);

            if (concept == null)
            {
                throw new InvalidOperationException($"The concept {conceptAspect.ConceptName} does not exist in the DTS. If this is a custom concept, then it needs to be defined in an extension taxonomy that is added to the DTS.");
            }

            var conceptPeriodType = concept.PeriodType;

            if (factPeriodType != conceptPeriodType)
            {
                throw new InvalidOperationException($"The fact for the concept {concept.Name} has period type {factPeriodType} but should be {conceptPeriodType}.");
            }
        }
        public void Fill(Taxonomy taxonomy, DiscoverableTaxonomySet dts)
        {
            if (taxonomy.EntryPointUri.IsAbsoluteUri)
            {
                throw new ArgumentException("The entry point for an extension taxonomy must be relative.");
            }

            var schema = CreateSchema(taxonomy.EntryPointUri);

            taxonomy.SetEntryPoint(schema);

            var labelLinkbase = CreateLabelLinkbase(taxonomy, dts);

            schema.Add(labelLinkbase);

            var presentationLinkbase = CreatePresentationLinkbase(taxonomy, dts);

            schema.Add(presentationLinkbase);

            var definitionLinkbase = CreateDefinitionLinkbase(taxonomy, dts);

            schema.Add(definitionLinkbase);
        }
 public TaxonomyDagProcessor(DiscoverableTaxonomySet dts, IFileReader fileReader)
 {
     _dts            = dts;
     _fileReader     = fileReader;
     _processedFiles = new Dictionary <Uri, TaxonomyFile>();
 }
        private Linkbase CreateDefinitionLinkbase(Taxonomy taxonomy, DiscoverableTaxonomySet dts)
        {
            var linkbase = new Linkbase(GetLinkbaseFileName(taxonomy, "def"));

            var memberItems = ExtensionItems.OfType <ExtensionMember>().ToList();

            var groupedByHypercube = memberItems.SelectMany(i => i.Locations.Select(l =>
                                                                                    new { l.HypercubeName, Location = l, Item = i }))
                                     .GroupBy(d => d.HypercubeName)
                                     .ToList();

            foreach (var groupByHypercube in groupedByHypercube)
            {
                var hypercubeNode = dts.GetAllLinks()
                                    .Where(l => l.ElementName == LinkbaseXNames.Definition)
                                    .SelectMany(l => l.NodesMap.Values)
                                    .OfType <LocatorNode>()
                                    .SingleOrDefault(ln => ln.Item.Name == groupByHypercube.Key);
                if (hypercubeNode == null)
                {
                    throw new InvalidOperationException($"Could not find a hypercube (aka table) {groupByHypercube.Key} in the DTS.");
                }

                var definitionLink = new DefinitionLink(LinkbaseXNames.Definition, hypercubeNode.Link.Role);
                linkbase.AddLink(definitionLink, dts);

                var locCount = 0;
                foreach (var locationAndItem in groupByHypercube)
                {
                    var dimensionLocationNode = hypercubeNode.FromArcs
                                                .OfType <DefinitionArc>()
                                                .Select(da => da.ToLocator)
                                                .SingleOrDefault(ln => ln.Item.Name == locationAndItem.Location.DimensionName);

                    if (dimensionLocationNode == null)
                    {
                        throw new InvalidOperationException($"Could not find a dimension (aka axis) {locationAndItem.Location.DimensionName} in the hypercube (aka table) {groupByHypercube.Key}.");
                    }

                    var parentNodeInBaseTaxonomy = FindParentNode(dimensionLocationNode, locationAndItem.Location.ParentName);
                    if (parentNodeInBaseTaxonomy == null)
                    {
                        throw new InvalidOperationException($"There is no member {locationAndItem.Location.ParentName} in the dimension {groupByHypercube.Key}.");
                    }

                    var siblingArcs = parentNodeInBaseTaxonomy.GetOrderedOutgoingHierarchicalArcs <DefinitionArc>();

                    double newOrder;
                    try
                    {
                        newOrder = DetermineOrder(locationAndItem.Location.PrecedingSiblingName, siblingArcs);
                    }
                    catch (InvalidOperationException ex)
                    {
                        throw new InvalidOperationException($"The sibling {locationAndItem.Location.PrecedingSiblingName} was not found as a child of {locationAndItem.Location.ParentName} in the dimension {groupByHypercube.Key}.", ex);
                    }

                    var parentLocLabel = $"loc_{locCount}";
                    locCount += 1;
                    var parentNode = new LocatorNode(parentLocLabel, parentNodeInBaseTaxonomy.Item);
                    definitionLink.AddNode(parentNode);

                    var locLabel = $"loc_{locCount}";
                    locCount += 1;
                    var locNode = CreateLocatorNode(locLabel, locationAndItem.Item, dts);
                    definitionLink.AddNode(locNode);

                    var arc = new DefinitionArc(parentNode, locNode, newOrder);
                    definitionLink.AddArc(arc);
                }
            }

            return(linkbase);
        }
        private LocatorNode CreateLocatorNode(string label, ExtensionItem extensionItem, DiscoverableTaxonomySet dts)
        {
            var itemName = (XNamespace)_targetNamespaceDeclaration.Value + extensionItem.Name;
            var item     = dts.FindItem(itemName);

            if (item == null)
            {
                throw new InvalidOperationException($"There is no item called {itemName} in the DTS. Perhaps you added taxonomies in the wrong order or forgot to add a base taxonomy.");
            }
            return(new LocatorNode(label, item));
        }
        private Linkbase CreatePresentationLinkbase(Taxonomy taxonomy, DiscoverableTaxonomySet dts)
        {
            var conceptItems = ExtensionItems.OfType <ExtensionConcept>().ToList(); // Does that include abstracts?

            var linkbase = new Linkbase(GetLinkbaseFileName(taxonomy, "pre"));

            var groupedByNetworkRole = conceptItems.SelectMany(i => i.Locations.Select(l =>
                                                                                       new { l.NetworkRole, Location = l, Item = i }))
                                       .GroupBy(d => d.NetworkRole)
                                       .ToList();

            foreach (var groupByNetworkRole in groupedByNetworkRole)
            {
                var presentationLink = new PresentationLink(LinkbaseXNames.Presentation, groupByNetworkRole.Key);
                linkbase.AddLink(presentationLink, dts);

                var locCount = 0;
                foreach (var locationAndItem in groupByNetworkRole)
                {
                    var parentItem = dts.FindItem(locationAndItem.Location.ParentName);
                    if (parentItem == null)
                    {
                        throw new InvalidOperationException($"There is no concept {locationAndItem.Location.ParentName} in the DTS.");
                    }

                    var parentLocatorNodes = parentItem.Nodes
                                             .Where(n => n.Link.Role == groupByNetworkRole.Key).ToList();
                    if (!parentLocatorNodes.Any())
                    {
                        throw new InvalidOperationException($"The concept {locationAndItem.Location.ParentName} is not in the presentation network {groupByNetworkRole.Key}.");
                    }

                    var siblingArcs = parentLocatorNodes.First().GetOrderedOutgoingHierarchicalArcs <PresentationArc>();

                    double newOrder;
                    try
                    {
                        newOrder = DetermineOrder(locationAndItem.Location.PrecedingSiblingName, siblingArcs);
                    }
                    catch (InvalidOperationException ex)
                    {
                        throw new InvalidOperationException($"The sibling {locationAndItem.Location.PrecedingSiblingName} was not found as a child of {locationAndItem.Location.ParentName} in the presentation network {groupByNetworkRole.Key}.", ex);
                    }

                    var parentLocLabel = $"loc_{locCount}";
                    locCount += 1;
                    var parentNode = new LocatorNode(parentLocLabel, parentItem);
                    presentationLink.AddNode(parentNode);

                    var childLocLabel = $"loc_{locCount}";
                    locCount += 1;
                    var childNode = CreateLocatorNode(childLocLabel, locationAndItem.Item, dts);
                    presentationLink.AddNode(childNode);

                    var arc = new PresentationArc(parentNode, childNode, newOrder, locationAndItem.Location.PreferredLabelRole);
                    presentationLink.AddArc(arc);
                }
            }

            return(linkbase);
        }