Exemplo n.º 1
0
        /// <summary>
        /// Create a list of Code that compose a Codelist
        /// </summary>
        /// <param name="_dataFlowCode">Dataflow Code</param>
        /// <param name="_concept">Concept Object</param>
        /// <returns>List of ICodeMutableObject</returns>
        public List <ICodeMutableObject> GetCodelist(string _dataFlowCode, IConceptObjectImpl _concept)
        {
            try
            {
                DimensionCodelistsManager cm = new DimensionCodelistsManager(this.parsingObject, this.versionTypeResp);
                AttributeCodelistsManager at = new AttributeCodelistsManager(this.parsingObject, this.versionTypeResp);
                FLAGCodelistManager       fl = new FLAGCodelistManager(this.parsingObject, this.versionTypeResp);
                SpecialCodelistsManager   sp = new SpecialCodelistsManager(this.parsingObject, this.versionTypeResp);

                switch (_concept.ConceptType)
                {
                case ConceptTypeEnum.Dimension:
                    if (string.IsNullOrEmpty(_dataFlowCode))
                    {
                        return(cm.GetDimensionCodelistNoContrain(_concept as IDimensionConcept));
                    }
                    else
                    {
                        return(cm.GetDimensionCodelistContrain(_dataFlowCode, _concept as IDimensionConcept));
                    }

                case ConceptTypeEnum.Attribute:
                    if (((IAttributeConcept)_concept).IsFlagAttribute)
                    {
                        return(fl.GetFlagCodelist(_dataFlowCode, _concept as IAttributeConcept));
                    }
                    else if (!((IAttributeConcept)_concept).IsValueAttribute)
                    {
                        if (string.IsNullOrEmpty(_dataFlowCode))
                        {
                            return(at.GetAttributeCodelistNoConstrain(_concept as IAttributeConcept));
                        }
                        else
                        {
                            return(at.GetAttributeCodelistConstrain(_dataFlowCode, _concept as IAttributeConcept));
                        }
                    }
                    break;

                case ConceptTypeEnum.Special:
                    return(sp.GetSpecialCodelist(_dataFlowCode, _concept as ISpecialConcept));
                }
                return(null);
            }
            catch (SdmxException) { throw; }
            catch (Exception ex)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.GetCodelist, ex);
            }
        }
        private List <ICodeMutableObject> SpecialCodelist_CL_CONTRAINED(string _dataFlowCode, ISpecialConcept specialConcept)
        {
            string        WhereStatement = "1=1";
            string        Time           = "1=1";
            List <string> _ConceptWhere  = new List <string>();

            if (specialConcept.ContrainConceptREF != null && specialConcept.ContrainConceptREF.Keys.Count > 0)
            {
                foreach (string otherconept in specialConcept.ContrainConceptREF.Keys.ToList())
                {
                    if (specialConcept.ContrainConceptREF[otherconept] == null)
                    {
                        continue;
                    }
                    if (new List <string>()
                    {
                        "TIME", "TIME_PERIOD"
                    }.Contains(otherconept.Trim().ToUpper()))
                    {
                        if (specialConcept.ContrainConceptREF[otherconept].Count > 0 && specialConcept.TimeDimensionRef != null)
                        {
                            string    timedim   = string.Format(DataMessageManager.FormatWhereValue, ((IDimensionConcept)specialConcept.TimeDimensionRef).GetColumTimeName());
                            ISdmxDate StartDate = new SdmxDateCore(specialConcept.ContrainConceptREF[otherconept][0].Value);
                            string    STime     = TimePeriodDBFormat.GetTimeWhereStatment(timedim, TimePeriodDBFormat.TypeDateOperation.Major, StartDate.TimeFormatOfDate.EnumType, StartDate);
                            Time = String.Format("({0})", STime);
                            if (specialConcept.ContrainConceptREF[otherconept].Count == 2)
                            {
                                ISdmxDate EndDate = new SdmxDateCore(specialConcept.ContrainConceptREF[otherconept][1].Value);
                                string    ETime   = TimePeriodDBFormat.GetTimeWhereStatment(timedim, TimePeriodDBFormat.TypeDateOperation.Minor, EndDate.TimeFormatOfDate.EnumType, EndDate);
                                Time = String.Format("({0} AND {1})", STime, ETime);
                            }
                        }
                        continue;
                    }
                    if (otherconept.Trim().ToUpper() == "FREQ")
                    {
                        //Devo controllare se stò in modalità FakeFrequency se cosi
                        continue;
                    }
                    List <string> ConceptInternalWhere = new List <string>();
                    foreach (var item in specialConcept.ContrainConceptREF[otherconept])
                    {
                        ConceptInternalWhere.Add(string.Format("{0}='{1}'", string.Format(DataMessageManager.FormatWhereValue, otherconept), item.Value));
                    }
                    _ConceptWhere.Add(string.Format("({0})", string.Join(" OR ", ConceptInternalWhere)));
                }
            }
            WhereStatement = string.Format("{0}", string.Join(" AND ", _ConceptWhere));
            if (string.IsNullOrEmpty(WhereStatement))
            {
                WhereStatement = "1=1";
            }

            List <IParameterValue> parametri = new List <IParameterValue>()
            {
                new ParameterValue()
                {
                    Item = "DataSetCode", Value = _dataFlowCode
                },
                new ParameterValue()
                {
                    Item = "WhereStatement", Value = WhereStatement
                },
                new ParameterValue()
                {
                    Item = "Time", Value = Time
                },
                new ParameterValue()
                {
                    Item = "UserName", Value = FlyConfiguration.UserName
                },
                new ParameterValue()
                {
                    Item = "Domain", Value = FlyConfiguration.Domain
                },
            };

            List <ICodeMutableObject> codes = null;

            if (specialConcept.Id.Trim().ToUpper() == "FREQ")
            {
                codes = GetFrequencyCodelist();
            }
            else
            {
                DimensionCodelistsManager dimcm = new DimensionCodelistsManager(this.parsingObject, this.versionTypeResp);

                codes = dimcm.InternalGetDimensionCodelistConstrain(_dataFlowCode, specialConcept.Id);
            }

            List <string> existCode = ((DWHAccess)DbAccess).GetCL_CONTRAINED(parametri, specialConcept.Id);

            List <ICodeMutableObject> Contrainedcodes = new List <ICodeMutableObject>();

            for (int i = codes.Count - 1; i >= 0; i--)
            {
                if (existCode.Contains(codes[i].Id))
                {
                    Contrainedcodes.Add(codes[i]);
                }
            }
            for (int i = 0; i < Contrainedcodes.Count; i++)
            {
                ICodeMutableObject observeCode = Contrainedcodes[i];

                while (true)
                {
                    if (!string.IsNullOrEmpty(observeCode.ParentCode) && !Contrainedcodes.Exists(c => c.Id == observeCode.ParentCode))
                    {
                        ICodeMutableObject ParentCode = codes.Find(c => c.Id == observeCode.ParentCode);
                        if (ParentCode != null)
                        {
                            Contrainedcodes.Add(ParentCode);
                            observeCode = ParentCode;
                            continue;
                        }
                    }
                    break;
                }
            }

            return(Contrainedcodes);
        }