private bool UpdateNonMAForUploadedDSDWithHeader(string DbNId, string UserNId, string DataBaseNId) { bool RetVal; SDMXObjectModel.Message.RegistryInterfaceType Registrations; SDMXApi_2_0.Message.GenericMetadataType MetadataFiles; //SDMXObjectModel.Message.GenericDataType DataFiles; SDMXApi_2_0.Message.CompactDataType DataFiles; SDMXObjectModel.Message.RegistryInterfaceType Subscriptions; RetVal = true; string UploadedHeaderFileWPath = string.Empty; string UploadedHeaderFolderPath = Server.MapPath("../../stock/data"); string UploadedDSDHeaderFilePath = string.Empty; 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(); XmlDocument UploadedHeaderXmlFor2_0 = 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; UploadedDSDHeaderFilePath = UploadedHeaderFolderPath + "/" + DbNId + "/" + "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); UploadedHeaderXmlFor2_0.Load(UploadedDSDHeaderFilePath); SDMXObjectModel.Message.StructureType UploadedDSDStructure = new SDMXObjectModel.Message.StructureType(); SDMXObjectModel.Message.StructureHeaderType Header = new SDMXObjectModel.Message.StructureHeaderType(); SDMXApi_2_0.Message.StructureType UploadedDSDStruct20 = new SDMXApi_2_0.Message.StructureType(); SDMXApi_2_0.Message.HeaderType DSDHeader = new SDMXApi_2_0.Message.HeaderType(); UploadedDSDStructure = (SDMXObjectModel.Message.StructureType)SDMXObjectModel.Deserializer.LoadFromXmlDocument(typeof(SDMXObjectModel.Message.StructureType), UploadedHeaderXml); Header = UploadedDSDStructure.Header; UploadedDSDStruct20 = (SDMXApi_2_0.Message.StructureType)SDMXApi_2_0.Deserializer.LoadFromXmlDocument(typeof(SDMXApi_2_0.Message.StructureType), UploadedHeaderXmlFor2_0); DSDHeader = UploadedDSDStruct20.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 SDMXApi_2_0.Message.GenericMetadataType(); MetadataFiles = (SDMXApi_2_0.Message.GenericMetadataType)Deserializer.LoadFromFile(typeof(SDMXApi_2_0.Message.GenericMetadataType), UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "Metadata" + "\\" + dirMeta.Name + "\\" + metafile.ToString()); MetadataFiles.Header.ID = DSDHeader.ID.ToString(); MetadataFiles.Header.Prepared = DSDHeader.Prepared.ToString(); MetadataFiles.Header.Receiver = DSDHeader.Receiver; MetadataFiles.Header.Sender = DSDHeader.Sender; MetadataFiles.Header.Test = DSDHeader.Test; SDMXApi_2_0.Serializer.SerializeToFile(typeof(SDMXApi_2_0.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 SDMXApi_2_0.Message.CompactDataType(); DataFiles = (SDMXApi_2_0.Message.CompactDataType)Deserializer.LoadFromFile(typeof(SDMXApi_2_0.Message.CompactDataType), UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "SDMX-ML" + "\\" + dirSDMX.Name + "\\" + sdmxMlFile.ToString()); DataFiles.Header.ID = DSDHeader.ID.ToString(); DataFiles.Header.Prepared = Header.Prepared.ToString(); DataFiles.Header.Receiver = DSDHeader.Receiver; DataFiles.Header.Sender = DSDHeader.Sender; DataFiles.Header.Test = DSDHeader.Test; SDMXApi_2_0.Serializer.SerializeToFile(typeof(SDMXApi_2_0.Message.CompactDataType), 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; }
private static Dictionary<string, string> Validate_DSD_Compliance(CompactDataType Data, string dsdFileNameWPath) { Dictionary<string, string> RetVal; StructureType Structure; SDMXApi_2_0.CompactData.SeriesType Series; List<string> ListFrequency, ListIndicator, ListUnit, ListLocation, ListAge, ListSex, ListArea, ListSourceType, ListNature, ListUnitMult; int Counter = 0; RetVal = new Dictionary<string, string>(); try { // 1. Loading the DSD file in a SDMXApi's Structure object. Structure = ((StructureType)(SDMXApi_2_0.Deserializer.LoadFromFile(typeof(StructureType), dsdFileNameWPath))); // 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 CompactData object. Load_Lists_From_Codelists(Structure, out ListFrequency, out ListIndicator, out ListUnit, out ListLocation, out ListAge, out ListSex, out ListArea, out ListSourceType, out ListNature, out ListUnitMult); while (RetVal.Keys.Count == 0 && Counter < Data.DataSet.ListSeries.Count) { // 3. Extracting a Series object from the CompactData's DataSet object. Series = Data.DataSet.ListSeries[Counter]; // 4. Validating a Series object at a time against the various lists. RetVal = Validate_Series(Series, ListFrequency, ListIndicator, ListUnit, ListLocation, ListAge, ListSex, ListArea, ListSourceType, ListNature, ListUnitMult); Counter++; } } catch (Exception ex) { Global.CreateExceptionString(ex, null); throw ex; } return RetVal; }
/// <summary> /// Generate_Data for Country DSD SDMX-ML v2.0 /// </summary> /// <param name="DictMapping">Key - DevInfo GId; Value - UNSD GID</param> /// <param name="OutputFolder">SDMX-ML folder path</param> /// <param name="DIConnection"></param> /// <param name="DIQueries"></param> /// <param name="fileCount">Return Count of SDMX-ML files generated for all language</param> /// <param name="AreaId"></param> /// <param name="DBOrDSDDBId">dbnid of devinfo database / country dsd</param> /// <param name="GeneratedFiles">list unique SDMX-ML file generated (single file name for multiple language)</param> /// <param name="HeaderfilePath"></param> /// <param name="xml">In case of optimize database - user selection through databuplish xml</param> /// <param name="DuplicateKey">Return knowldege of Duplicate key for indicator and time</param> /// <param name="dtSelections">In case of Register - user selection in form of datatable [ind, Area]</param> /// <param name="ErrorLogs">Return indicator@@Timeperiod}} </param> /// <param name="GeneratedIndicatorCountryGIDS">Return list of Country GUID for which files have been generated</param> /// <returns></returns> internal static bool Generate_Data(Dictionary<string, string> DictMapping, string OutputFolder, DIConnection DIConnection, DIQueries DIQueries, string AreaId, string DBOrDSDDBId, string HeaderfilePath, string xml, DataTable dtSelections, out int fileCount, out List<string> GeneratedFiles, out string ErrorLogs, out string DuplicateKey) { bool RetVal; string Language; string IndicatorGId, UnitGId, SGVGId, AreaID; string AreaNIds, TPNIds, SourceNIds; string SeriesValue, Unit, Age, Sex, Location, Frequency, SourceType, Nature, UnitMult, TimePeriod, ObsVal, TimeDetail, SourceDetail, Footnotes, IndicatorName; ErrorLogs = string.Empty; List<string> ProcessedIUSA; DataTable DtData; DataRow[] IUSARows; DataRow[] CheckDuplicateKeys; XmlDocument AttributesDoc; System.Xml.XmlAttribute Attribute; CompactDataType CompactData; SDMXApi_2_0.CompactData.SeriesType Series; SDMXApi_2_0.CompactData.ObsType Obs; Dictionary<string, string> DictAreaMapping; DateTime CurrentTime; RetVal = true; fileCount = 0; Language = string.Empty; IndicatorGId = string.Empty; UnitGId = string.Empty; SGVGId = string.Empty; AreaID = string.Empty; SeriesValue = string.Empty; Unit = string.Empty; Age = string.Empty; Sex = string.Empty; Location = string.Empty; Frequency = string.Empty; SourceType = string.Empty; Nature = string.Empty; UnitMult = string.Empty; TimePeriod = string.Empty; ObsVal = string.Empty; TimeDetail = string.Empty; SourceDetail = string.Empty; Footnotes = string.Empty; int RowCount = 0; ProcessedIUSA = new List<string>(); DtData = null; IUSARows = null; CheckDuplicateKeys = null; AttributesDoc = null; Attribute = null; CompactData = null; Series = null; Obs = null; DictAreaMapping = null; CurrentTime = DateTime.Now; IndicatorName = string.Empty; XmlDocument UploadedHeaderXml = new XmlDocument(); DataSet ds = new DataSet(); SDMXApi_2_0.Message.StructureType UploadedDSDStructure = new SDMXApi_2_0.Message.StructureType(); SDMXApi_2_0.Message.HeaderType Header = new SDMXApi_2_0.Message.HeaderType(); DuplicateKey = string.Empty; DataTable dtIndicator = new DataTable(); if (File.Exists(HeaderfilePath)) { UploadedHeaderXml.Load(HeaderfilePath); UploadedDSDStructure = (SDMXApi_2_0.Message.StructureType)SDMXApi_2_0.Deserializer.LoadFromXmlDocument(typeof(SDMXApi_2_0.Message.StructureType), UploadedHeaderXml); Header = UploadedDSDStructure.Header; } GeneratedFiles = new List<string>(); if (dtSelections != null && dtSelections.Rows.Count > 0) { // register tab ds.Tables.Add(dtSelections); } else { // Admin if (File.Exists(xml)) { ds.ReadXml(xml); } } string IndicatorNId = string.Empty; // for each language in database foreach (DataRow LanguageRow in DIConnection.DILanguages(DIQueries.DataPrefix).Rows) { // Language = LanguageRow[DevInfo.Lib.DI_LibDAL.Queries.DIColumns.Language.LanguageCode].ToString(); int dsRowCount = ds.Tables["Data"].Rows.Count; RowCount = 0; // consider only those indiactors which are selected foreach (DataRow DSRow in ds.Tables["Data"].Select("selectedState=true")) { if (RowCount > dsRowCount) { break; } IndicatorNId = DSRow["Ind"].ToString(); AreaNIds = DSRow["areas"].ToString(); TPNIds = DSRow["timeperiods"].ToString(); SourceNIds = DSRow["source"].ToString(); // Get data based on Indiactor and associated fileters DtData = Get_Language_Specific_Data_Table(Language, IndicatorNId, AreaNIds, TPNIds, SourceNIds, DIConnection); dtIndicator = DIConnection.ExecuteDataTable(DIQueries.Indicators.GetIndicator(FilterFieldType.NId, IndicatorNId, FieldSelection.Heavy)); foreach (DataRow drIndicator in dtIndicator.Rows) { IndicatorName = drIndicator[Indicator.IndicatorName].ToString(); } ProcessedIUSA = new List<string>(); DictAreaMapping = RegTwoZeroFunctionality.Get_Area_Mapping_Dict(Convert.ToInt32(DBOrDSDDBId)); if ((DtData != null) && (DtData.Rows.Count > 0)) { fileCount += 1; CompactData = new CompactDataType(); if (!File.Exists(HeaderfilePath)) { CompactData.Header = RegTwoZeroFunctionality.Get_Appropriate_Header(); } else { CompactData.Header = Header; } CompactData.DataSet = new SDMXApi_2_0.CompactData.DataSetType(); CompactData.DataSet.ListSeries = new List<SDMXApi_2_0.CompactData.SeriesType>(); // for each data value for indicator foreach (DataRow DrData in DtData.Rows) { IndicatorGId = DrData[Indicator.IndicatorGId].ToString(); UnitGId = DrData[DevInfo.Lib.DI_LibDAL.Queries.DIColumns.Unit.UnitGId].ToString(); SGVGId = DrData[SubgroupVals.SubgroupValGId].ToString(); if (DictAreaMapping.ContainsKey(DrData[Area.AreaID].ToString())) { AreaId = DictAreaMapping[DrData[DevInfo.Lib.DI_LibDAL.Queries.DIColumns.Area.AreaID].ToString()]; } else { AreaId = DrData[DevInfo.Lib.DI_LibDAL.Queries.DIColumns.Area.AreaID].ToString(); } // AreaID = DrData[Area.AreaID].ToString(); AreaID = AreaId; if (string.IsNullOrEmpty(AreaID) == true) { AreaID = Global.registryMSDAreaId; } if (!DictMapping.ContainsKey(IndicatorGId + "@__@" + UnitGId + "@__@" + SGVGId)) { continue; } // Replace DI GUIDs with Coutry data GIDs based on mapping SeriesValue = DictMapping[IndicatorGId + "@__@" + UnitGId + "@__@" + SGVGId].Split(new string[] { "@__@" }, StringSplitOptions.None)[0]; Unit = DictMapping[IndicatorGId + "@__@" + UnitGId + "@__@" + SGVGId].Split(new string[] { "@__@" }, StringSplitOptions.None)[1]; Age = DictMapping[IndicatorGId + "@__@" + UnitGId + "@__@" + SGVGId].Split(new string[] { "@__@" }, StringSplitOptions.None)[2]; Sex = DictMapping[IndicatorGId + "@__@" + UnitGId + "@__@" + SGVGId].Split(new string[] { "@__@" }, StringSplitOptions.None)[3]; Location = DictMapping[IndicatorGId + "@__@" + UnitGId + "@__@" + SGVGId].Split(new string[] { "@__@" }, StringSplitOptions.None)[4]; Frequency = DictMapping[IndicatorGId + "@__@" + UnitGId + "@__@" + SGVGId].Split(new string[] { "@__@" }, StringSplitOptions.None)[5]; SourceType = DictMapping[IndicatorGId + "@__@" + UnitGId + "@__@" + SGVGId].Split(new string[] { "@__@" }, StringSplitOptions.None)[6]; Nature = DictMapping[IndicatorGId + "@__@" + UnitGId + "@__@" + SGVGId].Split(new string[] { "@__@" }, StringSplitOptions.None)[7]; UnitMult = DictMapping[IndicatorGId + "@__@" + UnitGId + "@__@" + SGVGId].Split(new string[] { "@__@" }, StringSplitOptions.None)[8]; // If series item already exists if (ProcessedIUSA.Contains(IndicatorGId + "@__@" + UnitGId + "@__@" + SGVGId + "@__@" + AreaID)) { continue; } else { ProcessedIUSA.Add(IndicatorGId + "@__@" + UnitGId + "@__@" + SGVGId + "@__@" + AreaID); Series = new SDMXApi_2_0.CompactData.SeriesType(); Series.AnyAttr = new List<XmlAttribute>(); AttributesDoc = new XmlDocument(); Attribute = AttributesDoc.CreateAttribute(Constants.UNSD.Concept.Indicator.Id); Attribute.Value = SeriesValue; Series.AnyAttr.Add(Attribute); Attribute = AttributesDoc.CreateAttribute(Constants.UNSD.Concept.Unit.Id); Attribute.Value = Unit; Series.AnyAttr.Add(Attribute); Attribute = AttributesDoc.CreateAttribute(Constants.UNSD.Concept.Age.Id); Attribute.Value = Age; Series.AnyAttr.Add(Attribute); Attribute = AttributesDoc.CreateAttribute(Constants.UNSD.Concept.Sex.Id); Attribute.Value = Sex; Series.AnyAttr.Add(Attribute); Attribute = AttributesDoc.CreateAttribute(Constants.UNSD.Concept.Location.Id); Attribute.Value = Location; Series.AnyAttr.Add(Attribute); Attribute = AttributesDoc.CreateAttribute(Constants.UNSD.Concept.Frequency.Id); Attribute.Value = Frequency; Series.AnyAttr.Add(Attribute); Attribute = AttributesDoc.CreateAttribute(Constants.UNSD.Concept.SourceType.Id); Attribute.Value = SourceType; Series.AnyAttr.Add(Attribute); Attribute = AttributesDoc.CreateAttribute(Constants.UNSD.Concept.Area.Id); Attribute.Value = AreaID; Series.AnyAttr.Add(Attribute); IUSARows = DtData.Select(Indicator.IndicatorGId + SDMXLibrary.Constants.EqualsTo + SDMXLibrary.Constants.Apostophe + IndicatorGId + SDMXLibrary.Constants.Apostophe + SDMXLibrary.Constants.AND + DevInfo.Lib.DI_LibDAL.Queries.DIColumns.Unit.UnitGId + SDMXLibrary.Constants.EqualsTo + SDMXLibrary.Constants.Apostophe + UnitGId + SDMXLibrary.Constants.Apostophe + SDMXLibrary.Constants.AND + SubgroupVals.SubgroupValGId + SDMXLibrary.Constants.EqualsTo + SDMXLibrary.Constants.Apostophe + SGVGId + SDMXLibrary.Constants.Apostophe + SDMXLibrary.Constants.AND + Area.AreaID + SDMXLibrary.Constants.EqualsTo + SDMXLibrary.Constants.Apostophe + DrData[Area.AreaID].ToString() + SDMXLibrary.Constants.Apostophe); Series.ListObs = new List<SDMXApi_2_0.CompactData.ObsType>(); foreach (DataRow IUSARow in IUSARows) { TimePeriod = Get_Time_Period_Start_Year(Convert.ToString(IUSARow[Timeperiods.TimePeriod])); CheckDuplicateKeys = DtData.Select(Indicator.IndicatorGId + SDMXLibrary.Constants.EqualsTo + SDMXLibrary.Constants.Apostophe + IndicatorGId + SDMXLibrary.Constants.Apostophe + SDMXLibrary.Constants.AND + DevInfo.Lib.DI_LibDAL.Queries.DIColumns.Unit.UnitGId + SDMXLibrary.Constants.EqualsTo + SDMXLibrary.Constants.Apostophe + UnitGId + SDMXLibrary.Constants.Apostophe + SDMXLibrary.Constants.AND + SubgroupVals.SubgroupValGId + SDMXLibrary.Constants.EqualsTo + SDMXLibrary.Constants.Apostophe + SGVGId + SDMXLibrary.Constants.Apostophe + SDMXLibrary.Constants.AND + Area.AreaID + SDMXLibrary.Constants.EqualsTo + SDMXLibrary.Constants.Apostophe + DrData[Area.AreaID].ToString() + SDMXLibrary.Constants.Apostophe + SDMXLibrary.Constants.AND + Timeperiods.TimePeriod + SDMXLibrary.Constants.EqualsTo + SDMXLibrary.Constants.Apostophe + TimePeriod + SDMXLibrary.Constants.Apostophe); ObsVal = IUSARow[Data.DataValue].ToString(); TimeDetail = IUSARow[Timeperiods.TimePeriod].ToString(); SourceDetail = IUSARow[IndicatorClassifications.ICName].ToString(); Footnotes = IUSARow[FootNotes.FootNote].ToString(); Obs = new SDMXApi_2_0.CompactData.ObsType(); Obs.AnyAttr = new List<XmlAttribute>(); AttributesDoc = new XmlDocument(); Attribute = AttributesDoc.CreateAttribute(Constants.UNSD.Concept.Nature.Id); Attribute.Value = Nature; Obs.AnyAttr.Add(Attribute); Attribute = AttributesDoc.CreateAttribute(Constants.UNSD.Concept.UnitMult.Id); Attribute.Value = UnitMult; Obs.AnyAttr.Add(Attribute); Attribute = AttributesDoc.CreateAttribute(Constants.UNSD.Concept.TimePeriod.Id); Attribute.Value = TimePeriod; Obs.AnyAttr.Add(Attribute); Attribute = AttributesDoc.CreateAttribute(Constants.UNSD.Concept.ObsVal.Id); Attribute.Value = ObsVal; Obs.AnyAttr.Add(Attribute); Attribute = AttributesDoc.CreateAttribute(Constants.UNSD.Concept.TimeDetail.Id); Attribute.Value = TimeDetail; Obs.AnyAttr.Add(Attribute); Attribute = AttributesDoc.CreateAttribute(Constants.UNSD.Concept.SourceDetail.Id); Attribute.Value = SourceDetail; Obs.AnyAttr.Add(Attribute); Attribute = AttributesDoc.CreateAttribute(Constants.UNSD.Concept.Footnotes.Id); Attribute.Value = Footnotes; Obs.AnyAttr.Add(Attribute); Series.ListObs.Add(Obs); } CompactData.DataSet.ListSeries.Add(Series); } } if (CheckDuplicateKeys.Count() <= 1) { SDMXApi_2_0.Serializer.SerializeToFile(typeof(CompactDataType), CompactData, Path.Combine(Path.Combine(OutputFolder, Language), Convert.ToString(SeriesValue + "_DI_" + IndicatorGId) + DevInfo.Lib.DI_LibSDMX.Constants.XmlExtension)); GeneratedFiles.Add(Convert.ToString(SeriesValue + "_DI_" + IndicatorGId)); } else { fileCount -= 1; if (string.IsNullOrEmpty(DuplicateKey)) { DuplicateKey += "DK" + Constants.Delimiters.ParamDelimiter + "INDICATOR: " + IndicatorName + "__@@@@__" + "TIMEPERIOD: " + TimePeriod + Constants.Delimiters.ParamDelimiter; } else { DuplicateKey += "DK" + Constants.Delimiters.ParamDelimiter + "INDICATOR: " + IndicatorName + "__@@@@__" + "TIMEPERIOD: " + TimePeriod + Constants.Delimiters.ParamDelimiter; } XLSLogGenerator.WriteCSVLogForMailStatus("Error found while publishing data", IndicatorName, "File not published for the given IndicatorGId and Timeperiod", DuplicateKey); } } else { // to find indicator gid DtData = Get_Language_Specific_Data_Table(Language, IndicatorNId, string.Empty, string.Empty, string.Empty, DIConnection); if (string.IsNullOrEmpty(IndicatorName)) { ErrorLogs += "NDF" + Constants.Delimiters.ParamDelimiter + IndicatorName + Constants.Delimiters.ParamDelimiter; XLSLogGenerator.WriteCSVLogForMailStatus("No data found", IndicatorName, "File not published", IndicatorName); } else { if (ErrorLogs.Contains(IndicatorName)) { continue; } else { if (string.IsNullOrEmpty(ErrorLogs)) { ErrorLogs += "NDF" + Constants.Delimiters.ParamDelimiter + IndicatorName + Constants.Delimiters.ParamDelimiter; } else { ErrorLogs += "NDF" + Constants.Delimiters.ParamDelimiter + IndicatorName + Constants.Delimiters.ParamDelimiter; } XLSLogGenerator.WriteCSVLogForMailStatus("No data found for ", IndicatorName, "File not published for the given IndicatorGId", IndicatorName); } } } RowCount += 1; } } RetVal = true; return RetVal; }
private static Dictionary<string, string> Validate_And_Load_Datafile(string dataFileNameWPath, out CompactDataType Data) { Dictionary<string, string> RetVal; XmlDocument Document; RetVal = new Dictionary<string, string>(); Data = null; Document = new XmlDocument(); try { // 1. Validating the SDMX-ML data file for: // 1.1. Well formed xml. // 1.2. The SDMX-ML data file's compliance to SDMX schemas. RetVal = Validate_XML_And_SDMX_Header(dataFileNameWPath); // 2. Loading the SDMX-ML data file in the CompactData object on successful validation against SDMX schemas. if (RetVal.Keys.Count == 0) { Document.Load(dataFileNameWPath); Data = ((CompactDataType)(SDMXApi_2_0.Deserializer.LoadFromXmlDocument(typeof(CompactDataType), Document))); } } catch (Exception ex) { Global.CreateExceptionString(ex, null); // An exception while loading the SDMX-ML data file in a CompactData object implies invalid SDMX structure. if (ex.InnerException 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; }