/// <summary>
        /// Build dataflow query. Override to alter the default behavior
        /// </summary>
        /// <param name="dataflowRefType">
        /// The Dataflow reference (SDMX v2.0
        /// </param>
        /// <returns>
        /// The <see cref="IStructureReference"/>.
        /// </returns>
        protected override IStructureReference BuildDataflowQuery(DataflowRefType dataflowRefType)
        {
            var urn = dataflowRefType.URN;
            var immutableInstance = BuildConstraintObject(dataflowRefType);

            StructureReferenceImpl structureReferenceImpl;
            if (ObjectUtil.ValidString(urn))
            {
                structureReferenceImpl = new ConstrainableStructureReference(urn);
            }
            else
            {
                string agencyId16 = dataflowRefType.AgencyID;
                string maintId17 = dataflowRefType.DataflowID;
                string version18 = dataflowRefType.Version;

                structureReferenceImpl = new ConstrainableStructureReference(agencyId16, maintId17, version18, SdmxStructureEnumType.Dataflow, immutableInstance);
            }

            return structureReferenceImpl;
        }
        /// <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;
        }
        /// <summary>
        /// Gets a bean with data about the codelist for specified dataflow and codelist ref.
        /// The dataflow can be retrieved from <see cref="RetrieveDataflow"/>
        /// </summary>
        /// <param name="dataflow">
        /// The dataflow
        /// </param>
        /// <param name="codelistRef">
        /// The codelist reference
        /// </param>
        /// <param name="criteria">
        /// The criteria includes a set of Member and MemberValue(s) for each dimension.
        /// </param>
        /// <param name="info">
        /// Some helper information used for logging
        /// </param>
        /// <returns>
        /// The partial codelist.
        /// </returns>
        private ICodelistObject GetCodelist(
            IDataflowObject dataflow, IStructureReference codelistRef, IContentConstraintMutableObject criteria, string info)
        {
            ICodelistObject codelist;

            var refs = new List<IStructureReference>();
            var dataflowRef = new StructureReferenceImpl(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Dataflow))
            {
                MaintainableId = dataflow.Id,
                AgencyId = dataflow.AgencyId,
                Version = dataflow.Version,
            };

            var dataflowRefBean = new ConstrainableStructureReference(dataflowRef, criteria.ImmutableInstance);

            Logger.InfoFormat(CultureInfo.InvariantCulture, Resources.InfoGettingCodelistFormat1, info);
            refs.Add(codelistRef);
            refs.Add(dataflowRefBean);

            try
            {
                ISdmxObjects response;

                response = this.SendQueryStructureRequest(refs, false);

                if (response.Codelists.Count != 1)
                {
                    string message = string.Format(
                        CultureInfo.InvariantCulture, Resources.ExceptionInvalidNumberOfCodeListsFormat1, info);
                    Logger.Error(message);
                    throw new NsiClientException(message);
                }

                codelist = response.Codelists.First();
                if (codelist.Items.Count == 0)
                {
                    string message = string.Format(
                        CultureInfo.InvariantCulture, Resources.ExceptionZeroCodesFormat1, info);
                    Logger.Error(message);
                    throw new NsiClientException(message);
                }
            }
            catch (NsiClientException e)
            {
                string message = string.Format(
                    CultureInfo.InvariantCulture, Resources.ExceptionGetCodelistFormat2, info, e.Message);
                Logger.Error(message);
                Logger.Error(e.Message, e);
                throw;
            }
            catch (DataflowException e)
            {
                throw;
            }
            catch (Exception e)
            {
                string message = string.Format(
                    CultureInfo.InvariantCulture, Resources.ExceptionGetCodelistFormat2, info, e.Message);
                Logger.Error(message);
                Logger.Error(e.Message, e);
                throw new NsiClientException(message, e);
            }

            return codelist;
        }
 /// <summary>
 /// The equals.
 /// </summary>
 /// <param name="other">
 /// The other.
 /// </param>
 /// <returns>
 /// The <see cref="bool"/>.
 /// </returns>
 protected bool Equals(ConstrainableStructureReference other)
 {
     return base.Equals(other) && Equals(this._constraint, other._constraint);
 }