public void SetJsonStructureDescriptions(IDataflowObject dataflow, RetreiveCodelistDelegate RetrieveCodelist) { foreach (var x in _dsd.DimensionList.Dimensions) { string codelist = ""; string agenzia = ""; string versione = ""; if (!(x.Representation == null)) { ISet <ICrossReference> isr = x.Representation.CrossReferences; foreach (var y in isr) { codelist = y.MaintainableReference.MaintainableId; agenzia = y.MaintainableReference.AgencyId; versione = y.MaintainableReference.Version; } List <ICodelistObject> codelists = null; if (string.IsNullOrEmpty(codelist) && x.TimeDimension) { codelists = RetrieveCodelist("MA", "CL_TIME_PERIOD", "1.0", dataflow, x.Id); } else { codelists = RetrieveCodelist(agenzia, codelist, versione, dataflow, x.Id); } foreach (var serie in this.JsonStruct.Series) { foreach (var value in serie.Values) { foreach (var codeBean in codelists) { foreach (var codeBeanItem in codeBean.Items) { if (codeBeanItem.Id == value.Id) { foreach (var item in codeBeanItem.Names) { if (item.Locale == "en") { value.Descr = item.Value; } } break; } } } } } } } foreach (var x in _dsd.DatasetAttributes) { string codelist = ""; string agenzia = ""; string versione = ""; if (!(x.Representation == null)) { ISet <ICrossReference> isr = x.Representation.CrossReferences; foreach (var y in isr) { codelist = y.MaintainableReference.MaintainableId; agenzia = y.MaintainableReference.AgencyId; versione = y.MaintainableReference.Version; } List <ICodelistObject> codelists = RetrieveCodelist(agenzia, codelist, versione, dataflow, x.Id); foreach (var att in this.JsonStruct.Attributes) { if (att.AttachmentLevel == "DataSet") { foreach (var value in att.Values) { foreach (var codeBean in codelists) { foreach (var codeBeanItem in codeBean.Items) { if (codeBeanItem.Id == value.Id) { foreach (var item in codeBeanItem.Names) { if (item.Locale == "en") { value.Descr = item.Value; } } break; } } } } } } } } foreach (var x in _dsd.GroupAttributes) { string codelist = ""; string agenzia = ""; string versione = ""; if (!(x.Representation == null)) { ISet <ICrossReference> isr = x.Representation.CrossReferences; foreach (var y in isr) { codelist = y.MaintainableReference.MaintainableId; agenzia = y.MaintainableReference.AgencyId; versione = y.MaintainableReference.Version; } List <ICodelistObject> codelists = RetrieveCodelist(agenzia, codelist, versione, dataflow, x.Id); foreach (var att in this.JsonStruct.Attributes) { if (att.AttachmentLevel == "Group") { foreach (var value in att.Values) { foreach (var codeBean in codelists) { foreach (var codeBeanItem in codeBean.Items) { if (codeBeanItem.Id == value.Id) { foreach (var item in codeBeanItem.Names) { if (item.Locale == "en") { value.Descr = item.Value; } } break; } } } } } } } } foreach (var x in _dsd.ObservationAttributes) { string codelist = ""; string agenzia = ""; string versione = ""; if (!(x.Representation == null)) { ISet <ICrossReference> isr = x.Representation.CrossReferences; foreach (var y in isr) { codelist = y.MaintainableReference.MaintainableId; agenzia = y.MaintainableReference.AgencyId; versione = y.MaintainableReference.Version; } List <ICodelistObject> codelists = RetrieveCodelist(agenzia, codelist, versione, dataflow, x.Id); foreach (var att in this.JsonStruct.Attributes) { if (att.AttachmentLevel == "Observation") { foreach (var value in att.Values) { foreach (var codeBean in codelists) { foreach (var codeBeanItem in codeBean.Items) { if (codeBeanItem.Id == value.Id) { foreach (var item in codeBeanItem.Names) { if (item.Locale == "en") { value.Descr = item.Value; } } break; } } } } } } } } }
public void StartDataset(IDataflowObject dataflow, IDataStructureObject dsd, RetreiveCodelistDelegate RetreiveCodelist) { myDsplStructure._info.Names = new List <DsplStructure.Name>(); myDsplStructure._info.Descriptions = new List <DsplStructure.Name>(); myDsplStructure._info.Languages = new List <DsplStructure.Languages>(); myDsplStructure._provider.Names = new List <DsplStructure.Name>(); foreach (var item in dataflow.Names) { var names = new DsplStructure.Name(); names.name = item.Value; names.lang = item.Locale; //info myDsplStructure._info.Names.Add(names); myDsplStructure._info.url = GetWebConfigInfo("urlAddress"); //provider myDsplStructure._provider.Names.Add(names); myDsplStructure._provider.url = GetWebConfigInfo("urlAddress"); } myDsplStructure._info.Languages = VerifyNames(dataflow); myDsplStructure._info.description = dsd.Id; var topic = new DsplStructure.Topic(); topic.id = dataflow.Name.PadRight(64); topic.Names = new List <DsplStructure.Name>(); foreach (var item in dataflow.Names) { var names = new DsplStructure.Name(); names.name = item.Value; names.lang = item.Locale; topic.Names.Add(names); } myDsplStructure._topics.Add(topic); var table = new DsplStructure.Table(); var colonne = new DsplStructure.Column(); IList <IDimension> dimensions = dsd.GetDimensions(SdmxStructureEnumType.Dimension); string[] ordinamento1 = new string[dimensions.Count]; string[] ordinamento2 = new string[dsd.Components.Count]; string codelist = ""; string agenzia = ""; string versione = ""; var concept = new DsplStructure.Concept(); // metrics concept.id = "VALUE"; concept.type = "float"; //Pietro concept.infoconcept.Names = new List <DsplStructure.Name>(); concept.infoconcept.Descriptions = new List <DsplStructure.Name>(); foreach (var item in dataflow.Names) { var names = new DsplStructure.Name(); names.lang = item.Locale; names.name = item.Value; concept.infoconcept.Names.Add(names); } myDsplStructure._concepts.Add(concept); var slices = new DsplStructure.Slice(); slices.id = "DATI"; slices.dimension = new List <String>(); int indord = 0; foreach (IDimension dim in dimensions) { ISet <ICrossReference> isr = dim.Representation.CrossReferences; foreach (var x in isr) { codelist = x.MaintainableReference.MaintainableId; agenzia = x.MaintainableReference.AgencyId; versione = x.MaintainableReference.Version; } string IDDimension = dim.ConceptRef.FullId.ToString(); if (dim.FrequencyDimension == true) { freqfieldcode = codelist; } slices.dimension.Add(dim.Id + "_code"); colonne.id = dim.Id; colonne.type = "string"; table.columntable = new List <DsplStructure.Column>(); string namefiledim = ""; StringBuilder csv = new StringBuilder(); trovato = false; List <ICodelistObject> codelists = RetreiveCodelist(agenzia, codelist, versione, dataflow, dim.Id); if (codelists.Count > 0) { namefiledim = dirPath + "\\" + dim.Id.ToLower() + ".csv"; string headLine = ""; bool BheadLine = true; foreach (ICodelistObject codelistBean in codelists) { concept = new DsplStructure.Concept(); concept.id = dim.Id + "_code"; concept.type = "string"; concept.infoconcept.Names = new List <DsplStructure.Name>(); concept.infoconcept.Descriptions = new List <DsplStructure.Name>(); concept.infoconcept.Languages = new List <DsplStructure.Languages>(); foreach (var item in codelistBean.Names) { var names = new DsplStructure.Name(); var langs = new DsplStructure.Languages(); langs.lang = item.Locale; names.lang = item.Locale; names.name = item.Value; concept.infoconcept.Languages.Add(langs); concept.infoconcept.Names.Add(names); } foreach (var item in codelistBean.Descriptions) { var names = new DsplStructure.Name(); names.lang = item.Locale; names.name = item.Value; concept.infoconcept.Descriptions.Add(names); } if (concept.infoconcept.Languages.Count != myDsplStructure._info.Languages.Count) { AdjustLanguages(concept.infoconcept); AdjustNames(concept.infoconcept, concept.infoconcept.Names[0].name); } if (BheadLine) { foreach (var item in concept.infoconcept.Languages) { headLine = headLine + "name_" + item.lang + ","; BheadLine = false; } } concept.table = dim.Id; myDsplStructure._concepts.Add(concept); string valore = ""; string newLine = ""; IList <ICode> codes = codelistBean.Items; if (codes.Count > 0) { foreach (ICode codeBean in codes) { var hasParent = VerifyParentCode(codes); var codelisNames = new DsplStructure.Codelists(); codelisNames.Names = new List <DsplStructure.Name>(); codelisNames.Languages = new List <DsplStructure.Languages>(); foreach (var item in concept.infoconcept.Names) { foreach (var codeName in codeBean.Names) { if (item.lang == codeName.Locale) { var names = new DsplStructure.Name(); var Lang = new DsplStructure.Languages(); Lang.lang = codeName.Locale; names.lang = codeName.Locale; names.name = codeName.Value.Replace('"', ' '); codelisNames.id = codeBean.Id; codelisNames.Names.Add(names); codelisNames.Languages.Add(Lang); } } } if (codelisNames.Languages.Count != myDsplStructure._info.Languages.Count) { AdjustNames(codelisNames, codelisNames.Names[0].name); } if (hasParent) { trovato = true; var pc = codeBean.ParentCode; foreach (var value in codelisNames.Names) { valore = valore + value.name.Replace(',', '.') + ","; } valore = valore + codelisNames.id + "," + pc; } else { foreach (var value in codelisNames.Names) { valore = valore + value.name.Replace(',', '.') + ","; } valore = valore + codelisNames.id; } newLine = string.Format("{0}{1}", valore, Environment.NewLine); valore = ""; csv.Append(newLine); } } if (trovato == true) { valore = headLine + dim.Id + "_code,parent"; } else { valore = headLine + dim.Id + "_code"; } table.id = dim.Id; foreach (var item in headLine.Split(',')) { if (item != "") { colonne.id = item; colonne.type = "string"; colonne.value = ""; table.columntable.Add(colonne); } } colonne.id = dim.Id + "_code"; colonne.type = "string"; colonne.value = ""; table.columntable.Add(colonne); if (trovato == true) { colonne.id = "parent"; colonne.type = "string"; colonne.value = ""; table.columntable.Add(colonne); } table.datafile_filename = dim.Id.ToLower() + ".csv"; myDsplStructure._tables.Add(table); newLine = string.Format("{0}{1}", valore, Environment.NewLine); csv.Insert(0, newLine); } } File.WriteAllText(namefiledim, csv.ToString()); } table.id = "DATI_TBL"; colonne.value = ""; table.columntable = new List <DsplStructure.Column>(); string valoredati = ""; IList <IDimension> dimensions1 = dsd.GetDimensions(SdmxStructureEnumType.Dimension); foreach (IDimension dim in dimensions1) { if (!dim.Id.Equals("FREQ")) { _dsplDataWriter.WriteValue(dim.Id + "_code,"); valoredati += dim.Id + "_code,"; colonne.id = dim.Id + "_code"; colonne.type = "string"; table.columntable.Add(colonne); ordine[indord] = dim.Id; indord++; } } _dsplDataWriter.WriteValue("FREQ_code,"); colonne.id = "FREQ_code"; colonne.type = "string"; table.columntable.Add(colonne); ordine[indord] = "FREQ"; _dsplDataWriter.WriteValue("date,"); _dsplDataWriter.WriteValue("VALUE"); slices.metric = "VALUE"; colonne.id = "VALUE"; colonne.type = "float"; table.columntable.Add(colonne); table.datafile_filename = "DATI.csv"; myDsplStructure._tables.Add(table); _dsplDataWriter.WriteValue("\n"); slices.table = "DATI_TBL"; myDsplStructure._slices.Add(slices); valoredati += "FREQ_code,VALUE,date"; string newLinedati = string.Format("{0}{1}", valoredati, Environment.NewLine); csvdati.Append(newLinedati); }
public void WriteSDMXJsonStructure(IDataflowObject dataflow, RetreiveCodelistDelegate RetrieveCodelist) { //Set the Description of Dimensions SetJsonStructureDescriptions(dataflow, RetrieveCodelist); CloseObject(); CloseObject(); CloseObject(); _startedObservations = false; this.StartElement("structure", true); this.WriteValue("name", dataflow.Name); if (dataflow.Description != null) { this.WriteValue("description", dataflow.Description); } if (dataflow.Uri != null && dataflow.Uri.AbsolutePath != null) { this.WriteValue("uri", dataflow.Uri.AbsolutePath); } this.StartElement("dimensions", true); this.StartElement("dataSet", false); this.CloseArray(); this.StartElement("series", false); foreach (var Serie in this.JsonStruct.Series) { this.OpenObject(); this.WriteValue("id", Serie.Id); this.WriteValue("keyPosition", Serie.KeyPosition); if (!(Serie.Role == null)) { this.WriteValue("role", Serie.Role); } this.StartElement("values", false); foreach (var Value in Serie.Values) { this.OpenObject(); this.WriteValue("id", Value.Id); this.WriteValue("descr", Value.Descr); this.CloseObject(); } this.CloseArray(); this.CloseObject(); } this.CloseArray(); this.StartElement("observation", false); this.OpenObject(); if (!(JsonStruct.Observation.Role == null)) { this.WriteValue("role", JsonStruct.Observation.Role); } this.WriteValue("id", this.JsonStruct.Observation.ID); this.StartElement("values", false); foreach (var Value in this.JsonStruct.Observation.Values) { this.OpenObject(); this.WriteValue("id", Value.Id); this.CloseObject(); } this.CloseArray(); this.CloseObject(); this.CloseArray(); this.CloseObject(); //atributes this.StartElement("attributes", true); this.StartElement("dataSet", false); foreach (var Att in this.JsonStruct.Attributes) { if (Att.AttachmentLevel == "DataSet") { this.OpenObject(); this.WriteValue("id", Att.Id); this.StartElement("values", false); foreach (var Value in Att.Values) { this.OpenObject(); this.WriteValue("id", Value.Id); this.WriteValue("descr", Value.Descr); this.CloseObject(); } this.CloseArray(); this.CloseObject(); } } this.CloseArray(); this.StartElement("series", false); foreach (var Att in this.JsonStruct.Attributes) { if (Att.AttachmentLevel == "Group") { this.OpenObject(); this.WriteValue("id", Att.Id); this.StartElement("values", false); foreach (var Value in Att.Values) { this.OpenObject(); this.WriteValue("id", Value.Id); this.WriteValue("descr", Value.Descr); this.CloseObject(); } this.CloseArray(); this.CloseObject(); } } this.CloseArray(); this.StartElement("observation", false); foreach (var Att in this.JsonStruct.Attributes) { if (Att.AttachmentLevel == "Observation") { this.OpenObject(); this.WriteValue("id", Att.Id); this.StartElement("values", false); foreach (var Value in Att.Values) { this.OpenObject(); this.WriteValue("id", Value.Id); this.WriteValue("descr", Value.Descr); this.CloseObject(); } this.CloseArray(); this.CloseObject(); } } this.CloseArray(); this.CloseObject(); this.StartElement("annotations", false); this.CloseArray(); this.CloseObject(); //close file this.CloseObject(); this.CloseArray(); this.CloseObject(); }