Beispiel #1
0
        public void SetDateSlice(string FreqType)
        {
            var table   = new DsplStructure.Table();
            var colonne = new DsplStructure.Column();
            var slices  = new DsplStructure.Slice();

            table.columntable = new List <DsplStructure.Column>();

            foreach (var myTable in myDsplStructure._tables)
            {
                if (myTable.id == "DATI_TBL")
                {
                    table = myTable;
                }
            }

            slices.dimension = new List <String>();

            if (FreqType == "A")
            {
                slices.dimension.Add("time:year");
                colonne.id     = "date";
                colonne.type   = "date";
                colonne.format = "yyyy";
                table.columntable.Add(colonne);
            }
            else if (FreqType == "M")
            {
                slices.dimension.Add("time:month");
                colonne.id     = "date";
                colonne.type   = "date";
                colonne.format = "yyyy.MM";
                table.columntable.Add(colonne);
            }
            else if (true)
            {
                slices.dimension.Add("time:month");
                colonne.id     = "date";
                colonne.type   = "date";
                colonne.format = "yyyy.MM";
                table.columntable.Add(colonne);
            }
        }
Beispiel #2
0
        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);
        }