/*FINE NUOVO SESSION QUERY*/
        private ICodelistObject GetCodeList(IDataflowObject df, IDataStructureObject kf, IComponent component)
        {
            ICodelistObject codes = null;
            if (this.SessionObj.CodelistConstrained != null && this.SessionObj.CodelistConstrained.ContainsKey(Utils.MakeKey(df)))
            {
                if (this.SessionObj.CodelistConstrained[Utils.MakeKey(df)].ContainsKey(component.Id))
                {
                    codes = this.SessionObj.CodelistConstrained[Utils.MakeKey(df)][component.Id];
                }
            }

            if (codes == null)
            {
                bool Contrained = component.StructureType.EnumType != Org.Sdmxsource.Sdmx.Api.Constants.SdmxStructureEnumType.DataAttribute;
                #region Criteria
                List<IContentConstraintMutableObject> criterias = new List<IContentConstraintMutableObject>();

                if (Contrained)
                {
                    IContentConstraintMutableObject criteria = new ContentConstraintMutableCore();
                    string currentComponent = component.ConceptRef.ChildReference.Id;
                    criteria.Id = currentComponent ?? "SPECIAL";
                    criteria.AddName("en", "english");
                    criteria.AgencyId = "agency";
                    ICubeRegionMutableObject region = new CubeRegionMutableCore();

                    if (currentComponent != null)
                    {
                        IKeyValuesMutable keyValue = new KeyValuesMutableImpl();
                        keyValue.Id = currentComponent;
                        keyValue.AddValue(SpecialValues.DummyMemberValue);
                        region.AddKeyValue(keyValue);
                    }
                    criteria.IncludedCubeRegion = region;
                    criterias.Add(criteria);
                }

                #endregion
                codes = GetSDMXObject.GetCodelist(df, kf, component, criterias, Contrained);
            }

            return codes;
        }
        private ICodelistObject GetCodeListCostraint(
            IDataflowObject df,
            IDataStructureObject kf,
            IComponent component)
        {
            //           ICodelistObject codes = GetCodeList(query, component);

            ICodelistObject codes = null;

            bool Contrained = component.StructureType.EnumType != Org.Sdmxsource.Sdmx.Api.Constants.SdmxStructureEnumType.DataAttribute;

            #region Criteria
            List<IContentConstraintMutableObject> criterias = new List<IContentConstraintMutableObject>();
            if (Contrained)
            {
                string currentComponent = component.ConceptRef.ChildReference.Id;

                IContentConstraintMutableObject criteria = new ContentConstraintMutableCore();
                criteria.Id = currentComponent ?? "SPECIAL";
                criteria.AddName("en", "english");
                criteria.AgencyId = "agency";

                ICubeRegionMutableObject region = new CubeRegionMutableCore();

                if (currentComponent != null)
                {
                    IKeyValuesMutable keyValue = new KeyValuesMutableImpl();
                    keyValue.Id = currentComponent;
                    keyValue.AddValue(SpecialValues.DummyMemberValue);
                    region.AddKeyValue(keyValue);

                    if (CodemapObj.PreviusCostraint != null)
                    {
                        foreach (string costreintKey in CodemapObj.PreviusCostraint.Keys)
                        {
                            if (costreintKey == currentComponent) continue;
                            if (costreintKey == kf.TimeDimension.Id)
                            {

                                // Qui considerare il caso in qui in CodemapObj.PreviusCostraint[costreintKey][0] ci sia solo un valore, ke equivale alla data da.
                                if (CodemapObj.PreviusCostraint[costreintKey].Count > 1)
                                //if (!string.IsNullOrEmpty(CodemapObj.PreviusCostraint[costreintKey][1]))
                                {
                                    DateTime MinDate = GetDateTimeFromSDMXTimePeriod(CodemapObj.PreviusCostraint[costreintKey][0].ToString(), 'M'); //DateTime.ParseExact(CodemapObj.PreviusCostraint[costreintKey][0].ToString(), "yyyy-MM-dd", CultureInfo.CurrentCulture, DateTimeStyles.None);
                                    DateTime MaxDate = GetDateTimeFromSDMXTimePeriod(CodemapObj.PreviusCostraint[costreintKey][1].ToString(), 'M'); //DateTime.ParseExact(CodemapObj.PreviusCostraint[costreintKey][1].ToString(), "yyyy-MM-dd", CultureInfo.CurrentCulture, DateTimeStyles.None);

                                    if (MinDate.CompareTo(MaxDate) > 0)
                                    {
                                        criteria.StartDate = MaxDate;
                                        criteria.EndDate = MinDate;
                                    }
                                    else
                                    {
                                        criteria.StartDate = MinDate;
                                        criteria.EndDate = MaxDate;
                                    }

                                }
                            }
                            else
                            {
                                foreach (var code in CodemapObj.PreviusCostraint[costreintKey])
                                {
                                    IKeyValuesMutable _keyValue = new KeyValuesMutableImpl();
                                    _keyValue.Id = costreintKey;
                                    _keyValue.AddValue(code);
                                    region.AddKeyValue(_keyValue);
                                }
                            }
                        }
                    }

                }
                criteria.IncludedCubeRegion = region;
                criterias.Add(criteria);

            }
            #endregion

            codes = GetSDMXObject.GetCodelist(df, kf, component, criterias, Contrained);

            return codes;
        }
        public int GetCountObservation(SessionQuery query)
        {
            ISdmxObjects structure = query.Structure;
            IDataflowObject df = structure.Dataflows.First();
            IDataStructureObject kf = structure.DataStructures.First();

            if (kf == null)
                throw new InvalidOperationException("DataStructure is not set");
            if (df == null)
                throw new InvalidOperationException("Dataflow is not set");

            var currentComponent = "CL_COUNT";

            IContentConstraintMutableObject criteria = new ContentConstraintMutableCore();
            criteria.Id = currentComponent;
            criteria.AddName("en", "english");
            criteria.AgencyId = "agency";
            ICubeRegionMutableObject region = new CubeRegionMutableCore();

            if (currentComponent != null)
            {
                IKeyValuesMutable keyValue = new KeyValuesMutableImpl();
                keyValue.Id = currentComponent;
                keyValue.AddValue(SpecialValues.DummyMemberValue);
                region.AddKeyValue(keyValue);

                if (query.Criteria != null)
                {
                    foreach (string costreintKey in query.Criteria.Keys)
                    {
                        if (costreintKey == currentComponent) continue;
                        if (costreintKey == kf.TimeDimension.Id)
                        {

                            // Qui considerare il caso in qui in CodemapObj.PreviusCostraint[costreintKey][0] ci sia solo un valore, ke equivale alla data da.
                            if (query.Criteria[costreintKey].Count > 1)
                            {
                                DateTime MinDate = GetDateTimeFromSDMXTimePeriod(query.Criteria[costreintKey][0].ToString(), 'M'); //DateTime.ParseExact(CodemapObj.PreviusCostraint[costreintKey][0].ToString(), "yyyy-MM-dd", CultureInfo.CurrentCulture, DateTimeStyles.None);
                                DateTime MaxDate = GetDateTimeFromSDMXTimePeriod(query.Criteria[costreintKey][1].ToString(), 'M'); //DateTime.ParseExact(CodemapObj.PreviusCostraint[costreintKey][1].ToString(), "yyyy-MM-dd", CultureInfo.CurrentCulture, DateTimeStyles.None);
                                //baco fabio
                                if (MinDate.CompareTo(MaxDate) > 0)
                                {
                                    criteria.StartDate = MaxDate;
                                    criteria.EndDate = MinDate;
                                }
                                else
                                {
                                    criteria.StartDate = MinDate;
                                    criteria.EndDate = MaxDate;
                                }

                            }
                        }
                        else
                        {
                            foreach (var code in query.Criteria[costreintKey])
                            {
                                IKeyValuesMutable _keyValue = new KeyValuesMutableImpl();
                                _keyValue.Id = costreintKey;
                                _keyValue.AddValue(code);
                                region.AddKeyValue(_keyValue);
                            }
                        }
                    }
                }

            }
            criteria.IncludedCubeRegion = region;

            GetSDMXObject = WebServiceSelector.GetSdmxImplementation(this.CodemapObj.Configuration);

            int count = GetSDMXObject.GetDataflowDataCount(df, criteria);

            return count;
        }
        /// <summary>
        /// The build cube region.
        /// </summary>
        /// <param name="cubeRegionType">
        /// The cube region type.
        /// </param>
        /// <returns>
        /// The <see cref="ICubeRegionMutableObject"/>.
        /// </returns>
        private static ICubeRegionMutableObject BuildCubeRegion(CubeRegionType cubeRegionType)
        {
            ICubeRegionMutableObject cubeRegion = new CubeRegionMutableCore();
            foreach (MemberType memberType in cubeRegionType.Member)
            {
                IKeyValuesMutable keyValues = new KeyValuesMutableImpl();
                keyValues.Id = memberType.ComponentRef;
                cubeRegion.AddKeyValue(keyValues);
                if (memberType.MemberValue == null || memberType.MemberValue.Count == 0)
                {
                    keyValues.AddValue(SpecialValues.DummyMemberValue);
                }
                else
                {
                    foreach (MemberValueType memberValueType in memberType.MemberValue)
                    {
                        keyValues.AddValue(memberValueType.Value);
                    }
                }
            }

            return cubeRegion;
        }
        private void PopolateKeyValue(ref IKeyValuesMutable kv)
        {
            kv = new KeyValuesMutableImpl();
            kv.Id = lblComponentSelectedID.Text;

            foreach (ListItem li in lbTarget.Items)
            {
                kv.AddValue(li.Value);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Create a new Constrain from the <see cref="SessionQuery._queryComponentIndex"/> and optionally for the specified component
        /// </summary>
        /// <param name="currentComponent">
        /// The current component. Normally this component should be belong to the AvailableComponents set. Set to null if there isn't any current component
        /// </param>
        /// <returns>
        /// A constrain bean
        /// </returns>
        public IContentConstraintMutableObject CreateConstraintBean(string currentComponent)
        {
            if (!this._sessionQuery.IsDataflowSet)
            {
                throw new InvalidOperationException("Dataflow is not set");
            }
            IContentConstraintMutableObject criteria = new ContentConstraintMutableCore();
            criteria.Id = currentComponent ?? "SPECIAL";
            criteria.AddName("en", "english");
            criteria.AgencyId = "agency";
            ICubeRegionMutableObject region = new CubeRegionMutableCore();

            if (currentComponent != null)
            {
                IKeyValuesMutable keyValue = new KeyValuesMutableImpl();
                keyValue.Id = currentComponent;
                keyValue.AddValue(SpecialValues.DummyMemberValue);
                region.AddKeyValue(keyValue);
            }

            foreach (var queryComponent in this._sessionQuery.GetQueryComponents())
            {
                if (queryComponent != null && !queryComponent.GetKeyFamilyComponent().ConceptRef.ChildReference.Id.Equals(currentComponent))
                {
                    var setComponents = new KeyValuesMutableImpl();
                    region.AddKeyValue(setComponents);
                    setComponents.Id = queryComponent.GetKeyFamilyComponent().ConceptRef.ChildReference.Id;

                    var dimension = queryComponent.GetKeyFamilyComponent() as IDimension;
                    if (dimension != null && dimension.TimeDimension)
                    {
                        // there is another way to handle this with ReferencePeriod but
                        // ReferencePeriod accepts {xs:Date,xs:DateTime}. Using this way, MemberValue, we can use anything we want.

                        // must be first
                        setComponents.KeyValues.Add(queryComponent.StartDate);

                        if (!string.IsNullOrEmpty(queryComponent.EndDate))
                        {
                            setComponents.KeyValues.Add(queryComponent.EndDate);
                        }
                    }
                    else if (queryComponent.GetKeyFamilyComponent().Representation.Representation.MaintainableReference.MaintainableId != null)
                    {
                        // java has different API for MemberValue
                        foreach (ICode code in queryComponent.RetrieveCodes())
                        {
                            setComponents.KeyValues.Add(code.Id);
                        }
                        if (setComponents.KeyValues.Count == 0)
                        {
                            setComponents.AddValue(SpecialValues.DummyMemberValue);
                        }
                    }
                    else
                    {
                        setComponents.KeyValues.Add(queryComponent.TextValue);
                    }
                }
            }

            if (region.KeyValues.Count > 0)
            {
                criteria.IncludedCubeRegion = region;
            }

            return criteria;
        }
        /// <summary>
        /// The build constrainable structure reference.
        /// </summary>
        /// <param name="id">
        /// The id.
        /// </param>
        /// <param name="agencyId">
        /// The agency id.
        /// </param>
        /// <param name="version">
        /// The version.
        /// </param>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="previousMembers">
        /// The previous members.
        /// </param>
        /// <param name="currentDataflowReference">
        /// The current dataflow reference.
        /// </param>
        /// <returns>
        /// The <see cref="IConstrainableStructureReference"/>.
        /// </returns>
        private static IConstrainableStructureReference BuildConstrainableStructureReference(
            string id, 
            string agencyId, 
            string version, 
            string name, 
            IEnumerable<IKeyValuesMutable> previousMembers, 
            IStructureReference currentDataflowReference)
        {
            IContentConstraintMutableObject mutableConstraint = new ContentConstraintMutableCore { Id = id, AgencyId = agencyId, Version = version };
            mutableConstraint.AddName("en", name);

            var cubeRegion = new CubeRegionMutableCore();
            mutableConstraint.IncludedCubeRegion = cubeRegion;
            IKeyValuesMutable requestedDimension = new KeyValuesMutableImpl();
            requestedDimension.Id = id;
            requestedDimension.AddValue(SpecialValues.DummyMemberValue);
            cubeRegion.AddKeyValue(requestedDimension);
            if (previousMembers != null)
            {
                cubeRegion.KeyValues.AddAll(previousMembers);
            }

            IContentConstraintObject constraint = new ContentConstraintObjectCore(mutableConstraint);
            IConstrainableStructureReference specialRequest = new ConstrainableStructureReference(currentDataflowReference, constraint);
            return specialRequest;
        }