/// <summary>
        /// Defines the entry point of the application.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public static void Main(string[] args)
        {
            var fileWriter = new SdmxFileWriter();

            // create the IStructureFormat from a standard Sdmx StructureOutputFormat
            StructureOutputFormat soFormat = StructureOutputFormat.GetFromEnum(StructureOutputFormatEnumType.SdmxV21StructureDocument);
            IStructureFormat outputFormat = new SdmxStructureFormat(soFormat);

            // create the output file
            var outputStream = new FileStream("output/structures.xml", FileMode.Create);

            // write the the structures to the output file
            fileWriter.writeStructureToFile(outputFormat, outputStream);
        }
Ejemplo n.º 2
0
        public void SaveSDMXFile(ISdmxObjects sdmxObjects, StructureOutputFormatEnumType version, string outputFileName)
        {

            StructureWriterManager swm = new StructureWriterManager();

            StructureOutputFormat soFormat = StructureOutputFormat.GetFromEnum(version);
            IStructureFormat outputFormat = new SdmxStructureFormat(soFormat);

            MemoryStream memoryStream = new MemoryStream();

            swm.WriteStructures(sdmxObjects, outputFormat, memoryStream);


            byte[] bytesInStream = memoryStream.ToArray();
            memoryStream.Close();

            SendAttachment(bytesInStream, outputFileName + ".xml");
        }
        /// <summary>
        /// The main method.
        /// </summary>
        /// <param name="args">
        /// The parameter is not used.
        /// </param>
        public static void Main(string[] args)
        {
            // Steps 1 - 4 are performed in the new class DatabaseRetrievalManager, an implementation of the ISdmxObjectRetrievalManager interface.
            // DatabaseRetrievalManager: Step 1. Creating an implementation of  the ISdmxObjectRetrievalManager interface
            // DatabaseRetrievalManager: Step 2. Implementing ISdmxObjectRetrievalManager GetMaintainableObjects<> method.
            // DatabaseRetrievalManager: Step 3. Retrieving codelists from database. 
            // DatabaseRetrievalManager: Step 4. Retrieving Codes from the database.

            // Step 5. Create a ISdmxObjectRetrievalManager instance
            ISdmxObjectRetrievalManager retrievalManager = new DatabaseRetrievalManager();

            // Step 6. Create an IHeader  instance.
            // Create a new HeaderImpl instance with ID “IDREF0001”, Sender ID “ZZ9” 
            IHeader header = new HeaderImpl("IDREF001", "ZZ9"); // can be an instance or even a static field.

            // Step 7. Create the query
            IMaintainableRefObject query = new MaintainableRefObjectImpl("TEST_AGENCY", "TEST", "1.2");

            // Step 8. Get the codelist objects
            var codelistObjects = retrievalManager.GetMaintainableObjects<ICodelistObject>(query);

            // Step 9. Build the immutable object container.
            // Create an immutable container with the header and the codelist objects.
            // Note that immutable container can be modified.
            ISdmxObjects immutableObjects = new SdmxObjectsImpl(header, codelistObjects);

            // Step 10. Create an instance of the IStructureWriterManager.
            IStructureWriterManager structureWriterManager = new StructureWriterManager(); // can be an instance or even static field.

            // Step 11. Create a SdmxStructureFormat instance with StructureOutputFormat SdmxV21StructureDocument
            // SDMX v2.1. Create a SdmxStructureFormat instance with StructureOutputFormat SdmxV21StructureDocument. It can also be an instance or even a static field.
            IStructureFormat formatV21 = new SdmxStructureFormat(StructureOutputFormat.GetFromEnum(StructureOutputFormatEnumType.SdmxV21StructureDocument));

            // Step 12. Create a SdmxStructureFormat instance with StructureOutputFormat SdmxV2StructureDocument
            // SDMX v2.0. Create a SdmxStructureFormat instance with StructureOutputFormat SdmxV2StructureDocument. It can also be an instance or even a static field.
            IStructureFormat formatV20 = new SdmxStructureFormat(StructureOutputFormat.GetFromEnum(StructureOutputFormatEnumType.SdmxV2StructureDocument));


            // Step 13. Write to  the SDMX v2.1 structure file.
            using (Stream fileStream = File.Create(@"..\..\Exercise Output\outputv21.xml"))
            {
                // Write the objects in SDMX v2.1 format. Then flush the output.
                structureWriterManager.WriteStructures(immutableObjects, formatV21, fileStream);
                fileStream.Flush();
            }

            // Step 14. Write to  the SDMX v2.0 structure file. 
            using (Stream fileStream = File.Create(@"..\..\Exercise Output\outputv20.xml"))
            {
                // Write the objects in SDMX v2.0 format. Then flush the output.
                structureWriterManager.WriteStructures(immutableObjects, formatV20, fileStream);
                fileStream.Flush();
            }
        }
Ejemplo n.º 4
0
        private void SaveSdmxOBJ(ISdmxObjects SdmxOBJ, string FileName)
        {
            if (SdmxOBJ == null)
                return;

            StructureWriterManager swm = new StructureWriterManager();
            StructureOutputFormat sofType = StructureOutputFormat.GetFromEnum(StructureOutputFormatEnumType.SdmxV2RegistryQueryResponseDocument);
            SdmxStructureFormat sof = new SdmxStructureFormat(sofType);
            string FullNamePath = Path.Combine(Utils.GetTreeCachePath(), FileName);
            using (Stream ms = File.Create(FullNamePath))
            {
                swm.WriteStructures(SdmxOBJ, sof, ms);
            }
        }
        public void TestWriteStructuresV2DefaultObjectCount(string file)
        {
            ISdmxObjects objects;
            var fileInfo = new FileInfo(file);
            using (IReadableDataLocation location = new FileReadableDataLocation(fileInfo))
            {
                var structureWorkspace = this._parsingManager.ParseStructures(location);
                objects = structureWorkspace.GetStructureObjects(false);
            }

            StructureOutputFormat format = StructureOutputFormat.GetFromEnum(StructureOutputFormatEnumType.SdmxV2StructureDocument);
            var sdmxStructureFormat = new SdmxStructureFormat(format);
            var outputFileName = string.Format("{0}-output.xml", fileInfo.Name);
            using (var stream = File.Create(outputFileName))
            {
                var settings = new XmlWriterSettings { Indent = true };
                using (XmlWriter writer = XmlWriter.Create(stream, settings))
                {
                    IStructureWriterManager structureWritingManager = new StructureWriterManager(new SdmxStructureWriterFactory(writer));
                    structureWritingManager.WriteStructures(objects, sdmxStructureFormat, null);
                    writer.Flush();
                }
            }

            ISdmxObjects objects2;
            using (IReadableDataLocation location = new FileReadableDataLocation(outputFileName))
            {
                var structureWorkspace = this._parsingManager.ParseStructures(location);
                objects2 = structureWorkspace.GetStructureObjects(false);
            }

            Assert.AreEqual(objects.GetAllMaintainables().Count, objects2.GetAllMaintainables().Count);
        }
        public void TestWriteStructuresV2Default(string file)
        {
            ISdmxObjects objects;
            var fileInfo = new FileInfo(file);
            using (IReadableDataLocation location = new FileReadableDataLocation(fileInfo))
            {
                var structureWorkspace = this._parsingManager.ParseStructures(location);
                objects = structureWorkspace.GetStructureObjects(false);
            }

            StructureOutputFormat format = StructureOutputFormat.GetFromEnum(StructureOutputFormatEnumType.SdmxV2StructureDocument);
            var sdmxStructureFormat = new SdmxStructureFormat(format);
            var outputFileName = string.Format("{0}-output.xml", fileInfo.Name);
            using (var stream = File.Create(outputFileName))
            {
                var settings = new XmlWriterSettings { Indent = true };
                using (XmlWriter writer = XmlWriter.Create(stream, settings))
                {
                    IStructureWriterManager structureWritingManager = new StructureWriterManager(new SdmxStructureWriterFactory(writer));
                    structureWritingManager.WriteStructures(objects, sdmxStructureFormat, null);
                    writer.Flush();
                }
            }

            using (var stream = File.OpenRead(outputFileName))
            {
                XMLParser.ValidateXml(stream, SdmxSchemaEnumType.VersionTwo);
            }
        }
        public void TestWriteStructures(string file)
        {
            ISdmxObjects objects;
            var fileInfo = new FileInfo(file);
            using (IReadableDataLocation location = new FileReadableDataLocation(fileInfo))
            {
                var structureWorkspace = this._parsingManager.ParseStructures(location);
                objects = structureWorkspace.GetStructureObjects(false);
            }

            StructureOutputFormat format = StructureOutputFormat.GetFromEnum(StructureOutputFormatEnumType.SdmxV2RegistryQueryResponseDocument);
            var sdmxStructureFormat = new SdmxStructureFormat(format);
            var outputFileName = string.Format("{0}-output.xml", fileInfo.Name);
            using (var stream = File.Create(outputFileName))
            {
                this._writerManager.WriteStructures(objects, sdmxStructureFormat, stream);    
            }

            using (var stream = File.OpenRead(outputFileName))
            {
                XMLParser.ValidateXml(stream, SdmxSchemaEnumType.VersionTwo);
            }
        }