Example #1
0
        /// <summary>
        /// Sends the specified <paramref name="request"/> to the Web Service defined by <see cref="_config"/>
        /// </summary>
        /// <param name="request">
        /// The <see cref="IComplexStructureQuery"/>
        /// </param>
        /// <returns>
        /// The ISdmxObjects returned by the Web Service
        /// </returns>
        private ISdmxObjects SendQueryStructureRequest(string request)
        {
            string tempFileName = Path.GetTempFileName();

            try
            {
                this.SendRequest(request, tempFileName, RequestType.Structure);

                ISdmxObjects             structureObjects = new SdmxObjectsImpl();
                IStructureParsingManager parsingManager   = new StructureParsingManager(SdmxSchemaEnumType.Null);
                using (var dataLocation = new FileReadableDataLocation(tempFileName))
                {
                    IStructureWorkspace structureWorkspace = parsingManager.ParseStructures(dataLocation);
                    structureObjects = structureWorkspace.GetStructureObjects(false);
                }

                NsiClientValidation.CheckResponse(structureObjects);
                return(structureObjects);
            }
            finally
            {
                // Delete the temporary file
                File.Delete(tempFileName);
            }
        }
        /// <summary>
        /// Sends the specified <paramref name="complexStructureQuery"/> to the Web Service defined by <see cref="_config"/>
        /// </summary>
        /// <param name="complexStructureQuery">The <see cref="IComplexStructureQuery"/></param>
        /// <returns>The ISdmxObjects returned by the Web Service</returns>
        private ISdmxObjects SendQueryStructureRequest(IComplexStructureQuery complexStructureQuery, SDMXWSFunctionV21 sdmxwsFunctionV21)
        {
            IStructureQueryFormat <XDocument> queryFormat = new ComplexQueryFormatV21();

            IComplexStructureQueryFactory <XDocument>        factory = new ComplexStructureQueryFactoryV21 <XDocument>();
            IComplexStructureQueryBuilderManager <XDocument> complexStructureQueryBuilderManager = new ComplexStructureQueryBuilderManager <XDocument>(factory);
            var wdoc = complexStructureQueryBuilderManager.BuildComplexStructureQuery(complexStructureQuery, queryFormat);
            var doc  = new XmlDocument();

            doc.LoadXml(wdoc.ToString());

            string tempFileName = Path.GetTempFileName();

            try
            {
                this.SendRequest(doc, sdmxwsFunctionV21, tempFileName);

                ISdmxObjects             structureObjects = new SdmxObjectsImpl();
                IStructureParsingManager parsingManager   = new StructureParsingManager(SdmxSchemaEnumType.Null);
                using (var dataLocation = new FileReadableDataLocation(tempFileName))
                {
                    IStructureWorkspace structureWorkspace = parsingManager.ParseStructures(dataLocation);

                    structureObjects = structureWorkspace.GetStructureObjects(false);
                }

                NsiClientValidation.CheckResponse(structureObjects);
                return(structureObjects);
            }
            finally
            {
                //Delete the temporary file
                File.Delete(tempFileName);
            }
        }
Example #3
0
        /// <summary>
        /// Gets a bean with data about the key family for specified dataflow.
        /// </summary>
        /// <param name="dataflow">
        /// The dataflow
        /// </param>
        /// <param name="dataStructures">
        /// The data Structures.
        /// </param>
        /// <returns>
        /// a <c>StructureBean</c> instance with requested data; the result is never <c>null</c> or  incomplete, instead an exception is throwed away if something goes wrong and not all required data is successfully retrieved
        /// </returns>
        /// <remarks>
        /// The resulted bean will contain exactly one key family, but also will include any concepts and codelists referenced by the key family.
        /// </remarks>
        public ISdmxObjects GetStructure(IDataflowObject dataflow, ISet <IDataStructureObject> dataStructures, bool resolseRef = false)
        {
            Logger.InfoFormat(
                CultureInfo.InvariantCulture,
                Resources.InfoGettingStructureFormat3,
                dataflow.AgencyId,
                dataflow.Id,
                dataflow.Version);
            ISdmxObjects structure = new SdmxObjectsImpl();

            try
            {
                ISdmxObjects responseConceptScheme = new SdmxObjectsImpl();
                ISdmxObjects response = new SdmxObjectsImpl();

                IStructureQueryFormat <string> structureQueryFormat = new RestQueryFormat();
                IStructureQueryFactory         factory = new RestStructureQueryFactory();
                IStructureQueryBuilderManager  structureQueryBuilderManager = new StructureQueryBuilderManager(factory);

                IDataStructureObject dsd = NsiClientHelper.GetDsdFromDataflow(dataflow, dataStructures);
                structure.AddDataStructure(dsd);

                NsiClientValidation.CheckifStructureComplete(structure, dataflow);
                IEnumerable <IStructureReference> conceptRefs = NsiClientHelper.BuildConceptSchemeRequest(structure.DataStructures.First());
                foreach (var structureReference in conceptRefs)
                {
                    IRestStructureQuery structureQuery = new RESTStructureQueryCore(StructureQueryDetail.GetFromEnum(StructureQueryDetailEnumType.Full), StructureReferenceDetail.GetFromEnum(StructureReferenceDetailEnumType.None), null, structureReference, false);
                    string request = structureQueryBuilderManager.BuildStructureQuery(structureQuery, structureQueryFormat);
                    responseConceptScheme = this.SendQueryStructureRequest(request);
                    response.Merge(responseConceptScheme);
                }

                structure.Merge(response);

                NsiClientValidation.CheckConcepts(structure);
                Logger.Info(Resources.InfoSuccess);
            }
            catch (NsiClientException e)
            {
                Logger.Error(Resources.ExceptionGettingStructure);
                Logger.Error(e.Message, e);
                throw;
            }
            catch (Exception e)
            {
                Logger.Error(Resources.ExceptionGettingStructure);
                Logger.Error(e.Message, e);
                throw new NsiClientException(Resources.ExceptionGettingStructure, e);
            }

            return(structure);
        }
        /// <summary>
        /// Gets a bean with data about the key family for specified dataflow.
        /// </summary>
        /// <param name="dataflow">
        /// The dataflow
        /// </param>
        /// <returns>
        /// a <c>StructureBean</c> instance with requested data; the result is never <c>null</c> or  incomplete, instead an exception is throwed away if something goes wrong and not all required data is successfully retrieved
        /// </returns>
        /// <remarks>
        /// The resulted bean will contain exactly one key family, but also will include any concepts and codelists referenced by the key family.
        /// </remarks>
        public ISdmxObjects GetStructure(IDataflowObject dataflow, ISet <IDataStructureObject> dataStructures, bool resolseRef = false)
        {
            Logger.InfoFormat(
                CultureInfo.InvariantCulture,
                Resources.InfoGettingStructureFormat3,
                dataflow.AgencyId,
                dataflow.Id,
                dataflow.Version);
            ISdmxObjects structure = new SdmxObjectsImpl();

            try
            {
                ISdmxObjects responseConceptScheme = new SdmxObjectsImpl();
                ISdmxObjects response = new SdmxObjectsImpl();

                IDataStructureObject dsd = NsiClientHelper.GetDsdFromDataflow(dataflow, dataStructures);
                structure.AddDataStructure(dsd);

                NsiClientValidation.CheckifStructureComplete(structure, dataflow);
                IEnumerable <IStructureReference> conceptRefs = NsiClientHelper.BuildConceptSchemeRequest(structure.DataStructures.First());
                foreach (var structureReference in conceptRefs)
                {
                    IRestStructureQuery structureQueryConceptScheme = new RESTStructureQueryCore(structureReference);
                    IBuilder <IComplexStructureQuery, IRestStructureQuery> transformerCategoryScheme = new StructureQuery2ComplexQueryBuilder();
                    IComplexStructureQuery complexStructureQueryConceptScheme = transformerCategoryScheme.Build(structureQueryConceptScheme);
                    responseConceptScheme = this.SendQueryStructureRequest(complexStructureQueryConceptScheme, SDMXWSFunctionV21.GetConceptScheme);
                    response.Merge(responseConceptScheme);
                }
                structure.Merge(response);

                NsiClientValidation.CheckConcepts(structure);
                Logger.Info(Resources.InfoSuccess);
            }
            catch (NsiClientException e)
            {
                Logger.Error(Resources.ExceptionGettingStructure);
                Logger.Error(e.Message, e);
                throw;
            }
            catch (Exception e)
            {
                Logger.Error(Resources.ExceptionGettingStructure);
                Logger.Error(e.Message, e);
                throw new NsiClientException(Resources.ExceptionGettingStructure, e);
            }

            return(structure);
        }
Example #5
0
        /// <summary>
        /// Gets a bean with data about the key family for specified dataflow.
        /// </summary>
        /// <param name="dataflow">
        /// The dataflow
        /// </param>
        /// <returns>
        /// a <c>StructureBean</c> instance with requested data; the result is never <c>null</c> or  incomplete, instead an exception is throwed away if something goes wrong and not all required data is successfully retrieved
        /// </returns>
        /// <remarks>
        /// The resulted bean will contain exactly one key family, but also will include any concepts and codelists referenced by the key family.
        /// </remarks>
        public ISdmxObjects GetStructure(IDataflowObject dataflow, ISet <IDataStructureObject> dataStructures, bool resolseRef = false)
        {
            Logger.InfoFormat(
                CultureInfo.InvariantCulture,
                Resources.InfoGettingStructureFormat3,
                dataflow.AgencyId,
                dataflow.Id,
                dataflow.Version);
            ISdmxObjects structure;

            var keyFamilyRefBean = new StructureReferenceImpl(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Dsd))
            {
                MaintainableId = dataflow.DataStructureRef.MaintainableReference.MaintainableId,
                AgencyId       = dataflow.DataStructureRef.MaintainableReference.AgencyId,
                Version        = dataflow.DataStructureRef.MaintainableReference.Version
            };

            try
            {
                ISdmxObjects response;

                structure = this.SendQueryStructureRequest(keyFamilyRefBean, false);
                NsiClientValidation.CheckifStructureComplete(structure, dataflow);
                IEnumerable <IStructureReference> conceptRefs = NsiClientHelper.BuildConceptSchemeRequest(structure.DataStructures.First());
                response = this.SendQueryStructureRequest(conceptRefs, false);

                structure.Merge(response);

                NsiClientValidation.CheckConcepts(structure);
                Logger.Info(Resources.InfoSuccess);
            }
            catch (NsiClientException e)
            {
                Logger.Error(Resources.ExceptionGettingStructure);
                Logger.Error(e.Message, e);
                throw;
            }
            catch (Exception e)
            {
                Logger.Error(Resources.ExceptionGettingStructure);
                Logger.Error(e.Message, e);
                throw new NsiClientException(Resources.ExceptionGettingStructure, e);
            }

            return(structure);
        }
Example #6
0
        /// <summary>
        /// Sends the specified <paramref name="references"/> to the Web Service defined by <see cref="_config"/>
        /// </summary>
        /// <param name="references">The <see cref="IStructureReference"/></param>
        /// <param name="resolveReferences">
        /// The resolve references
        /// </param>
        /// <returns>The QueryStructureResponse returned by the Web Service</returns>
        public ISdmxObjects SendQueryStructureRequest(
            IEnumerable <IStructureReference> references,
            bool resolveReferences)
        {
            var queryStructureRequestBuilderManager = new QueryStructureRequestBuilderManager();

            IStructureQueryFormat <XDocument> queryFormat = new QueryStructureRequestFormat();
            var wdoc = queryStructureRequestBuilderManager.BuildStructureQuery(references, queryFormat, resolveReferences);

            var doc = new XmlDocument();

            doc.LoadXml(wdoc.ToString());

            string tempFileName = Path.GetTempFileName();

            try
            {
                this.SendRequest(doc, SDMXWSFunction.QueryStructure, tempFileName);

                ISdmxObjects             structureObjects = new SdmxObjectsImpl();
                IStructureParsingManager parsingManager   = new StructureParsingManager(SdmxSchemaEnumType.Null);
                using (var dataLocation = new FileReadableDataLocation(tempFileName))
                {
                    IStructureWorkspace structureWorkspace = parsingManager.ParseStructures(dataLocation);
                    structureObjects = structureWorkspace.GetStructureObjects(false);
                }

                NsiClientValidation.CheckResponse(structureObjects);
                return(structureObjects);
            }
            finally
            {
                //delete the temporary file
                File.Delete(tempFileName);
            }
        }
Example #7
0
        public ISdmxObjects GetDsd(string DsdId, string DsdAgency, string DsdVersion, bool resolseRef = false)
        {
            Logger.InfoFormat(
                CultureInfo.InvariantCulture,
                Resources.InfoGettingStructureFormat3,
                DsdAgency,
                DsdId,
                DsdVersion);



            System.Reflection.Assembly ass = System.Reflection.Assembly.GetExecutingAssembly();
            string path         = System.IO.Path.GetDirectoryName(ass.CodeBase);
            string templateFile = Path.Combine(path, "Model\\XMLQueryTemplate\\DOTSTAT_GetDataStructureDefinition.xml");
            var    doc          = new XmlDocument();

            doc.Load(templateFile);

            var nodesId = doc.GetElementsByTagName("KeyFamily");

            if (nodesId == null || nodesId.Count < 1)
            {
                return(null);
            }
            nodesId[0].InnerText = DsdId;

            var nodeAgency = doc.GetElementsByTagName("Receiver");

            if (nodeAgency == null || nodeAgency.Count < 1)
            {
                return(null);
            }
            nodeAgency[0].Attributes.GetNamedItem("id").Value = DsdAgency;

            string tempFileName = Path.GetTempFileName();

            try
            {
                this.SendRequest(doc, SDMXWSFunction.GetDataStructureDefinition, tempFileName);


                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(tempFileName);


                var codes = xmlDoc.GetElementsByTagName("Code");
                for (int i = 0; i < codes.Count; i++)
                {
                    var val = codes.Item(i).Attributes.GetNamedItem("value");
                    var par = codes.Item(i).Attributes.GetNamedItem("parentCode");
                    if (val != null && par != null && val.Value == par.Value)
                    {
                        codes.Item(i).Attributes.GetNamedItem("parentCode").Value = null;
                    }
                }

                var time_dimensions = xmlDoc.GetElementsByTagName("TimeDimension");
                time_dimensions.Item(0).Attributes.RemoveNamedItem("codelist");

                xmlDoc.Save(tempFileName);

                ISdmxObjects             structureObjects = new SdmxObjectsImpl();
                IStructureParsingManager parsingManager   = new StructureParsingManager(SdmxSchemaEnumType.VersionTwo);

                using (var dataLocation = new FileReadableDataLocation(tempFileName))
                {
                    IStructureWorkspace structureWorkspace = parsingManager.ParseStructures(dataLocation);
                    structureObjects = structureWorkspace.GetStructureObjects(false);
                }

                NsiClientValidation.CheckResponse(structureObjects);
                return(structureObjects);
            }
            finally
            {
                //delete the temporary file
                File.Delete(tempFileName);
            }
        }
Example #8
0
        public ISdmxObjects GetStructure(string DataflowId, string DatafloAgency, string DatafloVersion, bool resolseRef = false)
        {
            Logger.InfoFormat(
                CultureInfo.InvariantCulture,
                Resources.InfoGettingStructureFormat3,
                DatafloAgency,
                DataflowId,
                DatafloVersion);

            #region Dataflow
            ISdmxObjects responseDF      = new SdmxObjectsImpl();
            var          dataflowRefBean = new StructureReferenceImpl(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Dataflow))
            {
                MaintainableId = DataflowId,
                AgencyId       = DatafloAgency,
                Version        = DatafloVersion
            };
            IList <IStructureReference> refs = new List <IStructureReference>();
            refs.Add(dataflowRefBean);
            responseDF = this.SendQueryStructureRequest(refs, false);
            if (responseDF.Dataflows == null || responseDF.Dataflows.Count == 0)
            {
                throw new Exception("Dataflow not found");
            }
            #endregion
            IDataflowObject dataflow = responseDF.Dataflows.First();

            ISdmxObjects structure;

            var keyFamilyRefBean = new StructureReferenceImpl(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Dsd))
            {
                MaintainableId = dataflow.DataStructureRef.MaintainableReference.MaintainableId,
                AgencyId       = dataflow.DataStructureRef.MaintainableReference.AgencyId,
                Version        = dataflow.DataStructureRef.MaintainableReference.Version
            };

            try
            {
                ISdmxObjects response;

                structure = this.SendQueryStructureRequest(keyFamilyRefBean, resolseRef);
                NsiClientValidation.CheckifStructureComplete(structure, dataflow);
                IEnumerable <IStructureReference> conceptRefs = NsiClientHelper.BuildConceptSchemeRequest(structure.DataStructures.First());
                response = this.SendQueryStructureRequest(conceptRefs, resolseRef);

                structure.Merge(responseDF);
                structure.Merge(response);

                NsiClientValidation.CheckConcepts(structure);
                Logger.Info(Resources.InfoSuccess);
            }
            catch (NsiClientException e)
            {
                Logger.Error(Resources.ExceptionGettingStructure);
                Logger.Error(e.Message, e);
                throw;
            }
            catch (Exception e)
            {
                Logger.Error(Resources.ExceptionGettingStructure);
                Logger.Error(e.Message, e);
                throw new NsiClientException(Resources.ExceptionGettingStructure, e);
            }

            return(structure);
        }
Example #9
0
        public ISdmxObjects GetStructure(string DataflowId, string DatafloAgency, string DatafloVersion, bool resolseRef = false)
        {
            Logger.InfoFormat(
                CultureInfo.InvariantCulture,
                Resources.InfoGettingStructureFormat3,
                DatafloAgency,
                DataflowId,
                DatafloVersion);
            ISdmxObjects structure = new SdmxObjectsImpl();

            #region Dataflow
            // Get dataflows
            ISdmxObjects responseDataflows = new SdmxObjectsImpl();
            string       requestDataFlows  = this.RetrieveDataflow(DataflowId, DatafloAgency, DatafloVersion);
            responseDataflows = this.SendQueryStructureRequest(requestDataFlows);
            // Remove from structure (ISdmxObjects) the DSDS built with SDMX v2.0
            var structureSdmxV20DSD = responseDataflows.DataStructures.Where(o => o.Annotations.Any(a => a.FromAnnotation() == CustomAnnotationType.SDMXv20Only)).ToArray();
            foreach (var sdmxV20Only in structureSdmxV20DSD)
            {
                responseDataflows.RemoveDataStructure(sdmxV20Only);
            }

            // DSDS with annotation
            var sdmxV20onlyReferences = structureSdmxV20DSD.Select(o => o.AsReference).ToArray();

            // Add the DSDS built with Sdmx V2.0
            ISdmxObjects responseDSD = new SdmxObjectsImpl();
            if (sdmxV20onlyReferences.Length > 0)
            {
                responseDSD = this._nsiClientWs.SendQueryStructureRequest(sdmxV20onlyReferences, false);
                responseDataflows.Merge(responseDSD);
            }
            if (responseDataflows.Dataflows == null || responseDataflows.Dataflows.Count == 0)
            {
                throw new Exception("Dataflow not found");
            }
            #endregion

            try
            {
                IDataflowObject dataflow = responseDataflows.Dataflows.First();
                ISdmxObjects    responseConceptScheme = new SdmxObjectsImpl();
                ISdmxObjects    response = new SdmxObjectsImpl();

                IStructureQueryFormat <string> structureQueryFormat = new RestQueryFormat();
                IStructureQueryFactory         factory = new RestStructureQueryFactory();
                IStructureQueryBuilderManager  structureQueryBuilderManager = new StructureQueryBuilderManager(factory);

                IDataStructureObject dsd = NsiClientHelper.GetDsdFromDataflow(dataflow, responseDataflows.DataStructures);
                structure.AddDataStructure(dsd);

                NsiClientValidation.CheckifStructureComplete(structure, dataflow);
                IEnumerable <IStructureReference> conceptRefs = NsiClientHelper.BuildConceptSchemeRequest(structure.DataStructures.First());
                foreach (var structureReference in conceptRefs)
                {
                    IRestStructureQuery structureQuery = new RESTStructureQueryCore(StructureQueryDetail.GetFromEnum(StructureQueryDetailEnumType.Full), StructureReferenceDetail.GetFromEnum(StructureReferenceDetailEnumType.None), null, structureReference, false);
                    string request = structureQueryBuilderManager.BuildStructureQuery(structureQuery, structureQueryFormat);
                    responseConceptScheme = this.SendQueryStructureRequest(request);
                    response.Merge(responseConceptScheme);
                }

                structure.Merge(responseDataflows);
                structure.Merge(response);

                NsiClientValidation.CheckConcepts(structure);
                Logger.Info(Resources.InfoSuccess);
            }
            catch (NsiClientException e)
            {
                Logger.Error(Resources.ExceptionGettingStructure);
                Logger.Error(e.Message, e);
                throw;
            }
            catch (Exception e)
            {
                Logger.Error(Resources.ExceptionGettingStructure);
                Logger.Error(e.Message, e);
                throw new NsiClientException(Resources.ExceptionGettingStructure, e);
            }

            return(structure);
        }