public void Write(Instance instance)
        {
            var entries = new Dictionary <string, string>();

            var inlineXbrlWriter = new InlineXbrlWriter(_template, _settings);

            instance.Save(inlineXbrlWriter);
            entries[_settings.InlineXbrlFileName] = inlineXbrlWriter.Document.ToString();

            foreach (var taxonomy in instance.Dts.Taxonomies)
            {
                if (taxonomy.EntryPointUri.IsAbsoluteUri)
                {
                    // No need to include taxonomies with absolute entry points in the archive.
                    continue;
                }

                var taxonomyWriter = new ZipArchiveWriter();
                taxonomy.Save(taxonomyWriter);
                var taxonmyEntries = ZipArchiveHelper.ExtractEntries(taxonomyWriter.ZipArchiveBytes);
                foreach (var taxonmyEntry in taxonmyEntries)
                {
                    entries[taxonmyEntry.Key] = taxonmyEntry.Value;
                }
            }

            ZipArchiveBytes = ZipArchiveHelper.CreateFromEntries(entries);
        }
示例#2
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);
        }
示例#3
0
        public void WriteExtensionTaxonomy()
        {
            // 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);

            var extensionTaxonomy = dts.AddTaxonomy(new Uri("banan-20180710.xsd", UriKind.Relative), extension);

            // Act
            var writer = new ZipArchiveWriter();

            extensionTaxonomy.Save(writer);

            // Assert
            File.WriteAllBytes(@"C:\temp\banan-20180710.zip", writer.ZipArchiveBytes);
        }
示例#4
0
        protected virtual void _Transform(string inputFile, string outputFile, ConversionOptions options)
        {
            // this throws an exception in the the following cases:
            // - input file is not a valid file
            // - input file is an encrypted file
            CheckFile(inputFile);

            XmlReader   source      = null;
            XmlWriter   writer      = null;
            ZipResolver zipResolver = null;

            string currentDirectory = Environment.CurrentDirectory;

            try
            {
                XslCompiledTransform xslt = this.Load(outputFile == null);
                zipResolver = new ZipResolver(inputFile);
                XsltArgumentList parameters = new XsltArgumentList();
                parameters.XsltMessageEncountered += new XsltMessageEncounteredEventHandler(MessageCallBack);

                if (options != null)
                {
                    // set working directory to the input document's path
                    // that way we can resolve references to relative links into the file system easily
                    Environment.CurrentDirectory = options.InputBaseFolder;

                    parameters.AddParam("documentType", "", options.DocumentType.ToString());
                    parameters.AddParam("generator", "", options.Generator);
                }
                else
                {
                    parameters.AddParam("generator", "", "OpenXML/ODF Translator");
                }

                if (outputFile != null)
                {
                    parameters.AddParam("outputFile", "", outputFile);

                    XmlWriter finalWriter;
                    if (this.packaging)
                    {
                        finalWriter = new ZipArchiveWriter(zipResolver, outputFile);
                    }
                    else
                    {
                        finalWriter = new XmlTextWriter(outputFile, System.Text.Encoding.UTF8);
                    }
                    writer = GetWriter(finalWriter);
                }
                else
                {
                    writer = new XmlTextWriter(new StringWriter());
                }

                source = this.Source(inputFile);
                // Apply the transformation

                xslt.Transform(source, parameters, writer, zipResolver);
            }
            finally
            {
                // restore working folder
                Environment.CurrentDirectory = currentDirectory;

                if (writer != null)
                {
                    writer.Close();
                }
                if (source != null)
                {
                    source.Close();
                }
                if (zipResolver != null)
                {
                    zipResolver.Dispose();
                }
            }
        }