コード例 #1
0
    private bool UpdateNonMAForUploadedDBWithHeader(string DbNId, string UserNId, string DataBaseNId)
    {
        bool RetVal;
        SDMXObjectModel.Message.RegistryInterfaceType Registrations;
        SDMXObjectModel.Message.GenericMetadataType MetadataFiles;
        //SDMXObjectModel.Message.GenericDataType DataFiles;
        SDMXObjectModel.Message.StructureSpecificTimeSeriesDataType DataFiles;

        SDMXObjectModel.Message.RegistryInterfaceType Subscriptions;
        RetVal = true;
        string UploadedHeaderFileWPath = string.Empty;
        string UploadedHeaderFolderPath = Server.MapPath("../../stock/data");
        string UploadedHeaderName = string.Empty;
        string SubscriptionsFolderPath = string.Empty;
        string MetadataFolderPath = string.Empty;
        string RegistrationsFolderPath = string.Empty;
        string SDMXMLFolderPath = string.Empty;
        string MappingFolderPath = string.Empty;
        XmlDocument UploadedHeaderXml = new XmlDocument();
        FileInfo[] Files = null;

        DirectoryInfo dirRegs = null;
        DirectoryInfo dirMetadata = null;
        DirectoryInfo dirSubscriptions = null;
        DirectoryInfo dirSDMXML = null;

        try
        {
            UploadedHeaderFileWPath = UploadedHeaderFolderPath + "/" + DataBaseNId + "/" + "sdmx" + "/" + DevInfo.Lib.DI_LibSDMX.Constants.Header.FileName;
            dirRegs = new DirectoryInfo(UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "Registrations");
            dirMetadata = new DirectoryInfo(UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "Metadata");
            dirSDMXML = new DirectoryInfo(UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "SDMX-ML");
            dirSubscriptions = new DirectoryInfo(UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "Subscriptions");
            MappingFolderPath = UploadedHeaderFolderPath + "/" + DbNId + "/" + "sdmx" + "/" + "Mappings";
            UploadedHeaderXml.Load(UploadedHeaderFileWPath);
            SDMXObjectModel.Message.StructureType UploadedDSDStructure = new SDMXObjectModel.Message.StructureType();
            SDMXObjectModel.Message.StructureHeaderType Header = new SDMXObjectModel.Message.StructureHeaderType();
            SDMXObjectModel.Message.BasicHeaderType BHeader = new SDMXObjectModel.Message.BasicHeaderType();

            UploadedDSDStructure = (SDMXObjectModel.Message.StructureType)SDMXObjectModel.Deserializer.LoadFromXmlDocument(typeof(SDMXObjectModel.Message.StructureType), UploadedHeaderXml);
            Header = UploadedDSDStructure.Header;
            //  BHeader = (SDMXObjectModel.Message.BasicHeaderType)UploadedDSDStructure.Header;
            foreach (DirectoryInfo dirReg in dirRegs.GetDirectories())
            {
                Files = dirReg.GetFiles();
                foreach (FileInfo regfile in Files)
                {
                    Registrations = new SDMXObjectModel.Message.RegistryInterfaceType();

                    Registrations = (SDMXObjectModel.Message.RegistryInterfaceType)Deserializer.LoadFromFile(typeof(SDMXObjectModel.Message.RegistryInterfaceType), UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "Registrations" + "\\" + dirReg.Name + "\\" + regfile.ToString());

                    Registrations.Header.ID = Header.ID.ToString();
                    Registrations.Header.Prepared = Header.Prepared.ToString();
                    foreach (PartyType receiver in Header.Receiver)
                    {
                        Registrations.Header.Receiver.Contact = receiver.Contact;
                        Registrations.Header.Receiver.id = receiver.id;
                        Registrations.Header.Receiver.Name = receiver.Name;
                    }
                    Registrations.Header.Sender = (SDMXObjectModel.Message.SenderType)Header.Sender;
                    Registrations.Header.Test = Header.Test;

                    Registrations.Footer = null;
                    SDMXObjectModel.Serializer.SerializeToFile(typeof(SDMXObjectModel.Message.RegistryInterfaceType), Registrations, UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "Registrations" + "\\" + dirReg.Name + "\\" + regfile.ToString());
                }
            }

            foreach (DirectoryInfo dirMeta in dirMetadata.GetDirectories())
            {
                Files = null;
                Files = dirMeta.GetFiles();
                foreach (FileInfo metafile in Files)
                {
                    MetadataFiles = new SDMXObjectModel.Message.GenericMetadataType();

                    MetadataFiles = (SDMXObjectModel.Message.GenericMetadataType)Deserializer.LoadFromFile(typeof(SDMXObjectModel.Message.GenericMetadataType), UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "Metadata" + "\\" + dirMeta.Name + "\\" + metafile.ToString());

                    MetadataFiles.Header.ID = Header.ID.ToString();
                    MetadataFiles.Header.Prepared = Header.Prepared.ToString();
                    MetadataFiles.Header.Receiver = Header.Receiver;
                    MetadataFiles.Header.Sender = (SDMXObjectModel.Message.SenderType)Header.Sender;
                    MetadataFiles.Header.Test = Header.Test;

                    MetadataFiles.Footer = null;
                    SDMXObjectModel.Serializer.SerializeToFile(typeof(SDMXObjectModel.Message.GenericMetadataType), MetadataFiles, UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "Metadata" + "\\" + dirMeta.Name + "\\" + metafile.ToString());
                }
            }

            foreach (DirectoryInfo dirSDMX in dirSDMXML.GetDirectories())
            {
                Files = null;
                Files = dirSDMX.GetFiles();
                foreach (FileInfo sdmxMlFile in Files)
                {
                    DataFiles = new SDMXObjectModel.Message.StructureSpecificTimeSeriesDataType();

                    DataFiles = (SDMXObjectModel.Message.StructureSpecificTimeSeriesDataType)Deserializer.LoadFromFile(typeof(SDMXObjectModel.Message.StructureSpecificTimeSeriesDataType), UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "SDMX-ML" + "\\" + dirSDMX.Name + "\\" + sdmxMlFile.ToString());

                    DataFiles.Header.ID = Header.ID.ToString();
                    DataFiles.Header.Prepared = Header.Prepared.ToString();
                    DataFiles.Header.Receiver = Header.Receiver;
                    DataFiles.Header.Sender = (SDMXObjectModel.Message.SenderType)Header.Sender;
                    DataFiles.Header.Test = Header.Test;

                    DataFiles.Footer = null;
                    SDMXObjectModel.Serializer.SerializeToFile(typeof(SDMXObjectModel.Message.StructureSpecificTimeSeriesDataType), DataFiles, UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "SDMX-ML" + "\\" + dirSDMX.Name + "\\" + sdmxMlFile.ToString());
                }
            }

            foreach (DirectoryInfo dirSubs in dirSubscriptions.GetDirectories())
            {
                Files = null;
                Files = dirSubs.GetFiles();
                foreach (FileInfo subsFile in Files)
                {
                    Subscriptions = new SDMXObjectModel.Message.RegistryInterfaceType();

                    Subscriptions = (SDMXObjectModel.Message.RegistryInterfaceType)Deserializer.LoadFromFile(typeof(SDMXObjectModel.Message.RegistryInterfaceType), UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "Subscriptions" + "\\" + dirSubs.Name + "\\" + subsFile.ToString());

                    Subscriptions.Header.ID = Header.ID.ToString();
                    Subscriptions.Header.Prepared = Header.Prepared.ToString();
                    foreach (PartyType receiver in Header.Receiver)
                    {
                        Subscriptions.Header.Receiver.Contact = receiver.Contact;
                        Subscriptions.Header.Receiver.id = receiver.id;
                        Subscriptions.Header.Receiver.Name = receiver.Name;
                    }
                    Subscriptions.Header.Sender = (SDMXObjectModel.Message.SenderType)Header.Sender;
                    Subscriptions.Header.Test = Header.Test;

                    Subscriptions.Footer = null;
                    SDMXObjectModel.Serializer.SerializeToFile(typeof(SDMXObjectModel.Message.RegistryInterfaceType), Subscriptions, UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "Subscriptions" + "\\" + dirSubs.Name + "\\" + subsFile.ToString());
                }
            }

        }
        catch (Exception ex)
        {
            RetVal = false;
            Global.CreateExceptionString(ex, null);
            //Global.WriteErrorsInLog("Creating CategoryScheme For Uploaded DSD From Admin");
            //Global.WriteErrorsInLog(ex.StackTrace);
            //Global.WriteErrorsInLog(ex.Message);
        }
        finally
        {

        }

        return RetVal;
    }
コード例 #2
0
        internal override bool Generate_Data(XmlDocument query, string outputFolder, out int fileCount, out List<string> GeneratedFiles, SDMXObjectModel.Message.StructureHeaderType Header)
        {
            bool RetVal;
            string FileName;
            fileCount = 0;
            SDMXObjectModel.Message.StructureSpecificTimeSeriesDataQueryType StructureSpecificTimeSeriesDataQuery;
            StructureSpecificTimeSeriesDataType StructureSpecificTimeSeriesData;
            TimeSeriesDataSetType Dataset;
            SeriesType Series;
            ObsType Obs;
            Dictionary<string, string> DictSeriesAttributes, DictObsAttributes, DictSubgroupBreakup;
            DataTable DtSubgroup, DtSubgroupTypes, DtData, DtDistinctIUS, DtDistinctIUSA;
            string IndicatorGId, UnitGId, SubgroupValGId, AreaID, Source;
            DataRow[] IUSRows, IUSARows;
            GeneratedFiles = new List<string>();
            DateTime CurrentTime = DateTime.Now;
            try
            {
                StructureSpecificTimeSeriesDataQuery = (SDMXObjectModel.Message.StructureSpecificTimeSeriesDataQueryType)Deserializer.LoadFromXmlDocument(typeof(SDMXObjectModel.Message.StructureSpecificTimeSeriesDataQueryType), query);

                this.Parse_Query(StructureSpecificTimeSeriesDataQuery.Query.DataWhere, StructureSpecificTimeSeriesDataQuery.Query.ReturnDetails);
                this.Create_Folder_Structure(outputFolder);

                DtSubgroup = this.DIConnection.ExecuteDataTable(this.DIQueries.SubgroupValSubgroup.GetSubgroupValsWithSubgroups());
                DtSubgroupTypes = this.DIConnection.ExecuteDataTable(this.DIQueries.SubgroupTypes.GetSubgroupTypes(FilterFieldType.None, string.Empty));
                FileName = string.Empty;

                SDMXUtility.Raise_Initilize_Process_Event("Generating SDMX files...", this.Languages.Count, this.Languages.Count);

                if (this.Languages != null && this.Languages.Count > 0)
                {
                    foreach (string language in this.Languages)
                    {
                        this.Set_Area_NIds(language);
                        this.Set_Source_NIds(language);
                        DtDistinctIUS = this.Get_Distinct_IUS_Table(language);
                        DtDistinctIUSA = this.Get_Distinct_IUSA_Table(language);
                        DtData = this.Get_Language_Specific_Data_Table(language);

                        foreach (DataRow DrDistinctIUS in DtDistinctIUS.Rows)
                        {
                            fileCount = fileCount + 1;
                            IndicatorGId = DrDistinctIUS[Indicator.IndicatorGId].ToString();
                            UnitGId = DrDistinctIUS[Unit.UnitGId].ToString();
                            SubgroupValGId = DrDistinctIUS[SubgroupVals.SubgroupValGId].ToString();

                            FileName = Path.Combine(Path.Combine(outputFolder, language), IndicatorGId + Constants.Underscore + UnitGId + Constants.Underscore + SubgroupValGId + "_" + language + "_" + CurrentTime.ToString("yyyy-MM-dd HHmmss") + Constants.XmlExtension);

                            StructureSpecificTimeSeriesData = new StructureSpecificTimeSeriesDataType();
                            StructureSpecificTimeSeriesData.DataSet = new List<TimeSeriesDataSetType>();

                            //StructureSpecificTimeSeriesData.Header = this.Get_Appropriate_Header();

                            if (Header == null)
                            {
                                StructureSpecificTimeSeriesData.Header = this.Get_Appropriate_Header();
                            }
                            else
                            {
                                StructureSpecificTimeSeriesData.Header.ID = Header.ID;
                                StructureSpecificTimeSeriesData.Header.Name = Header.Name;
                                StructureSpecificTimeSeriesData.Header.Prepared = Header.Prepared;
                                StructureSpecificTimeSeriesData.Header.Receiver = Header.Receiver;
                                StructureSpecificTimeSeriesData.Header.Sender = Header.Sender;
                                StructureSpecificTimeSeriesData.Header.Test = Header.Test;
                            }
                            StructureSpecificTimeSeriesData.Header.Structure = new List<SDMXObjectModel.Common.StructureSpecificDataTimeSeriesStructureType>();
                            StructureSpecificTimeSeriesData.Header.Structure.Add(new SDMXObjectModel.Common.StructureSpecificDataTimeSeriesStructureType());

                            StructureSpecificTimeSeriesData.Header.Structure[0].dimensionAtObservation = Constants.Concept.TIME_PERIOD.Id;
                            StructureSpecificTimeSeriesData.Header.Structure[0].structureID = Constants.DSD.Id;
                            StructureSpecificTimeSeriesData.Header.Structure[0].@namespace = Constants.defaultNamespace;

                            StructureSpecificTimeSeriesData.Header.Structure[0].Item = new DataStructureReferenceType();
                            ((DataStructureReferenceType)StructureSpecificTimeSeriesData.Header.Structure[0].Item).Items.Add(new DataStructureRefType());
                            ((DataStructureRefType)((DataStructureReferenceType)StructureSpecificTimeSeriesData.Header.Structure[0].Item).Items[0]).id = Constants.DSD.Id;
                            ((DataStructureRefType)((DataStructureReferenceType)StructureSpecificTimeSeriesData.Header.Structure[0].Item).Items[0]).agencyID = this.AgencyId;
                            ((DataStructureRefType)((DataStructureReferenceType)StructureSpecificTimeSeriesData.Header.Structure[0].Item).Items[0]).version = Constants.DSD.Version;
                            StructureSpecificTimeSeriesData.Footer = null;

                            Dataset = new TimeSeriesDataSetType();
                            StructureSpecificTimeSeriesData.DataSet.Add(Dataset);
                            Dataset.structureRef = Constants.DSD.Id;
                            Dataset.DataProvider = null;
                            Dataset.Annotations = null;
                            Dataset.Items = new List<SDMXObjectModel.Common.AnnotableType>();

                            IUSRows = DtDistinctIUSA.Select(Indicator.IndicatorGId + Constants.EqualsTo + Constants.Apostophe + IndicatorGId + Constants.Apostophe + Constants.AND + Unit.UnitGId + Constants.EqualsTo + Constants.Apostophe + UnitGId + Constants.Apostophe + Constants.AND + SubgroupVals.SubgroupValGId + Constants.EqualsTo + Constants.Apostophe + SubgroupValGId + Constants.Apostophe);

                            foreach (DataRow DrIUS in IUSRows)
                            {
                                AreaID = DrIUS[Area.AreaID].ToString();
                                Source = DrIUS[IndicatorClassifications.ICName].ToString();

                                DictSeriesAttributes = new Dictionary<string, string>();

                                DictSeriesAttributes.Add(Constants.Concept.INDICATOR.Id, IndicatorGId);
                                DictSeriesAttributes.Add(Constants.Concept.UNIT.Id, UnitGId);

                                DictSubgroupBreakup = this.Get_Subgroup_Breakup(SubgroupValGId, DtSubgroup, DtSubgroupTypes);
                                foreach (string Key in DictSubgroupBreakup.Keys)
                                {
                                    DictSeriesAttributes.Add(Key, DictSubgroupBreakup[Key]);
                                }

                                DictSeriesAttributes.Add(Constants.Concept.AREA.Id, AreaID);
                                DictSeriesAttributes.Add(Constants.Concept.SOURCE.Id, Source);

                                Series = new SeriesType(DictSeriesAttributes, null);
                                Dataset.Items.Add(Series);
                                Series.Annotations = null;
                                Series.Obs = new List<ObsType>();

                                IUSARows = DtData.Select(Indicator.IndicatorGId + Constants.EqualsTo + Constants.Apostophe + IndicatorGId + Constants.Apostophe + Constants.AND + Unit.UnitGId + Constants.EqualsTo + Constants.Apostophe + UnitGId + Constants.Apostophe + Constants.AND + SubgroupVals.SubgroupValGId + Constants.EqualsTo + Constants.Apostophe + SubgroupValGId + Constants.Apostophe + Constants.AND + Area.AreaID + Constants.EqualsTo + Constants.Apostophe + AreaID.Replace("'", "''") + Constants.Apostophe + Constants.AND + IndicatorClassifications.ICName + Constants.EqualsTo + Constants.Apostophe + Source.Replace("'", "''") + Constants.Apostophe);

                                foreach (DataRow DrIUSA in IUSARows)
                                {
                                    DictObsAttributes = new Dictionary<string, string>();

                                    DictObsAttributes.Add(Constants.Concept.OBS_VALUE.Id, DrIUSA[DevInfo.Lib.DI_LibDAL.Queries.DIColumns.Data.DataValue].ToString());
                                    DictObsAttributes.Add(Constants.Concept.TIME_PERIOD.Id, DrIUSA[Timeperiods.TimePeriod].ToString());

                                    DictObsAttributes.Add(Constants.Concept.CONFIDENCE_INTERVAL_LOWER.Id, DrIUSA["ConfidenceIntervalLower"].ToString());
                                    DictObsAttributes.Add(Constants.Concept.CONFIDENCE_INTERVAL_UPPER.Id, DrIUSA["ConfidenceIntervalUpper"].ToString());
                                    DictObsAttributes.Add(Constants.Concept.NATURE.Id, DrIUSA["Nature"].ToString());
                                    DictObsAttributes.Add(Constants.Concept.PERIODICITY.Id, DrIUSA["Periodicity"].ToString());
                                    DictObsAttributes.Add(Constants.Concept.DENOMINATOR.Id, DrIUSA[DevInfo.Lib.DI_LibDAL.Queries.DIColumns.Data.DataDenominator].ToString());
                                    DictObsAttributes.Add(Constants.Concept.FOOTNOTES.Id, DrIUSA[DevInfo.Lib.DI_LibDAL.Queries.DIColumns.FootNotes.FootNote].ToString());
                                    Obs = new ObsType(DictObsAttributes);
                                    Series.Obs.Add(Obs);
                                    Obs.Annotations = null;
                                }
                            }

                            Serializer.SerializeToFile(typeof(StructureSpecificTimeSeriesDataType), StructureSpecificTimeSeriesData, FileName);
                            GeneratedFiles.Add(FileName);
                            //-- Raise event for generated file
                            SDMXUtility.Raise_Notify_File_Name_Event(FileName);
                        }
                    }
                }

                RetVal = true;
            }
            catch (Exception ex)
            {
                RetVal = false;
                throw ex;
            }
            finally
            {
            }

            return RetVal;
        }
コード例 #3
0
        internal override XmlDocument Get_Data(XmlDocument query)
        {
            XmlDocument RetVal;
            SDMXObjectModel.Message.StructureSpecificTimeSeriesDataQueryType StructureSpecificTimeSeriesDataQuery;
            StructureSpecificTimeSeriesDataType StructureSpecificTimeSeriesData;
            TimeSeriesDataSetType Dataset;
            SeriesType Series;
            ObsType Obs;
            Dictionary<string, string> DictSeriesAttributes, DictObsAttributes, DictSubgroupBreakup;
            DataTable DtSubgroup, DtSubgroupTypes, DtData, DtDistinctIUSA;
            string IndicatorGId, UnitGId, SubgroupValGId, AreaID, Source;
            DataRow[] IUSARows;

            RetVal = null;
            DtData = null;

            try
            {
                try
                {
                    StructureSpecificTimeSeriesDataQuery = (SDMXObjectModel.Message.StructureSpecificTimeSeriesDataQueryType)Deserializer.LoadFromXmlDocument(typeof(SDMXObjectModel.Message.StructureSpecificTimeSeriesDataQueryType), query);
                }
                catch
                {
                    throw new Exception(Constants.SDMXWebServices.Exceptions.InvalidSyntax.Message);
                }

                this.Parse_Query(StructureSpecificTimeSeriesDataQuery.Query.DataWhere, StructureSpecificTimeSeriesDataQuery.Query.ReturnDetails);

                DtSubgroup = this.DIConnection.ExecuteDataTable(this.DIQueries.SubgroupValSubgroup.GetSubgroupValsWithSubgroups());
                DtSubgroupTypes = this.DIConnection.ExecuteDataTable(this.DIQueries.SubgroupTypes.GetSubgroupTypes(FilterFieldType.None, string.Empty));

                if (this.Languages != null && this.Languages.Count > 0)
                {
                    StructureSpecificTimeSeriesData = new StructureSpecificTimeSeriesDataType();
                    StructureSpecificTimeSeriesData.DataSet = new List<TimeSeriesDataSetType>();

                    StructureSpecificTimeSeriesData.Header = this.Get_Appropriate_Header();
                    StructureSpecificTimeSeriesData.Header.Structure = new List<SDMXObjectModel.Common.StructureSpecificDataTimeSeriesStructureType>();
                    StructureSpecificTimeSeriesData.Header.Structure.Add(new SDMXObjectModel.Common.StructureSpecificDataTimeSeriesStructureType());

                    StructureSpecificTimeSeriesData.Header.Structure[0].dimensionAtObservation = Constants.Concept.TIME_PERIOD.Id;
                    StructureSpecificTimeSeriesData.Header.Structure[0].structureID = Constants.DSD.Id;
                    StructureSpecificTimeSeriesData.Header.Structure[0].@namespace = Constants.defaultNamespace;

                    StructureSpecificTimeSeriesData.Header.Structure[0].Item = new DataStructureReferenceType();
                    ((DataStructureReferenceType)StructureSpecificTimeSeriesData.Header.Structure[0].Item).Items.Add(new DataStructureRefType());
                    ((DataStructureRefType)((DataStructureReferenceType)StructureSpecificTimeSeriesData.Header.Structure[0].Item).Items[0]).id = Constants.DSD.Id;
                    ((DataStructureRefType)((DataStructureReferenceType)StructureSpecificTimeSeriesData.Header.Structure[0].Item).Items[0]).agencyID = this.AgencyId;
                    ((DataStructureRefType)((DataStructureReferenceType)StructureSpecificTimeSeriesData.Header.Structure[0].Item).Items[0]).version = Constants.DSD.Version;
                    StructureSpecificTimeSeriesData.Footer = null;

                    foreach (string language in this.Languages)
                    {
                        Dataset = new TimeSeriesDataSetType();
                        StructureSpecificTimeSeriesData.DataSet.Add(Dataset);
                        Dataset.structureRef = Constants.DSD.Id;
                        Dataset.DataProvider = null;
                        Dataset.Annotations = null;
                        Dataset.Items = new List<SDMXObjectModel.Common.AnnotableType>();

                        this.Set_Area_NIds(language);
                        this.Set_Source_NIds(language);
                        DtDistinctIUSA = this.Get_Distinct_IUSA_Table(language);

                        if (this.DataReturnDetailType == DataReturnDetailTypes.Full)
                        {
                            DtData = this.Get_Language_Specific_Data_Table(language);
                        }

                        foreach (DataRow DrDistinctIUSA in DtDistinctIUSA.Rows)
                        {
                            IndicatorGId = DrDistinctIUSA[Indicator.IndicatorGId].ToString();
                            UnitGId = DrDistinctIUSA[Unit.UnitGId].ToString();
                            SubgroupValGId = DrDistinctIUSA[SubgroupVals.SubgroupValGId].ToString();
                            AreaID = DrDistinctIUSA[Area.AreaID].ToString();
                            Source = DrDistinctIUSA[IndicatorClassifications.ICName].ToString();

                            DictSeriesAttributes = new Dictionary<string, string>();

                            DictSeriesAttributes.Add(Constants.Concept.INDICATOR.Id, IndicatorGId);
                            DictSeriesAttributes.Add(Constants.Concept.UNIT.Id, UnitGId);

                            DictSubgroupBreakup = this.Get_Subgroup_Breakup(SubgroupValGId, DtSubgroup, DtSubgroupTypes);
                            foreach (string Key in DictSubgroupBreakup.Keys)
                            {
                                DictSeriesAttributes.Add(Key, DictSubgroupBreakup[Key]);
                            }

                            DictSeriesAttributes.Add(Constants.Concept.AREA.Id, AreaID);
                            DictSeriesAttributes.Add(Constants.Concept.SOURCE.Id, Source);

                            Series = new SeriesType(DictSeriesAttributes, null);
                            Dataset.Items.Add(Series);
                            Series.Annotations = null;
                            Series.Obs = new List<ObsType>();

                            if (this.DataReturnDetailType == DataReturnDetailTypes.Full)
                            {
                                IUSARows = DtData.Select(Indicator.IndicatorGId + Constants.EqualsTo + Constants.Apostophe + IndicatorGId + Constants.Apostophe + Constants.AND + Unit.UnitGId + Constants.EqualsTo + Constants.Apostophe + UnitGId + Constants.Apostophe + Constants.AND + SubgroupVals.SubgroupValGId + Constants.EqualsTo + Constants.Apostophe + SubgroupValGId + Constants.Apostophe + Constants.AND + Area.AreaID + Constants.EqualsTo + Constants.Apostophe + AreaID.Replace("'", "''") + Constants.Apostophe + Constants.AND + IndicatorClassifications.ICName + Constants.EqualsTo + Constants.Apostophe + Source.Replace("'", "''") + Constants.Apostophe);

                                foreach (DataRow DrIUSA in IUSARows)
                                {
                                    DictObsAttributes = new Dictionary<string, string>();

                                    DictObsAttributes.Add(Constants.Concept.OBS_VALUE.Id, DrIUSA[DevInfo.Lib.DI_LibDAL.Queries.DIColumns.Data.DataValue].ToString());
                                    DictObsAttributes.Add(Constants.Concept.TIME_PERIOD.Id, DrIUSA[Timeperiods.TimePeriod].ToString());

                                    DictObsAttributes.Add(Constants.Concept.CONFIDENCE_INTERVAL_LOWER.Id, DrIUSA["ConfidenceIntervalLower"].ToString());
                                    DictObsAttributes.Add(Constants.Concept.CONFIDENCE_INTERVAL_UPPER.Id, DrIUSA["ConfidenceIntervalUpper"].ToString());
                                    DictObsAttributes.Add(Constants.Concept.NATURE.Id, DrIUSA["Nature"].ToString());
                                    DictObsAttributes.Add(Constants.Concept.PERIODICITY.Id, DrIUSA["Periodicity"].ToString());
                                    DictObsAttributes.Add(Constants.Concept.DENOMINATOR.Id, DrIUSA[DevInfo.Lib.DI_LibDAL.Queries.DIColumns.Data.DataDenominator].ToString());
                                    DictObsAttributes.Add(Constants.Concept.FOOTNOTES.Id, DrIUSA[DevInfo.Lib.DI_LibDAL.Queries.DIColumns.FootNotes.FootNote].ToString());
                                    Obs = new ObsType(DictObsAttributes);
                                    Series.Obs.Add(Obs);
                                    Obs.Annotations = null;
                                }
                            }
                        }
                    }

                    if (StructureSpecificTimeSeriesData != null && StructureSpecificTimeSeriesData.DataSet != null && StructureSpecificTimeSeriesData.DataSet.Count > 0 && StructureSpecificTimeSeriesData.DataSet[0].Items != null && StructureSpecificTimeSeriesData.DataSet[0].Items.Count > 0)
                    {
                        RetVal = Serializer.SerializeToXmlDocument(typeof(StructureSpecificTimeSeriesDataType), StructureSpecificTimeSeriesData);
                    }
                    else
                    {
                        throw new Exception(Constants.SDMXWebServices.Exceptions.NoResults.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                RetVal = null;
                throw ex;
            }
            finally
            {
            }

            return RetVal;
        }
コード例 #4
0
        /// <summary>
        /// Validate_DSD_Compliance method validates a StructureSpecificData object against a DSD(data structure definition) file.
        /// </summary>
        /// <param name="Data">The StructureSpecificData object to be validated.</param>
        /// <param name="completeFileNameWPath">The DSD(data structure definition) file name with path to be used for validation.</param>
        /// <returns>SDMXValidationStatus enum value.</returns>
        private Dictionary<string, string> Validate_DSD_Compliance(StructureSpecificTimeSeriesDataType Data, string completeFileNameWPath)
        {
            Dictionary<string, string> RetVal;

            SDMXObjectModel.Message.StructureType Structure;
            SDMXObjectModel.Data.StructureSpecific.SeriesType Series;
            List<string> ListIndicator, ListUnit, ListArea, ListSource, ListDimensions, ListAttributes;
            Dictionary<string, List<string>> dictSubgroupBreakUp;
            int Counter = 0;

            RetVal = new Dictionary<string, string>();

            try
            {
                // 1. Loading the DSD file in a SDMXApi's Structure object.

                Structure = (SDMXObjectModel.Message.StructureType)(Deserializer.LoadFromFile(typeof(SDMXObjectModel.Message.StructureType), completeFileNameWPath));

                // 2. Initialising various lists e.g. Indicators, Units etc. from the Structure object. These lists represent the codelists
                // contained in Structure object and are later used to validate Series and Obs objects contained in StructureSpecificData object.

                Load_Lists_From_Codelists(Structure, out ListIndicator, out ListUnit, out ListArea,out ListSource, out dictSubgroupBreakUp);

                Load_ListOfDimensionsAtSeriesLevel(Structure, out ListDimensions);

                Load_ListOfAttributesAtObsLevel(Structure, out ListAttributes);

                while (RetVal.Keys.Count == 0 && Counter < Data.DataSet[0].Items.Count)
                {
                    // 3. Extracting a Series object from the StructureSpecificData's DataSet object.
                    Series = ((SeriesType)(Data.DataSet[0].Items[Counter]));

                    // 4. Validating a Series object at a time against the various lists.
                    RetVal = Validate_Series(Series, ListIndicator, ListUnit, ListArea, ListSource, dictSubgroupBreakUp, ListDimensions, ListAttributes);
                    Counter++;

                }

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return RetVal;
        }
コード例 #5
0
        /// <summary>
        /// Validate_And_Load_Datafile method:
        /// 1. Validates the SDMX-ML data file for:
        ///     1.1. Well formed xml.
        ///     1.2. The SDMX-ML data file's compliance to SDMX schemas.
        /// 2. Loads a StructureSpecificData object after successful valdations of SDMX-ML data file.
        /// </summary>
        /// <param name="dataFileNameWPath">The SDMX-ML file name with path to be validated.</param>
        /// <param name="Data">The StructureSpecificData object to be loaded if the SDMX-ML data file is found valid for the above-mentioned two 
        /// validations.</param>
        /// <returns>SDMXValidationStatus enum value.</returns>
        private Dictionary<string, string> Validate_And_Load_Datafile(string dataFileNameWPath, out StructureSpecificTimeSeriesDataType Data)
        {
            Dictionary<string, string> RetVal;
            XmlDocument Document;

            RetVal = new Dictionary<string, string>();
            Data = null;
            Document = null;

            try
            {
                // 1. Validating the SDMX-ML data file:
                RetVal = Validate_XML(dataFileNameWPath, out Document);

                if (RetVal.Keys.Count == 0)
                {
                    RetVal = Validate_SDMX(Document.InnerXml);
                }

                // 2. Loading the SDMX-ML data file in the CompactData object on successful validation against SDMX schemas.

                if (RetVal.Keys.Count == 0)
                {
                    Data = (StructureSpecificTimeSeriesDataType)(Deserializer.LoadFromXmlDocument(typeof(StructureSpecificTimeSeriesDataType), Document));
                }

            }
            catch (Exception ex)
            {
                // An exception while loading the SDMX-ML data file in a CompactData object implies invalid SDMX structure.
                if (ex is System.InvalidOperationException)
                {
                    RetVal.Add(SDMXValidationStatus.SDMX_Invalid.ToString(), ex.InnerException.Message.ToString());
                }
                // All other exceptions e.g System.IO exceptions are thrown to be handled by using code.
                else
                {
                    throw ex;
                }
            }

            return RetVal;
        }
コード例 #6
0
    /// <summary>
    /// Process SDMX-ML file with complete DSD to make csv file
    /// </summary>
    /// <param name="sdmxSeries">Series nodes in SDMX-ML </param>
    /// <param name="DSD">DSD Object</param>
    /// <param name="lngCode">language code</param>
    /// <param name="csvFilepath">CSV file path</param>
    /// <returns></returns>
    private string processSDMXFileWithDSD(StructureSpecificTimeSeriesDataType sdmxSeries, SDMXObjectModel.Message.StructureType DSD, string lngCode, string csvFilepath)
    {
        string result = string.Empty;
        string codeListCode = string.Empty;
        string attributeID = string.Empty;
        string value = string.Empty;
        string obsValue = string.Empty;
        string timePeriod = string.Empty;
        List<string> dataForCSV = new List<string>();
        string dataRow = string.Empty;
        string seperator = "{@@}";
        SeriesType series = null;
        int i = 0;
        // Make heading row
        series = (SeriesType)sdmxSeries.DataSet[0].Items[i];
        for (int j = 0; j < series.AnyAttr.Count; j++)
        {
            XmlAttribute seriesAttr = series.AnyAttr[j];
            dataRow += seperator + seriesAttr.Name;
        }
        /*for (int c = 0; c < series.Obs[0].AnyAttr.Count; c++)
        {
            dataRow += seperator + series.Obs[0].AnyAttr[c].Name;
        }*/
        dataRow += seperator + "OBS_VALUE" + seperator + "Time_Period";
        dataRow = dataRow.Substring(4);
        dataForCSV.Add(dataRow);

        for (i = 0; i < sdmxSeries.DataSet[0].Items.Count; i++)
        {
            dataRow = string.Empty;
            string tempDataRow = string.Empty;
            series = (SeriesType)sdmxSeries.DataSet[0].Items[i];
            for (int j = 0; j < series.AnyAttr.Count; j++)
            {
                XmlAttribute seriesAttr = series.AnyAttr[j];
                attributeID = seriesAttr.Value;
                switch (seriesAttr.Name)
                {
                    case Constants.MyData.INDICATOR:
                        codeListCode = "CL_INDICATOR";
                        break;
                    case Constants.MyData.UNIT:
                        codeListCode = "CL_UNIT";
                        break;
                    case Constants.MyData.LOCATION:
                        codeListCode = "CL_LOCATION";
                        break;
                    case Constants.MyData.SEX:
                        codeListCode = "CL_SEX";
                        break;
                    case Constants.MyData.AGE:
                        codeListCode = "CL_AGE";
                        break;
                    case Constants.MyData.OTHER:
                        codeListCode = "CL_OTHER";
                        break;
                    case Constants.MyData.AREA:
                        codeListCode = "CL_AREA";
                        break;
                    case Constants.MyData.SOURCE:
                        codeListCode = "CL_SOURCE";
                        break;
                }
                value = getCorrespondingValueByIdAndType(DSD, codeListCode, attributeID, lngCode);
                dataRow += seperator + value;
            }
            dataRow = dataRow.Substring(4);
            //tempDataRow = dataRow.Substring(4);
            if (series.Obs.Count > 0) // Reading Obs nodes
            {
                for (int k = 0; k < series.Obs.Count; k++)
                {
                    tempDataRow = dataRow;
                    /*for (int c = 0; c < series.Obs[k].AnyAttr.Count; c++)
                    {
                        tempDataRow += seperator + series.Obs[k].AnyAttr[c].Value;
                    }*/
                    tempDataRow += seperator + series.Obs[k].OBS_VALUE + seperator + series.Obs[k].TIME_PERIOD;
                    dataForCSV.Add(tempDataRow);
                }
            }
        }
        result = createCSV_By_SdmxMl(dataForCSV, csvFilepath);
        return result;
    }