private Dictionary<string, CodemapObj> ParseCodelist(Dictionary<string, ICodelistObject> Codemap, IDataStructureObject kf,SessionQuery query)
        {
            Dictionary<string, CodemapObj> dr_codemap = new Dictionary<string, CodemapObj>();
            //IDataStructureObject kf = query._keyFamily;

            foreach (string conceptId in Codemap.Keys)
            {
                ICodelistObject codelist = Codemap[conceptId];
                if (codelist != null)
                {
                    if (this.SessionObj != null && this.SessionObj.SdmxObject != null)
                    { this.SessionObj.SdmxObject.AddCodelist(codelist); }

                    var component =
                       kf.DimensionList.Dimensions.FirstOrDefault(
                       c => c.HasCodedRepresentation()
                           && c.ConceptRef.FullId == conceptId);
                           //&& !string.IsNullOrEmpty(c.Representation.Representation.MaintainableReference.MaintainableId));
                           //&& c.Representation.Representation.MaintainableReference.MaintainableId == Codemap[conceptId].Id);
                           //&& kf.Id == conceptId);

                    if (component != null )
                    {
                        //var conceptScheme = this.SessionObj.SdmxObject.ConceptSchemes.FirstOrDefault(c => c.Id == component.ConceptRef.MaintainableId);
                        var conceptScheme = query.Structure.ConceptSchemes.FirstOrDefault(c => c.Id == component.ConceptRef.MaintainableId);
                        //var conceptScheme = this.GetCodeList(query, component);
                        //GetCodelistMap(query, false);

                        foreach (var concept in conceptScheme.Items)
                        {
                            //if (component.Id == concept.Id)
                           if (component.ConceptRef.FullId == concept.Id)
                           // if (component.ConceptRef.FullId == concept.AsReference.FullId)
                            //if (component.Representation.Representation.MaintainableId == concept.IdentifiableParent.Id)
                            {
                                //if (Codemap[conceptId]==concept){
                                CodemapObj codemap = new CodemapObj()
                                {
                                    title = TextTypeHelper.GetText(concept.Names, this.CodemapObj.Configuration.Locale),
                                    codes = new Dictionary<string, CodeObj>()
                                };
                                foreach (ICode codeItem in codelist.Items)
                                    codemap.codes.Add(
                                        codeItem.Id.ToString(),
                                        new CodeObj()
                                        {
                                            name = TextTypeHelper.GetText(codeItem.Names, this.CodemapObj.Configuration.Locale),
                                            parent = codeItem.ParentCode
                                        });

                                codemap.codes = codemap.codes.OrderBy(c => c.Value.parent == null).ToDictionary(c => c.Key, c => c.Value);
                                dr_codemap.Add(conceptId, codemap);
                            }
                        }

                     }
                     else {  //time_period code_list esiste nel codemap ma non esiste nel concept schema
                                CodemapObj codemap = new CodemapObj()
                                {
                                    title = TextTypeHelper.GetText(codelist.Names, this.CodemapObj.Configuration.Locale),
                                    codes = new Dictionary<string, CodeObj>()
                                };
                                foreach (ICode codeItem in codelist.Items)
                                    codemap.codes.Add(
                                        codeItem.Id.ToString(),
                                        new CodeObj()
                                        {
                                            name = TextTypeHelper.GetText(codeItem.Names, this.CodemapObj.Configuration.Locale),
                                            parent = codeItem.ParentCode
                                        });

                                codemap.codes = codemap.codes.OrderBy(c => c.Value.parent == null).ToDictionary(c => c.Key, c => c.Value);
                                dr_codemap.Add(conceptId, codemap);
                           }
                }
                else { dr_codemap.Add(conceptId, null); }

            }
            return dr_codemap;
        }
        /*ParseCodelist(Dictionary<string, ICodelistObject> Codemap) è errata perchè non riporta i title del concept schema*/
        private Dictionary<string, CodemapObj> ParseCodelist(Dictionary<string, ICodelistObject> Codemap)
        {
            Dictionary<string, CodemapObj> dr_codemap = new Dictionary<string, CodemapObj>();

            foreach (string conceptId in Codemap.Keys)
            {
                //List<string> criteri = new List<string>();
                ICodelistObject codelist = Codemap[conceptId];
                if (codelist != null)
                {

                    if (this.SessionObj != null && this.SessionObj.SdmxObject != null)
                    {
                        this.SessionObj.SdmxObject.AddCodelist(codelist);
                    }

                    CodemapObj codemap = new CodemapObj()
                    {
                        title = TextTypeHelper.GetText(codelist.Names, this.CodemapObj.Configuration.Locale),
                        codes = new Dictionary<string, CodeObj>()
                    };

                    foreach (ICode codeItem in codelist.Items)
                        codemap.codes.Add(
                            codeItem.Id.ToString(),
                            new CodeObj()
                            {
                                name = TextTypeHelper.GetText(codeItem.Names, this.CodemapObj.Configuration.Locale),
                                parent = codeItem.ParentCode
                            });

                    codemap.codes = codemap.codes.OrderBy(c => c.Value.parent == null).ToDictionary(c => c.Key, c => c.Value);
                    dr_codemap.Add(conceptId, codemap);

                }
                else { dr_codemap.Add(conceptId, null); }

            }
            return dr_codemap;
        }
        public Dictionary<string, CodemapObj> ParseCodelist(Dictionary<string, ICodelistObject> Codemap)
        {
            Dictionary<string, CodemapObj> drcodemap = new Dictionary<string, CodemapObj>();
            foreach (string conceptId in Codemap.Keys)
            {
                List<string> criteri = new List<string>();

                ICodelistObject codelist = Codemap[conceptId];
                CodemapObj codemap = new CodemapObj() { title = TextTypeHelper.GetText(codelist.Names, this.CodemapObj.Configuration.Locale), codes = new Dictionary<string, CodeObj>() };

                foreach (ICode codeItem in codelist.Items.Where(ci => (criteri.Count > 0 ? criteri.Contains(ci.Id) : true)))
                    codemap.codes.Add(
                        codeItem.Id.ToString(),
                        new CodeObj()
                        {
                            name = TextTypeHelper.GetText(codeItem.Names, this.CodemapObj.Configuration.Locale),
                            parent = codeItem.ParentCode
                        });

                codemap.codes = codemap.codes.OrderBy(c => c.Value.parent == null).ToDictionary(c => c.Key, c => c.Value);
                drcodemap.Add(conceptId, codemap);
            }
            return drcodemap;
        }