public void TestWriteStructures(string file) { var structureReader = new StructureParsingManager(); var fileInfo = new FileInfo(file); IStructureWorkspace structureWorkspace; using (var readable = new FileReadableDataLocation(fileInfo)) { structureWorkspace = structureReader.ParseStructures(readable); } ISdmxObjects structureBeans = structureWorkspace.GetStructureObjects(false); string output = string.Format(CultureInfo.InvariantCulture, "test-sdmxv2.1-{0}", fileInfo.Name); var writtingManager = new StructureWriterManager(); using (var outputStream = new FileStream(output, FileMode.Create)) { writtingManager.WriteStructures(structureBeans, new SdmxStructureFormat(StructureOutputFormat.GetFromEnum(StructureOutputFormatEnumType.SdmxV21StructureDocument)), outputStream); } using (var readable = new FileReadableDataLocation(output)) { XMLParser.ValidateXml(readable, SdmxSchemaEnumType.VersionTwoPointOne); var structures = structureReader.ParseStructures(readable); Assert.NotNull(structures); } }
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(); } }
private static System.IO.MemoryStream GetStream(ISdmxObjects sdmxObjects, Org.Sdmxsource.Sdmx.Api.Constants.StructureOutputFormatEnumType version) { Org.Sdmxsource.Sdmx.Api.Constants.StructureOutputFormat soFormat = Org.Sdmxsource.Sdmx.Api.Constants.StructureOutputFormat.GetFromEnum(version); Org.Sdmxsource.Sdmx.Api.Model.Format.IStructureFormat outputFormat = new Org.Sdmxsource.Sdmx.SdmxObjects.Model.SdmxStructureFormat(soFormat); Org.Sdmxsource.Sdmx.Structureparser.Manager.StructureWriterManager swm = new Org.Sdmxsource.Sdmx.Structureparser.Manager.StructureWriterManager(); System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(); swm.WriteStructures(sdmxObjects, outputFormat, memoryStream); return memoryStream; }
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 TestReadWriteSdmxV21ObjectCount(string file) { IStructureParsingManager parsingManager = new StructureParsingManager(SdmxSchemaEnumType.VersionTwoPointOne); ISdmxObjects structureBeans; using (IReadableDataLocation fileReadableDataLocation = new FileReadableDataLocation(file)) { IStructureWorkspace structureWorkspace = parsingManager.ParseStructures(fileReadableDataLocation); Assert.NotNull(structureWorkspace); structureBeans = structureWorkspace.GetStructureObjects(false); Assert.NotNull(structureBeans); } IStructureWriterManager writerManager = new StructureWriterManager(); var outputFileName = file + "-out.xml"; using (Stream outputStream = File.Create(outputFileName)) { writerManager.WriteStructures(structureBeans, new SdmxStructureFormat(StructureOutputFormat.GetFromEnum(StructureOutputFormatEnumType.SdmxV21StructureDocument)), outputStream); outputStream.Flush(); } ISdmxObjects objects2; using (IReadableDataLocation location = new FileReadableDataLocation(outputFileName)) { var structureWorkspace = parsingManager.ParseStructures(location); objects2 = structureWorkspace.GetStructureObjects(false); } Assert.AreEqual(structureBeans.GetAllMaintainables().Count, objects2.GetAllMaintainables().Count); }
public void TestReadWriteSdmxV21(string file) { IStructureParsingManager parsingManager = new StructureParsingManager(SdmxSchemaEnumType.VersionTwoPointOne); ISdmxObjects structureBeans; using (IReadableDataLocation fileReadableDataLocation = new FileReadableDataLocation(file)) { IStructureWorkspace structureWorkspace = parsingManager.ParseStructures(fileReadableDataLocation); Assert.NotNull(structureWorkspace); structureBeans = structureWorkspace.GetStructureObjects(false); Assert.NotNull(structureBeans); } IStructureWriterManager writerManager = new StructureWriterManager(); var outputFileName = file + "-out.xml"; using (Stream outputStream = File.Create(outputFileName)) { writerManager.WriteStructures(structureBeans, new SdmxStructureFormat(StructureOutputFormat.GetFromEnum(StructureOutputFormatEnumType.SdmxV21StructureDocument)), outputStream); outputStream.Flush(); } using (var stream = File.OpenRead(outputFileName)) { XMLParser.ValidateXml(stream, SdmxSchemaEnumType.VersionTwoPointOne); } }