Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ControllerBuilder"/> class.
        /// </summary>
        /// <param name="mappingStoreConnectionSettings">
        /// The mapping store connection settings.
        /// </param>
        /// <param name="defaultHeader">
        /// The default header.
        /// </param>
        public ControllerBuilder(ConnectionStringSettings mappingStoreConnectionSettings, IHeader defaultHeader)
        {
            if (mappingStoreConnectionSettings == null)
            {
                _log.Error("No connection string defined. Please check the web.config.");
                throw new ArgumentNullException("mappingStoreConnectionSettings");
            }

            var dataRetrieverCore = new DataRetrieverCore(defaultHeader, mappingStoreConnectionSettings, SdmxSchemaEnumType.VersionTwo);
            var dataRetrieverV21  = new DataRetrieverCore(defaultHeader, mappingStoreConnectionSettings, SdmxSchemaEnumType.VersionTwoPointOne);

            this._retrievalWithCrossWriter    = dataRetrieverCore;
            this._retrievalWithWriter         = dataRetrieverCore;
            this._retrievalWithWriterv21      = dataRetrieverV21;
            this._advancedRetrievalWithWriter = dataRetrieverV21;

            // structure search factories
            IStructureSearchManagerFactory <IAdvancedMutableStructureSearchManager>     advancedFactory    = new AdvancedMutableStructureSearchManagerFactory();
            IStructureSearchManagerFactory <IAuthAdvancedMutableStructureSearchManager> autAdvancedFactory = new AuthAdvancedMutableStructureSearchManagerFactory();

            IStructureSearchManagerFactory <IMutableStructureSearchManager>     structureSearchManager = new MutableStructureSearchManagerFactory();
            IStructureSearchManagerFactory <IAuthMutableStructureSearchManager> autFactory             = new AuthMutableStructureSearchManagerFactory();

            // advanced structure search managers
            this._advancedMutableStructureSearchManager     = advancedFactory.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV21);
            this._authAdvancedMutableStructureSearchManager = autAdvancedFactory.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV21);

            // simple structure search managers
            this._mutableStructureSearchManagerV20     = structureSearchManager.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV20);
            this._authMutableStructureSearchManagerV20 = autFactory.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV20);

            this._mutableStructureSearchManagerV21       = structureSearchManager.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV21);
            this._authMutableStructureSearchManagerV21   = autFactory.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV21);
            this._mappingStoreSdmxObjectRetrievalManager = new MappingStoreSdmxObjectRetrievalManager(mappingStoreConnectionSettings);
        }
        public void TestGetDataDataWriterEngineEmptyAttr(string query, string name)
        {
            var connectionString = ConfigurationManager.ConnectionStrings [name];
            var dataQuery = new DataQueryImpl(new RESTDataQueryCore(query), new MappingStoreSdmxObjectRetrievalManager(connectionString));
            const string EmptyAttributeXML = "empty-attribute.xml";
            using (XmlWriter writer = XmlWriter.Create(EmptyAttributeXML, new XmlWriterSettings() {Indent = true}))
            {
                IDataWriterEngine dataWriter = new CompactDataWriterEngine(writer, SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwoPointOne));

                ISdmxDataRetrievalWithWriter sdmxDataRetrievalWithWriter = new DataRetrieverCore(new HeaderImpl("TestEmptyConditionalAttribute", "ZZ9"), connectionString, SdmxSchemaEnumType.VersionTwoPointOne);
                sdmxDataRetrievalWithWriter.GetData(dataQuery, dataWriter);
                writer.Flush();
            }
            var fileInfo = new FileInfo(EmptyAttributeXML);
            Assert.IsTrue(fileInfo.Exists);
            using (var fileStream = fileInfo.OpenRead())
            using (var reader = XmlReader.Create(fileStream))
            {
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            {
                                var localName = reader.LocalName;
                                if (localName.Equals("Group"))
                                {
                                    Assert.IsTrue(reader.HasAttributes);
                                    var dateStr = reader.GetAttribute("NAT_TITLE");
                                    Assert.IsNull(dateStr);
                                }
                                else if (localName.Equals("Obs"))
                                {
                                    Assert.IsTrue(reader.HasAttributes);
                                    var attribute = reader.GetAttribute("OBS_COM");
                                    Assert.IsTrue(attribute == null || !string.IsNullOrWhiteSpace(attribute));
                                }
                            }

                            break;
                    }
                }
            }
        }
        public void TestNestedAndOr(string queryFile, string dataflowFile, string dsdFile, string name)
        {
            var retrievalManager = this.GetSdmxObjectRetrievalManager(dataflowFile, dsdFile);
            var connectionString = ConfigurationManager.ConnectionStrings [name];
            ISdmxDataRetrievalWithWriter dr = new DataRetrieverCore(new HeaderImpl("TestNestedAndOr", "ZZ9"), connectionString, SdmxSchemaEnumType.VersionTwo);
            IList<IDataQuery> dataQuery;
            using (var fileReadableDataLocation = new FileReadableDataLocation(queryFile))
            {
                dataQuery = this.dataQueryParseManager.BuildDataQuery(fileReadableDataLocation, retrievalManager);
                Assert.IsNotEmpty(dataQuery);
            }

            var outputFileName = string.Format("{0}-TestNestedAndOr-out.xml", queryFile);
            using (XmlWriter writer = XmlWriter.Create(outputFileName, new XmlWriterSettings { Indent = true }))
            using (IDataWriterEngine dataWriter = new CompactDataWriterEngine(writer, SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwo)))
            {
                dr.GetData(dataQuery.First(), dataWriter);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ControllerBuilder"/> class.
        /// </summary>
        /// <param name="mappingStoreConnectionSettings">
        /// The mapping store connection settings.
        /// </param>
        /// <param name="defaultHeader">
        /// The default header.
        /// </param>
        public CsvZipControllerBuilder(ConnectionStringSettings mappingStoreConnectionSettings, IHeader defaultHeader)
        {
            if (mappingStoreConnectionSettings == null)
            {
                _log.Error("No connection string defined. Please check the web.config.");
                throw new ArgumentNullException("mappingStoreConnectionSettings");
            }

            var dataRetrieverCore = new DataRetrieverCore(defaultHeader, mappingStoreConnectionSettings, SdmxSchemaEnumType.VersionTwo);
            var dataRetrieverV21 = new DataRetrieverCore(defaultHeader, mappingStoreConnectionSettings, SdmxSchemaEnumType.VersionTwoPointOne);
            var dataRetrieverCsvZip = new CsvZipDataRetrieverCore(defaultHeader, mappingStoreConnectionSettings, SdmxSchemaEnumType.VersionTwoPointOne);
            this._retrievalWithCrossWriter = dataRetrieverCore;
            this._retrievalWithWriter = dataRetrieverCore;
            this._retrievalWithWriterv21 = dataRetrieverCsvZip;
            this._advancedRetrievalWithWriter = dataRetrieverV21;

            //andrea
            this._retrievalTabular = dataRetrieverCore;

            // structure search factories
            IStructureSearchManagerFactory<IAdvancedMutableStructureSearchManager> advancedFactory = new AdvancedMutableStructureSearchManagerFactory();
            IStructureSearchManagerFactory<IAuthAdvancedMutableStructureSearchManager> autAdvancedFactory = new AuthAdvancedMutableStructureSearchManagerFactory();

            IStructureSearchManagerFactory<IMutableStructureSearchManager> structureSearchManager = new MutableStructureSearchManagerFactory();
            IStructureSearchManagerFactory<IAuthMutableStructureSearchManager> autFactory = new AuthMutableStructureSearchManagerFactory();

            // advanced structure search managers 
            this._advancedMutableStructureSearchManager = advancedFactory.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV21);
            this._authAdvancedMutableStructureSearchManager = autAdvancedFactory.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV21);

            // simple structure search managers
            this._mutableStructureSearchManagerV20 = structureSearchManager.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV20);
            this._authMutableStructureSearchManagerV20 = autFactory.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV20);

            this._mutableStructureSearchManagerV21 = structureSearchManager.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV21);
            this._authMutableStructureSearchManagerV21 = autFactory.GetStructureSearchManager(mappingStoreConnectionSettings, _sdmxSchemaV21);
        }
        public void TestSDMXv20XS(string filePath, string name, int allowedObs)
        {
            var connectionString = ConfigurationManager.ConnectionStrings [name];
            IList<IDataQuery> dataQueries;
            var mappingStoreSdmxObjectRetrievalManager = new MappingStoreSdmxObjectRetrievalManager(connectionString);
            using (IReadableDataLocation dataLocation = new FileReadableDataLocation(filePath))
            {
                dataQueries = this._dataQueryParseManager.BuildDataQuery(dataLocation, mappingStoreSdmxObjectRetrievalManager);
            }

            Assert.IsNotEmpty(dataQueries);
            var dataQuery = dataQueries.First();

            var outputFileName = string.Format("{0}-soap-v20-xs-max-obs-out.xml", filePath);
            using (XmlWriter writer = XmlWriter.Create(outputFileName, new XmlWriterSettings { Indent = true }))
            {
                ICrossSectionalWriterEngine dataWriter = new CrossSectionalWriterEngine(writer, SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwo));

                ISdmxDataRetrievalWithCrossWriter advancedSdmxDataRetrievalWithWriter = new DataRetrieverCore(this._defaultHeader, connectionString, SdmxSchemaEnumType.VersionTwo, allowedObs);
                advancedSdmxDataRetrievalWithWriter.GetData(dataQuery, dataWriter);
                writer.Flush();
            }
        }
        public void TestRest(string restUrl, string connectionName, int allowedObs)
        {
            var connectionString = ConfigurationManager.ConnectionStrings [connectionName];
            var mappingStoreSdmxObjectRetrievalManager = new MappingStoreSdmxObjectRetrievalManager(connectionString);
            var dataQuery = this._dataQueryParseManager.ParseRestQuery(restUrl, mappingStoreSdmxObjectRetrievalManager);

            Assert.IsNotNull(dataQuery);

            var outputFileName = string.Format("REST-{0}-{1}-{2}-{3}--max-obsout.xml", dataQuery.Dataflow.Id, dataQuery.DimensionAtObservation, dataQuery.FirstNObservations, dataQuery.LastNObservations);
            using (XmlWriter writer = XmlWriter.Create(outputFileName, new XmlWriterSettings { Indent = true }))
            {
                IDataWriterEngine dataWriter = new CompactDataWriterEngine(writer, SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwoPointOne));

                ISdmxDataRetrievalWithWriter sdmxDataRetrievalWithWriter = new DataRetrieverCore(this._defaultHeader, connectionString, SdmxSchemaEnumType.VersionTwoPointOne, allowedObs);
                sdmxDataRetrievalWithWriter.GetData(dataQuery, dataWriter);
                writer.Flush();
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SriRetrieverFactory" /> class.
        /// </summary>
        /// <exception cref="StructureRetrieverException">Could not establish a connection to the mapping store DB
        /// <see cref="P:Estat.Nsi.StructureRetriever.StructureRetrieverException.ErrorType" />
        /// is set to                  <see cref="F:Estat.Nsi.StructureRetriever.StructureRetrieverErrorTypes.MappingStoreConnectionError" /></exception>
        public SriRetrieverFactory()
        {
            var defaultHeader = SettingsManager.Header;
            var settingsManager = new MappingStoreSettingsManager();
            var mappingStoreConnectionSettings = settingsManager.MappingStoreConnectionSettings;
            if (mappingStoreConnectionSettings != null)
            {
                // Data Retriever initialization
                var dataRetrieverSdmxv20Behaviour = new DataRetrieverCore(defaultHeader, mappingStoreConnectionSettings, SdmxSchemaEnumType.VersionTwo);
                var dataRetrieverSdmxV21Behaviour = new DataRetrieverCore(defaultHeader, mappingStoreConnectionSettings, SdmxSchemaEnumType.VersionTwoPointOne);

                // SDMX v2.0 WS Soap for SDMX v2.0 CrossSectional data (does not throw No Results when no data is found).
                this._sdmxv20XSDataRetrievalForWs20 = dataRetrieverSdmxv20Behaviour;

                // SDMX v2.1 WS REST for SDMX v2.0 CrossSectional data (throws No Results when no data is found).
                this._sdmxV20XSDataRetrieverForRest = dataRetrieverSdmxV21Behaviour;
                this._dataRetrievalForWs20 = dataRetrieverSdmxv20Behaviour;
                this._dataRetrievalForRest = dataRetrieverSdmxV21Behaviour;
                this._dataRetrieverForWs21 = dataRetrieverSdmxV21Behaviour;

                // advanced structure search managers  (SDMX v2.1 SOAP)
                SdmxSchema sdmxSchemaV21 = SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwoPointOne);
                this._structureRetrievalForWs21 = new Estat.Nsi.StructureRetriever.Manager.AdvancedStructureRetriever(mappingStoreConnectionSettings);
                this._authStructureRetrievalForWs21 = new AuthAdvancedStructureRetriever(mappingStoreConnectionSettings);

                // simple structure search managers (SDMX v2.0 SOAP)
                SdmxSchema sdmxSchemaV20 = SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwo);
                this._structureRetrievalForWs20 = new StructureRetrieverAvailableData(mappingStoreConnectionSettings, sdmxSchemaV20);
                this._authStructureRetrievalForWs20 = new AuthStructureRetrieverAvailableData(mappingStoreConnectionSettings, sdmxSchemaV20);

                // structure search manager (SDMX v2.1 REST)
                this._structureRetrievalForRest = new StructureRetrieverAvailableData(mappingStoreConnectionSettings, sdmxSchemaV21);
                this._authStructureRetrievalForRest = new AuthStructureRetrieverAvailableData(mappingStoreConnectionSettings, sdmxSchemaV21);
                this._mappingStoreSdmxObjectRetrievalManager = new MappingStoreSdmxObjectRetrievalManager(mappingStoreConnectionSettings);
            }
        }