/// <summary>
        /// Obtains a StructureWritingEngine engine for the given output format
        /// </summary>
        /// <param name="structureFormat">An implementation of the StructureFormat to describe the output format for the structures (required)</param>
        /// <param name="streamWriter">The output stream to write to (can be null if it is not required)</param>
        /// <returns>Null if this factory is not capable of creating a data writer engine in the requested format</returns>
        public IStructureWriterEngine GetStructureWriterEngine(
            IStructureFormat structureFormat, Stream streamWriter)
        {
            if (structureFormat.SdmxOutputFormat != null)
            {
                var outputFormat = structureFormat.SdmxOutputFormat;
                SdmxSchema schemaVersion = outputFormat.OutputVersion;
                if (!outputFormat.IsQueryResponse && !outputFormat.IsRegistryDocument)
                {
                    return this.GetObjectEngine(schemaVersion, streamWriter);
                }

                if (outputFormat.EnumType == StructureOutputFormatEnumType.SdmxV2RegistryQueryResponseDocument)
                {
                    if (this._writer != null)
                    {
                        return new RegistryQueryResponseWriterEngineV2(this._writer);
                    }

                    return new RegistryQueryResponseWriterEngineV2(streamWriter);
                }
            }

            return null;
        }
        /// <summary>
        /// Gets the structure writer engine.
        /// </summary>
        /// <param name="structureFormat">The structure format.</param>
        /// <param name="streamWriter">The stream writer.</param>
        /// <returns>The <see cref="IStructureWriterEngine"/>.</returns>
        /// <exception cref="System.ArgumentException">Both outStream and structureFormat,XmlWriter set. Please set only one of them.</exception>
        public IStructureWriterEngine GetStructureWriterEngine(IStructureFormat structureFormat, Stream streamWriter)
        {
            SdmxStructureXmlFormat sdmxStructureXmlFormat = structureFormat as SdmxStructureXmlFormat;
            if (sdmxStructureXmlFormat != null)
            {
                if (streamWriter != null && sdmxStructureXmlFormat.XMLWriter != null)
                {
                    throw new ArgumentException("Both outStream and structureFormat,XmlWriter set. Please set only one of them.");
                }

                    // TODO check if we need this
                sdmxStructureXmlFormat.Actions.RunAll();
                IStructureWriterFactory decoratingFactory;
                if (sdmxStructureXmlFormat.XMLWriter != null)
                {
                    decoratingFactory = GetCoreStructureWriterFactory(sdmxStructureXmlFormat);
                }
                else
                {
                    decoratingFactory = GetCoreStructureWriterFactoryNoWriter(sdmxStructureXmlFormat);
                }

                if (decoratingFactory != null)
                {
                    return decoratingFactory.GetStructureWriterEngine(new SdmxStructureFormat(sdmxStructureXmlFormat.SdmxOutputFormat), streamWriter);
                }
            }

            return null;
        }
        /// <summary>
        /// Obtains a StructureWritingEngine engine for the given output format
        /// </summary>
        /// <param name="structureFormat">
        /// An implementation of the StructureFormat to describe the output format for the structures (required)
        /// </param>
        /// <param name="streamWriter">
        /// The output stream to write to (can be null if it is not required)
        /// </param>
        /// <returns>
        /// Null if this factory is not capable of creating a data writer engine in the requested format
        /// </returns>
        public IStructureWriterEngine GetStructureWriterEngine(IStructureFormat structureFormat, Stream streamWriter)
        {
            if (streamWriter != null && !streamWriter.CanWrite)
            {
                throw new ArgumentException(Resources.ExcepteptionCannotWriteToStream, "streamWriter");
            }

            if (structureFormat.SdmxOutputFormat != null)
            {
                var outputFormat = structureFormat.SdmxOutputFormat;
                SdmxSchema schemaVersion = outputFormat.OutputVersion;
                if (!outputFormat.IsQueryResponse && !outputFormat.IsRegistryDocument)
                {
                    return this.GetObjectEngine(schemaVersion, streamWriter);
                }

                if (outputFormat.EnumType == StructureOutputFormatEnumType.SdmxV2RegistryQueryResponseDocument)
                {
                    if (this._writer != null)
                    {
                        return new RegistryInterfaceWriterV2(this._writer);
                    }

                    return new RegistryInterfaceWriterV2(streamWriter);
                }
            }

            return null;
        }
        /// <summary>
        /// Obtains a StructureWritingEngine engine for the given output format
        /// </summary>
        /// <param name="structureFormat">An implementation of the StructureFormat to describe the output format for the structures (required)</param>
        /// <param name="streamWriter">The output stream to write to (can be null if it is not required)</param>
        /// <returns>Null if this factory is not capable of creating a data writer engine in the requested format</returns>
        public IStructureWriterEngine GetStructureWriterEngine(IStructureFormat structureFormat, Stream streamWriter)
        {
            if (structureFormat is HtmlOutputFormat)
            {
                return new HtmlStructureWriterEngine(streamWriter);
            }

            return null;
        }
示例#5
0
        /// <summary>
        /// The write structure to file.
        /// </summary>
        /// <param name="outputFormat">
        /// The output format.
        /// </param>
        /// <param name="outputStream">
        /// The output stream.
        /// </param>
        public void writeStructureToFile(IStructureFormat outputFormat, Stream outputStream)
        {
            ISdmxObjects sdmxObjects = new SdmxObjectsImpl();

            sdmxObjects.AddAgencyScheme(this.structuresCreator.BuildAgencyScheme());
            sdmxObjects.AddCodelist(this.structuresCreator.BuildCountryCodelist());
            sdmxObjects.AddCodelist(this.structuresCreator.BuildIndicatorCodelist());
            sdmxObjects.AddConceptScheme(this.structuresCreator.BuildConceptScheme());

            IDataStructureObject dsd = this.structuresCreator.BuildDataStructure();
            sdmxObjects.AddDataStructure(dsd);
            sdmxObjects.AddDataflow(this.structuresCreator.BuildDataflow("DF_WDI", "World Development Indicators", dsd));

            this.swm.WriteStructures(sdmxObjects, outputFormat, outputStream);
        }
 /// <summary>
 /// Gets the structures into an output stream
 /// </summary>
 /// <param name="query">
 /// The rest structures query
 /// </param>
 /// <param name="outputStream">
 /// The output stream
 /// </param>
 /// <param name="outputFormat">
 /// The output fromat
 /// </param>
 public void GetStructures(IRestStructureQuery query, Stream outputStream, IStructureFormat outputFormat)
 {
     ISdmxObjects beans = _beanRetrievalManager.GetMaintainables(query);
     _structureWritingManager.WriteStructures(beans, outputFormat, outputStream);
 }
        /// <summary>
        /// Return structure writing engine.
        /// </summary>
        /// <param name="outputFormat">
        /// The output format.
        /// </param>
        /// <param name="outputStream">
        /// The output stream.
        /// </param>
        /// <returns>
        /// The <see cref="IStructureWriterEngine"/>.
        /// </returns>
        private IStructureWriterEngine GetStructureWritingEngine(IStructureFormat outputFormat, Stream outputStream)
        {
            foreach (var structureWriterFactory in this._structureWriterFactory)
            {
                IStructureWriterEngine engine = structureWriterFactory.GetStructureWriterEngine(outputFormat, outputStream);
                if (engine != null)
                {
                    return engine;
                }
            }

            throw new SdmxNotImplementedException("Could not write structures out in format: " + outputFormat);
        }
 /// <summary>
 /// Writes the contents of the bean out to the output stream in the version specified.
 /// </summary>
 /// <param name="sdmxObject">
 /// The sdmxObjects to write to the output stream
 /// </param>
 /// <param name="header">
 /// can be null, if null will create a default header
 /// </param>
 /// <param name="outputFormat">
 /// the output format of the message (required)
 /// </param>
 /// <param name="outputStream">
 /// the stream to write to, the stream is NOT closed on completion, this can be null if not required (i.e the outputFormat may contain a writer)
 /// </param>
 public void WriteStructure(IMaintainableObject sdmxObject, IHeader header, IStructureFormat outputFormat, Stream outputStream)
 {
     _log.Debug("Write Structure '" + sdmxObject + "' as " + outputFormat);
     GetStructureWritingEngine(outputFormat, outputStream).WriteStructure(sdmxObject);
 }
 /// <summary>
 /// Writes the contents of the beans out to the output stream in the format specified.
 /// Will write the header information contained within the SdmxBeans container if there is a header present.  If the header
 /// is not present a default header will be created
 /// </summary>
 /// <param name="sdmxObjects">
 /// The SDMX objects to write to the output stream.
 /// </param>
 /// <param name="outputFormat">
 /// The output format of the message (required)
 /// </param>
 /// <param name="outputStream">
 /// the stream to write to, the stream is closed on completion, this can be null if not required (i.e the outputFormat may contain a writer)
 /// </param>
 public void WriteStructures(ISdmxObjects sdmxObjects, IStructureFormat outputFormat, Stream outputStream)
 {
     _log.Debug("Write Structures as " + outputFormat);
     GetStructureWritingEngine(outputFormat, outputStream).WriteStructures(sdmxObjects);
 }