示例#1
0
        /// <summary>
        /// Returns a new stub <see cref="IMaintainableMutableObject"/> object based on the specified <paramref name="maintainable"/>.
        /// The new object is a shallow copy.
        /// </summary>
        /// <typeparam name="TInterface">The maintainable type (interface).</typeparam>
        /// <typeparam name="TImplementation">The maintainable type (concrete implementation).</typeparam>
        /// <param name="maintainable">The maintainable.</param>
        /// <returns>A new stub <see cref="IMaintainableMutableObject"/> object based on the specified <paramref name="maintainable"/>; otherwise if <paramref name="maintainable"/> is null it returns null.</returns>
        public static TInterface CloneAsStub <TInterface, TImplementation>(this TInterface maintainable) where TInterface : IMaintainableMutableObject
            where TImplementation : TInterface, new()
        {
            if (maintainable.IsDefault())
            {
                return(default(TInterface));
            }

            var stub = new TImplementation
            {
                Id                = maintainable.Id,
                AgencyId          = maintainable.AgencyId,
                Version           = maintainable.Version,
                StructureURL      = _defaultUri,
                StartDate         = maintainable.StartDate,
                EndDate           = maintainable.EndDate,
                FinalStructure    = maintainable.FinalStructure,
                ServiceURL        = maintainable.ServiceURL,
                Uri               = maintainable.Uri,
                ExternalReference = TertiaryBool.ParseBoolean(true),

                // TODO following line when we remove when sync to CAPI v1.0
                Stub = true
            };

            stub.Annotations.AddAll(maintainable.Annotations);
            stub.Names.AddAll(maintainable.Names);

            return(stub);
        }
示例#2
0
        /// <summary>
        /// Retrieve cross sectional attachments.
        /// </summary>
        /// <param name="dataReader">
        ///     The data reader.
        /// </param>
        /// <param name="crossDataSet">
        ///     The list of components attached to cross-sectional data set.
        /// </param>
        /// <param name="conceptRef">
        ///     The concept id.
        /// </param>
        /// <param name="crossGroup">
        ///     The list of components attached to cross-sectional group.
        /// </param>
        /// <param name="crossSection">
        ///     The list of components attached to cross-sectional section.
        /// </param>
        /// <param name="crossObs">
        ///     The list of components attached to cross-sectional observation level
        /// </param>
        private static void RetrieveCrossSectionalAttachments(IDataRecord dataReader, ISet <string> crossDataSet, string conceptRef, ISet <string> crossGroup, ISet <string> crossSection, ISet <string> crossObs)
        {
            TertiaryBool crossSectionalAttachDataSet = DataReaderHelper.GetTristate(dataReader, "XS_ATTLEVEL_DS");

            if (crossSectionalAttachDataSet.IsTrue)
            {
                crossDataSet.Add(conceptRef);
            }

            TertiaryBool crossSectionalAttachGroup = DataReaderHelper.GetTristate(dataReader, "XS_ATTLEVEL_GROUP");

            if (crossSectionalAttachGroup.IsTrue)
            {
                crossGroup.Add(conceptRef);
            }

            TertiaryBool crossSectionalAttachSection = DataReaderHelper.GetTristate(dataReader, "XS_ATTLEVEL_SECTION");

            if (crossSectionalAttachSection.IsTrue)
            {
                crossSection.Add(conceptRef);
            }

            TertiaryBool crossSectionalAttachObservation = DataReaderHelper.GetTristate(dataReader, "XS_ATTLEVEL_OBS");

            if (crossSectionalAttachObservation.IsTrue)
            {
                crossObs.Add(conceptRef);
            }
        }
        /// <summary>
        /// Create a ImmutableInstance of DataStructure (Keyfamily in sdmx 2.0)
        /// </summary>
        /// <param name="components">list of IComponentMutableObject that compose dsd</param>
        /// <param name="Groups">list of Groups (ever Null for OnTheFly version 1.0)</param>
        /// <param name="AgencyId">Agency Id</param>
        /// <param name="Version">Artefact Version</param>
        /// <returns>DataStructureObjectImpl</returns>
        public DataStructureObjectImpl BuildDataStructure(List <IComponentMutableObject> components, List <IGroupMutableObject> Groups, string AgencyId, string Version)
        {
            try
            {
                DataStructureObjectImpl dsd = new DataStructureObjectImpl();
                dsd._Concepts = this._Concepts;
                dsd.AgencyId  = AgencyId;
                dsd.Version   = Version;
                dsd.Id        = this.Code;
                foreach (var nomi in this.Names)
                {
                    dsd.AddName(nomi.Lingua, nomi.Name);
                }

                if (!this.ParsingObject.ReturnStub)
                {
                    foreach (IComponentMutableObject comp in components)
                    {
                        if (comp.StructureType.EnumType == SdmxStructureEnumType.PrimaryMeasure)
                        {
                            dsd.AddPrimaryMeasure(comp.ConceptRef);
                        }
                        else if (comp is IAttributeMutableObject)
                        {
                            dsd.AddAttribute((IAttributeMutableObject)comp);
                        }
                        else if (comp is IDimensionMutableObject)
                        {
                            dsd.AddDimension((IDimensionMutableObject)comp);
                        }
                    }

                    if (Groups != null)
                    {
                        foreach (GroupMutableCore group in Groups)
                        {
                            dsd.AddGroup(group);
                        }
                    }
                }
                dsd.FinalStructure = TertiaryBool.ParseBoolean(true);

                if (this.ParsingObject.isReferenceOf || this.ParsingObject.ReturnStub)
                {
                    dsd.ExternalReference = TertiaryBool.ParseBoolean(true);
                    dsd.StructureURL      = RetreivalStructureUrl.Get(this, dsd.Id, dsd.AgencyId, dsd.Version);
                }


                dsd.Immutated = dsd.ImmutableInstance;
                return(dsd);
            }
            catch (SdmxException) { throw; }
            catch (Exception ex)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.CreateImmutable, ex);
            }
        }
示例#4
0
        /// <summary>
        /// Convert the <paramref name="facetValue"/> to <see cref="TertiaryBool"/>
        /// </summary>
        /// <param name="facetValue">
        /// The facet value.
        /// </param>
        /// <returns>
        /// the <paramref name="facetValue"/> as <see cref="TertiaryBool"/>
        /// </returns>
        private static TertiaryBool FacetToTristateBool(string facetValue)
        {
            if (string.IsNullOrWhiteSpace(facetValue))
            {
                return(TertiaryBool.GetFromEnum(TertiaryBoolEnumType.Unset));
            }

            return(TertiaryBool.ParseBoolean(XmlConvert.ToBoolean(facetValue.ToLowerInvariant())));
        }
示例#5
0
        /// <summary>
        ///  Add facet to the specified <paramref name="facets"/>
        /// </summary>
        /// <param name="value">
        /// The value.
        /// </param>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="facets">
        /// The facets.
        /// </param>
        private void AddFacet(TertiaryBool value, string name, Stack <KeyValuePair <long, string> > facets)
        {
            long id;

            if (value.IsSet() && this._facetMap.TryGetValue(name, out id))
            {
                facets.Push(new KeyValuePair <long, string>(id, XmlConvert.ToString(value.IsTrue)));
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ComplexAnnotationReferenceCore"/> class.
        /// </summary>
        /// <param name="returnLatest">
        /// The return latest. 
        /// </param>
        /// <param name="version">
        /// The version. 
        /// </param>
        /// <param name="validFrom">
        /// The valid from. 
        /// </param>
        /// <param name="validTo">
        /// The valid to. 
        /// </param>
        public ComplexVersionReferenceCore(TertiaryBool returnLatest, string version, ITimeRange validFrom, ITimeRange validTo) 
        {
		    if (returnLatest != null)
            {
			   this._returnLatest = returnLatest;
		    }
	    	this._version = version;
	    	this._validFrom = validFrom;
		    this._validTo = validTo;
	    }
示例#7
0
        /// <summary>
        ///  Create a ImmutableInstance of Categorisation
        /// </summary>
        /// <param name="DataflowCode">Dataflow Code</param>
        /// <param name="DataflowAgency">Dataflow Agency Id</param>
        /// <param name="DataflowVersion">Dataflow Version</param>
        /// <param name="CategoryParent">list of category parent, from hightLevel parent to low level child category</param>
        /// <returns>ICategorisationObject</returns>
        public ICategorisationObject BuildCategorisation(string DataflowCode, string DataflowAgency, string DataflowVersion, List <string> CategoryParent)
        {
            try
            {
                ICategorisationMutableObject ca = new CategorisationMutableCore();
                ca.AgencyId = this.CategorySchemeAgencyId;
                ca.Version  = this.CategorySchemeVersion;
                string IDName = string.Format("{0}@{1}@{2}@{3}@{4}@{5}",
                                              DataflowCode, DataflowAgency, DataflowVersion.Replace(".", ""),
                                              this.Code, this.CategorySchemeVersion.Replace(".", ""), CategoryParent[CategoryParent.Count - 1]);
                ca.Id = IDName;
                ca.AddName("en", IDName);

                //IAnnotationMutableObject ann = new AnnotationMutableCore();
                //ann.Type="CategoryScheme_node_order";
                //ann.Text.Add(new TextTypeWrapperMutableCore("en", (CategoryParent.Count).ToString()));
                //ca.AddAnnotation(ann);

                //ca.Id = string.Format(FlyConfiguration.CategorisationFormat, DataflowCode);
                //foreach (SdmxObjectNameDescription item in this.Names)
                //    ca.AddName(item.Lingua, item.Name);

                if (!this.ParsingObject.ReturnStub)
                {
                    if (this.VersionTypeResp == SdmxSchemaEnumType.VersionTwo)
                    {
                        ca.CategoryReference = ReferenceBuilder.CreateCategoryReference(this.Code, this.CategorySchemeAgencyId, this.CategorySchemeVersion, CategoryParent.ToArray());
                    }
                    else
                    {
                        ca.CategoryReference = ReferenceBuilder.CreateCategoryReference(this.Code, this.CategorySchemeAgencyId, this.CategorySchemeVersion, CategoryParent != null && CategoryParent.Count > 0 ? new string[1] {
                            CategoryParent[CategoryParent.Count - 1]
                        } : CategoryParent.ToArray());
                    }

                    ca.StructureReference = ReferenceBuilder.CreateDataflowReference(DataflowCode, DataflowAgency, DataflowVersion);
                }

                ca.FinalStructure = TertiaryBool.ParseBoolean(true);

                //if (this.ParsingObject.isReferenceOf || this.ParsingObject.ReturnStub)
                //{
                //    ca.ExternalReference = TertiaryBool.ParseBoolean(true);
                //    ca.StructureURL = RetreivalStructureUrl.Get(this, ca.Id, ca.AgencyId, ca.Version);
                //}

                return(ca.ImmutableInstance);
            }
            catch (SdmxException) { throw; }
            catch (Exception ex)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.CreateImmutable, ex);
            }
        }
示例#8
0
        private void GetCategorisationDataflow()
        {
            _dtCategorisationDataflow = DbAccess.ExecutetoTable(DBOperationEnum.GetCategorisationDataflow, null);

            if (_dtCategorisationDataflow.Rows.Count <= 0)
            {
                return;
            }

            ReferencesObject.Categorisation = new List <ICategorisationObject>();

            string DFID, DFAgency, DFVersion, CSID, CSAgency, CSVersion, CatCode, IDCAT, IDDataFlow;

            DataView  viewCSDF = new DataView(_dtCategorisationDataflow);
            DataTable dtCSDF   = viewCSDF.ToTable(true, "IDDataFlow", "DFID", "DFAgency", "DFVersion", "CSID",
                                                  "CSAgency", "CSVersion", "CatCode", "IDCAT");
            DataTable dtCatNames = viewCSDF.ToTable(true, "IDCAT", "CubeLang", "CubeName", "IDDataFlow");

            ICategorisationMutableObject categorisation;

            foreach (DataRow row in dtCSDF.Rows)
            {
                IDDataFlow = row["IDDataFlow"].ToString();
                DFID       = row["DFID"].ToString();
                DFAgency   = row["DFAgency"].ToString();
                DFVersion  = row["DFVersion"].ToString();
                CSID       = row["CSID"].ToString();
                CSAgency   = row["CSAgency"].ToString();
                CSVersion  = row["CSVersion"].ToString();
                CatCode    = row["CatCode"].ToString();
                IDCAT      = row["IDCAT"].ToString();

                categorisation = new CategorisationMutableCore()
                {
                    Id             = DFID,
                    AgencyId       = DFAgency,
                    Version        = DFVersion,
                    FinalStructure = TertiaryBool.ParseBoolean(true),
                };

                IStructureReference structureRef = new StructureReferenceImpl(DFAgency, DFID, DFVersion,
                                                                              SdmxStructureEnumType.Dataflow);
                IStructureReference categoryRef = new StructureReferenceImpl(CSAgency, CSID, CSVersion,
                                                                             SdmxStructureEnumType.Category, CatCode);

                categorisation.StructureReference = structureRef;
                categorisation.CategoryReference  = categoryRef;

                SetNames(dtCatNames.Select("IDCat = " + IDCAT + " AND IDDataFlow = " + IDDataFlow), categorisation);

                ReferencesObject.Categorisation.Add(categorisation.ImmutableInstance);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MetadataAttributeMutableCore"/> class.
 /// </summary>
 /// <param name="objTarget">
 /// The obj target.
 /// </param>
 public MetadataAttributeMutableCore(IMetadataAttributeObject objTarget)
     : base(objTarget)
 {
     this._metadataAttributes = new List<IMetadataAttributeMutableObject>();
     this._presentational = TertiaryBool.GetFromEnum(TertiaryBoolEnumType.Unset);
     this._minOccurs = objTarget.MinOccurs;
     this._maxOccurs = objTarget.MaxOccurs;
     this._presentational = objTarget.Presentational;
     if (objTarget.MetadataAttributes != null)
     {
         foreach (IMetadataAttributeObject currentMetadatAttribute in objTarget.MetadataAttributes)
         {
             this._metadataAttributes.Add(new MetadataAttributeMutableCore(currentMetadatAttribute));
         }
     }
 }
        /// <summary>
        /// Add item to codelist whitout generate a duplicate items
        /// </summary>
        /// <param name="codelist">codelist from which to copy the items</param>
        public void AddItemto(ICodelistMutableObject codelist)
        {
            try
            {
                List <string> Idduples = new List <string>();
                try
                {//ci sono i duplicati ID sotto padri diversi e SDMX scoppia....
                    if (CodesObjects != null)
                    {
                        Idduples = (from c in CodesObjects
                                    where CodesObjects.Count(comp => comp.Id == c.Id) > 1
                                    select c.Id).Distinct().ToList();
                    }
                }
                catch (Exception)
                {
                    //Errore nella ricerca dei duplicati ma non fa niente
                }


                if (!this.ParsingObject.ReturnStub)
                {
                    foreach (ICodeMutableObject cl in CodesObjects)
                    {
                        if (!Idduples.Contains(cl.Id) && codelist.Items.Count(presentCode => presentCode.Id == cl.Id) == 0)
                        {
                            codelist.AddItem(cl);
                        }
                    }
                    codelist.FinalStructure = TertiaryBool.ParseBoolean(true);
                }


                if (this.ParsingObject.isReferenceOf || this.ParsingObject.ReturnStub)
                {
                    codelist.ExternalReference = TertiaryBool.ParseBoolean(true);
                    codelist.StructureURL      = RetreivalStructureUrl.Get(this, codelist.Id, codelist.AgencyId, codelist.Version);
                }
            }
            catch (SdmxException) { throw; }
            catch (Exception ex)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.CreateImmutable, ex);
            }
        }
        /// <summary>
        /// Create a ImmutableInstance of Dataflow
        /// </summary>
        /// <param name="AgencyId">Agency Id</param>
        /// <param name="Version">Artefact Version</param>
        /// <returns>IDataflowObject</returns>
        public IDataflowObject BuildDataflow(string AgencyId, string Version)
        {
            try
            {
                IDataflowMutableObject df = new DataflowMutableCore();
                df.AgencyId = AgencyId;
                df.Version  = Version;
                df.Id       = this.Code;
                if (this.Names != null)
                {
                    foreach (SdmxObjectNameDescription nome in this.Names)
                    {
                        df.AddName(nome.Lingua, nome.Name);
                    }
                }

                if (!this.ParsingObject.ReturnStub)
                {
                    if (this.DataStrunctureRef != null)
                    {
                        df.DataStructureRef = this.DataStrunctureRef;
                    }
                    else
                    {
                        df.DataStructureRef = ReferenceBuilder.CreateDSDStructureReference(this.Code);//Creo una struttura di riferimento
                    }
                }

                df.FinalStructure = TertiaryBool.ParseBoolean(true);

                if (this.ParsingObject.isReferenceOf || this.ParsingObject.ReturnStub)
                {
                    df.ExternalReference = TertiaryBool.ParseBoolean(true);
                    df.StructureURL      = RetreivalStructureUrl.Get(this, df.Id, df.AgencyId, df.Version);
                }
                return(df.ImmutableInstance);
            }
            catch (SdmxException) { throw; }
            catch (Exception ex)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.CreateImmutable, ex);
            }
        }
示例#12
0
        /// <summary>
        /// Create a ImmutableInstance of CategoryScheme
        /// </summary>
        /// <param name="CategoryObjects">List of CategoryObject</param>
        /// <returns>ICategorySchemeObject</returns>
        public ICategorySchemeObject BuildCategorySchemeObject(List <ICategoryMutableObject> CategoryObjects)
        {
            try
            {
                ICategorySchemeMutableObject ca = new CategorySchemeMutableCore();
                ca.AgencyId = this.CategorySchemeAgencyId;
                ca.Id       = this.Code;
                ca.Version  = this.categorySchemeVersion;
                foreach (SdmxObjectNameDescription item in this.Names)
                {
                    ca.AddName(item.Lingua, item.Name);
                }

                //IAnnotationMutableObject ann = new AnnotationMutableCore();
                //ann.Type = "CategoryScheme_node_order";
                //ann.Text.Add(new TextTypeWrapperMutableCore("en", "0"));
                //ca.AddAnnotation(ann);

                if (!this.ParsingObject.ReturnStub)
                {
                    foreach (ICategoryMutableObject item in CategoryObjects)
                    {
                        ca.AddItem(item);
                    }

                    ca.FinalStructure = TertiaryBool.ParseBoolean(true);
                }

                if (this.ParsingObject.isReferenceOf || this.ParsingObject.ReturnStub)
                {
                    ca.ExternalReference = TertiaryBool.ParseBoolean(true);
                    ca.StructureURL      = RetreivalStructureUrl.Get(this, ca.Id, ca.AgencyId, ca.Version);
                }

                return(ca.ImmutableInstance);
            }
            catch (SdmxException) { throw; }
            catch (Exception ex)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.CreateImmutable, ex);
            }
        }
示例#13
0
        /// <summary>
        /// Converts the specified <paramref name="crossDsd"/> to stub.
        /// </summary>
        /// <param name="crossDsd">The cross DSD.</param>
        public static void ConvertToStub(this ICrossSectionalDataStructureMutableObject crossDsd)
        {
            crossDsd.Stub = true;
            crossDsd.ExternalReference = TertiaryBool.GetFromEnum(TertiaryBoolEnumType.True);
            crossDsd.StructureURL      = _defaultUri;

            // remove components
            crossDsd.AttributeList = null;
            crossDsd.DimensionList = new DimensionListMutableCore();
            crossDsd.Dimensions.Clear();
            crossDsd.Groups.Clear();
            crossDsd.MeasureList = null;
            crossDsd.CrossSectionalAttachDataSet.Clear();
            crossDsd.CrossSectionalAttachGroup.Clear();
            crossDsd.CrossSectionalAttachSection.Clear();
            crossDsd.CrossSectionalAttachObservation.Clear();
            crossDsd.CrossSectionalMeasures.Clear();
            crossDsd.MeasureDimensionCodelistMapping.Clear();
            crossDsd.AttributeToMeasureMap.Clear();
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////BUILD FROM MUTABLE OBJECT                 //////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////    
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="MetadataAttributeObjectCore"/> class.
        /// </summary>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        /// <param name="itemMutableObject">
        /// The sdmxObject. 
        /// </param>
        /// <exception cref="SdmxSemmanticException">
        /// Throws Validate exception.
        /// </exception>
        public MetadataAttributeObjectCore(IIdentifiableObject parent, IMetadataAttributeMutableObject itemMutableObject)
            : base(itemMutableObject, parent)
        {
            this.metadataAttributes = new List<IMetadataAttributeObject>();
            this.presentational = TertiaryBool.GetFromEnum(TertiaryBoolEnumType.Unset);
            try
            {
                if (itemMutableObject.MetadataAttributes != null)
                {
                    foreach (IMetadataAttributeMutableObject currentMa in itemMutableObject.MetadataAttributes)
                    {
                        this.metadataAttributes.Add(new MetadataAttributeObjectCore(this, currentMa));
                    }
                }

                if (itemMutableObject.MinOccurs != null)
                {
                    this.minOccurs = itemMutableObject.MinOccurs;
                }

                if (itemMutableObject.MaxOccurs != null)
                {
                    this.maxOccurs = itemMutableObject.MaxOccurs;
                }

                this.presentational = itemMutableObject.Presentational;
            }
            catch (Exception th)
            {
                throw new SdmxSemmanticException("IsError creating structure: " + this, th);
            }

            try
            {
                this.Validate();
            }
            catch (SdmxSemmanticException e)
            {
                throw new SdmxSemmanticException(e, ExceptionCode.FailValidation, this);
            }
        }
        /// <summary>
        ///  Create a ImmutableInstance of ConceptScheme
        /// </summary>
        /// <param name="AgencyId">Agency Id</param>
        /// <param name="Version">Artefact Version</param>
        /// <returns>IConceptSchemeObject</returns>
        public IConceptSchemeObject BuildConceptScheme(string AgencyId, string Version)
        {
            try
            {
                IConceptSchemeMutableObject cs = new ConceptSchemeMutableCore();
                cs.AgencyId = AgencyId;
                cs.Version  = Version;
                cs.Id       = this.Code;
                if (this.Names != null)
                {
                    foreach (SdmxObjectNameDescription item in this.Names)
                    {
                        cs.AddName(item.Lingua, item.Name);
                    }
                }

                if (!this.ParsingObject.ReturnStub)
                {
                    foreach (IConceptMutableObject _dim in Concepts)
                    {
                        cs.AddItem(_dim);
                    }
                }


                cs.FinalStructure = TertiaryBool.ParseBoolean(true);

                if (this.ParsingObject.isReferenceOf || this.ParsingObject.ReturnStub)
                {
                    cs.ExternalReference = TertiaryBool.ParseBoolean(true);
                    cs.StructureURL      = RetreivalStructureUrl.Get(this, cs.Id, cs.AgencyId, cs.Version);
                }

                return(cs.ImmutableInstance);
            }
            catch (SdmxException) { throw; }
            catch (Exception ex)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.CreateImmutable, ex);
            }
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="MetadataAttributeMutableCore" /> class.
 /// </summary>
 public MetadataAttributeMutableCore()
     : base(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.MetadataAttribute))
 {
     this._metadataAttributes = new List<IMetadataAttributeMutableObject>();
     this._presentational = TertiaryBool.GetFromEnum(TertiaryBoolEnumType.Unset);
 }
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////BUILD FROM V2 SCHEMA                 //////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes a new instance of the <see cref="MetadataAttributeObjectCore"/> class.
        /// </summary>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        /// <param name="metadataAttribute">
        /// The metadata attributeObject. 
        /// </param>
        /// <exception cref="SdmxSemmanticException">
        /// Throws Validate exception.
        /// </exception>
        public MetadataAttributeObjectCore(
            IIdentifiableObject parent, 
            Org.Sdmx.Resources.SdmxMl.Schemas.V20.structure.MetadataAttributeType metadataAttribute)
            : base(
                metadataAttribute, 
                SdmxStructureType.GetFromEnum(SdmxStructureEnumType.MetadataAttribute), 
                metadataAttribute.Annotations, 
                metadataAttribute.TextFormat, 
                metadataAttribute.representationSchemeAgency, 
                metadataAttribute.representationScheme,
                metadataAttribute.RepresentationSchemeVersionEstat, 
                metadataAttribute.conceptSchemeAgency, 
                metadataAttribute.conceptSchemeRef, 
                GetConceptSchemeVersion(metadataAttribute), 
                metadataAttribute.conceptAgency, 
                metadataAttribute.conceptRef, 
                parent)
        {
            this.metadataAttributes = new List<IMetadataAttributeObject>();
            this.presentational = TertiaryBool.GetFromEnum(TertiaryBoolEnumType.Unset);

            if (metadataAttribute.usageStatus != null)
            {
                if (metadataAttribute.usageStatus == UsageStatusTypeConstants.Mandatory)
                {
                    this.minOccurs = 1;
                    this.maxOccurs = 1;
                }
                else
                {
                    this.minOccurs = 0;
                }
            }

            if (metadataAttribute.MetadataAttribute != null)
            {
                foreach (Org.Sdmx.Resources.SdmxMl.Schemas.V20.structure.MetadataAttributeType currentMa in
                    metadataAttribute.MetadataAttribute)
                {
                    this.metadataAttributes.Add(new MetadataAttributeObjectCore(this, currentMa));
                }
            }

            try
            {
                this.Validate();
            }
            catch (SdmxSemmanticException e)
            {
                throw new SdmxSemmanticException(e, ExceptionCode.FailValidation, this);
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////BUILD FROM V2.1 SCHEMA                 //////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes a new instance of the <see cref="MetadataAttributeObjectCore"/> class.
        /// </summary>
        /// <param name="metadataAttribute">
        /// The metadata attributeObject. 
        /// </param>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        /// <exception cref="SdmxSemmanticException">
        /// Throws Validate exception.
        /// </exception>
        public MetadataAttributeObjectCore(MetadataAttributeType metadataAttribute, IIdentifiableObject parent)
            : base(metadataAttribute, SdmxStructureType.GetFromEnum(SdmxStructureEnumType.MetadataAttribute), parent)
        {
            this.metadataAttributes = new List<IMetadataAttributeObject>();
            this.presentational = TertiaryBool.GetFromEnum(TertiaryBoolEnumType.Unset);
            this.minOccurs = (metadataAttribute.minOccurs < int.MaxValue) ? decimal.ToInt32(metadataAttribute.minOccurs) : (int?)null;
           
            if (metadataAttribute.maxOccurs != null)
            {
                long res;
                if (long.TryParse(metadataAttribute.maxOccurs.ToString(), out res))
                {
                    this.maxOccurs = Convert.ToInt32(res);
                }
                else
                {
                    this.maxOccurs = null; // unbounded 
                }
            }

            if (metadataAttribute.isPresentational)
            {
                this.presentational = TertiaryBool.ParseBoolean(metadataAttribute.isPresentational);
            }

            if (metadataAttribute.MetadataAttribute != null)
            {
                foreach (MetadataAttribute currentMaType in metadataAttribute.MetadataAttribute)
                {
                    this.metadataAttributes.Add(new MetadataAttributeObjectCore(currentMaType.Content, this));
                }
            }

            try
            {
                this.Validate();
            }
            catch (SdmxSemmanticException e)
            {
                throw new SdmxSemmanticException(e, ExceptionCode.FailValidation, this);
            }
        }
        /// <summary>
        /// Create a ImmutableInstance of Codelist
        /// </summary>
        /// <param name="AgencyId">Agency Id</param>
        /// <param name="Version">Artefact Version</param>
        /// <returns>ICodelistObject</returns>
        public ICodelistMutableObject BuildCodelist(string AgencyId, string Version)
        {
            try
            {
                ICodelistMutableObject codelist = new CodelistMutableCore();
                codelist.Id       = this.Code;
                codelist.AgencyId = AgencyId;
                codelist.Version  = Version;
                if (this.Names == null)
                {
                    this.Names = new List <SdmxObjectNameDescription>();
                    this.Names.Add(new SdmxObjectNameDescription()
                    {
                        Lingua = "en", Name = Code
                    });
                }
                else
                {
                    foreach (SdmxObjectNameDescription item in this.Names)
                    {
                        codelist.AddName(item.Lingua, item.Name);
                    }
                }



                if (!this.ParsingObject.ReturnStub)
                {
                    Dictionary <string, int> Idduples = new Dictionary <string, int>();
                    //List<string> Idduples = new List<string>();
                    //try
                    //{//ci sono i duplicati ID sotto padri diversi e SDMX scoppia....
                    //    if (CodesObjects != null)
                    //        Idduples = (from c in CodesObjects
                    //                    where CodesObjects.Count(comp => comp.Id == c.Id) > 1
                    //                    select c.Id).Distinct().ToList();
                    //}
                    //catch (Exception)
                    //{
                    //    //Errore nella ricerca dei duplicati ma non fa niente
                    //}
                    foreach (ICodeMutableObject cl in CodesObjects)
                    {
                        if (!Idduples.ContainsKey(cl.Id))
                        {
                            Idduples[cl.Id] = 1;
                        }
                        else
                        {
                            Idduples[cl.Id]++;
                        }

                        if (Idduples[cl.Id] == 1)// && codelist.Items.Count(presentCode => presentCode.Id == cl.Id) == 0)
                        {
                            codelist.AddItem(cl);
                        }
                    }

                    codelist.FinalStructure = TertiaryBool.ParseBoolean(true);
                    codelist.IsPartial      = true;
                }


                if (this.ParsingObject.isReferenceOf || this.ParsingObject.ReturnStub)
                {
                    codelist.ExternalReference = TertiaryBool.ParseBoolean(true);
                    codelist.StructureURL      = RetreivalStructureUrl.Get(this, codelist.Id, codelist.AgencyId, codelist.Version);
                }
                return(codelist);
            }
            catch (SdmxException) { throw; }
            catch (Exception ex)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.CreateImmutable, ex);
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////BUILD FROM V2 SCHEMA                 //////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes a new instance of the <see cref="TextFormatObjectCore"/> class.
        /// </summary>
        /// <param name="textFormat">
        /// The text format. 
        /// </param>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        public TextFormatObjectCore(
            Org.Sdmx.Resources.SdmxMl.Schemas.V20.structure.TextFormatType textFormat, ISdmxObject parent)
            : base(_textFormatType, parent)
        {
            this._isSequence = TertiaryBool.GetFromEnum(TertiaryBoolEnumType.Unset);
            this.multilingual = TertiaryBool.GetFromEnum(TertiaryBoolEnumType.Unset);
            if (textFormat.textType != null)
            {
                string textType = textFormat.textType;
                switch (textType)
                {
                        // TODO java 0.9.9 bug. No Integer case
                        // http://www.metadatatechnology.com/mantis/view.php?id=1425
                    case TextTypeTypeConstants.BigInteger:
                        this._textType = TextType.GetFromEnum(TextEnumType.BigInteger);
                        break;
                    case TextTypeTypeConstants.Boolean:
                        this._textType = TextType.GetFromEnum(TextEnumType.Boolean);
                        break;
                    case TextTypeTypeConstants.Count:
                        this._textType = TextType.GetFromEnum(TextEnumType.Count);
                        break;
                    case TextTypeTypeConstants.Date:
                        this._textType = TextType.GetFromEnum(TextEnumType.Date);
                        break;
                    case TextTypeTypeConstants.DateTime:
                        this._textType = TextType.GetFromEnum(TextEnumType.DateTime);
                        break;
                    case TextTypeTypeConstants.Day:
                        this._textType = TextType.GetFromEnum(TextEnumType.Day);
                        break;
                    case TextTypeTypeConstants.Decimal:
                        this._textType = TextType.GetFromEnum(TextEnumType.Decimal);
                        break;
                    case TextTypeTypeConstants.Double:
                        this._textType = TextType.GetFromEnum(TextEnumType.Double);
                        break;
                    case TextTypeTypeConstants.Duration:
                        this._textType = TextType.GetFromEnum(TextEnumType.Duration);
                        break;
                    case TextTypeTypeConstants.ExclusiveValueRange:
                        this._textType = TextType.GetFromEnum(TextEnumType.ExclusiveValueRange);
                        break;
                    case TextTypeTypeConstants.Float:
                        this._textType = TextType.GetFromEnum(TextEnumType.Float);
                        break;
                    case TextTypeTypeConstants.InclusiveValueRange:
                        this._textType = TextType.GetFromEnum(TextEnumType.InclusiveValueRange);
                        break;
                    case TextTypeTypeConstants.Incremental:
                        this._textType = TextType.GetFromEnum(TextEnumType.Incremental);
                        break;
                    case TextTypeTypeConstants.Integer:
                        this._textType = TextType.GetFromEnum(TextEnumType.Integer);
                        break;
                    case TextTypeTypeConstants.Long:
                        this._textType = TextType.GetFromEnum(TextEnumType.Long);
                        break;
                    case TextTypeTypeConstants.Month:
                        this._textType = TextType.GetFromEnum(TextEnumType.Month);
                        break;
                    case TextTypeTypeConstants.MonthDay:
                        this._textType = TextType.GetFromEnum(TextEnumType.MonthDay);
                        break;
                    case TextTypeTypeConstants.ObservationalTimePeriod:
                        this._textType = TextType.GetFromEnum(TextEnumType.ObservationalTimePeriod);
                        break;
                    case TextTypeTypeConstants.Short:
                        this._textType = TextType.GetFromEnum(TextEnumType.Short);
                        break;
                    case TextTypeTypeConstants.String:
                        this._textType = TextType.GetFromEnum(TextEnumType.String);
                        break;
                    case TextTypeTypeConstants.Time:
                        this._textType = TextType.GetFromEnum(TextEnumType.Time);
                        break;
                    case TextTypeTypeConstants.Timespan:
                        this._textType = TextType.GetFromEnum(TextEnumType.Timespan);
                        break;
                    case TextTypeTypeConstants.URI:
                        this._textType = TextType.GetFromEnum(TextEnumType.Uri);
                        break;
                    case TextTypeTypeConstants.Year:
                        this._textType = TextType.GetFromEnum(TextEnumType.Year);
                        break;
                    case TextTypeTypeConstants.YearMonth:
                        this._textType = TextType.GetFromEnum(TextEnumType.YearMonth);
                        break;
                }

                if (textFormat.isSequence.HasValue)
                {
                    this._isSequence = TertiaryBool.ParseBoolean(textFormat.isSequence);
                }

                if (textFormat.maxLength.HasValue)
                {
                    this._maxLength = (long?)textFormat.maxLength;
                }

                if (textFormat.minLength.HasValue)
                {
                    this._minLength = (long?)textFormat.minLength;
                }

                if (textFormat.startValue.HasValue)
                {
                    this._startValue = (decimal)textFormat.startValue.Value;
                }

                if (textFormat.endValue.HasValue)
                {
                    this._endValue = new decimal(textFormat.endValue.Value);
                }

                if (textFormat.interval.HasValue)
                {
                    this._interval = new decimal(textFormat.interval.Value);
                }

                if (textFormat.timeInterval != null)
                {
                    this._timeInterval = textFormat.timeInterval.ToString();
                }

                if (textFormat.decimals.HasValue)
                {
                    this._decimals = (long)textFormat.decimals.Value;
                }

                if (!string.IsNullOrEmpty(textFormat.pattern))
                {
                    this._pattern = textFormat.pattern;
                }
            }

            this.Validate();
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////BUILD FROM V2.1 SCHEMA                 //////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes a new instance of the <see cref="TextFormatObjectCore"/> class.
        /// </summary>
        /// <param name="textFormatType">
        /// The text format type. 
        /// </param>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        public TextFormatObjectCore(TextFormatType textFormatType, ISdmxObject parent)
            : base(_textFormatType, parent)
        {
            this._isSequence = TertiaryBool.GetFromEnum(TertiaryBoolEnumType.Unset);
            this.multilingual = TertiaryBool.GetFromEnum(TertiaryBoolEnumType.Unset);
            if (textFormatType.textType != null)
            {
                this._textType = TextTypeUtil.GetTextType(textFormatType.textType);
            }

            if (textFormatType.isMultiLingual)
            {
                this.multilingual = TertiaryBool.ParseBoolean(textFormatType.isMultiLingual);
            }

            if (textFormatType.isSequence != null && textFormatType.isSequence.Value)
            {
                this._isSequence = TertiaryBool.ParseBoolean(textFormatType.isSequence.Value);
            }

            if (textFormatType.maxLength.HasValue)
            {
                this._maxLength = (long?)textFormatType.maxLength;
            }

            if (textFormatType.minLength != null)
            {
                this._minLength = (long?)textFormatType.minLength;
            }

            if (textFormatType.startValue.HasValue)
            {
                this._startValue = textFormatType.startValue.Value;
            }

            if (textFormatType.endValue.HasValue)
            {
                this._endValue = textFormatType.endValue.Value;
            }

            if (textFormatType.maxValue.HasValue)
            {
                this._maxValue = textFormatType.maxValue.Value;
            }

            if (textFormatType.minValue.HasValue)
            {
                this._minValue = (long)textFormatType.minValue.Value;
            }

            if (textFormatType.interval.HasValue)
            {
                this._interval = textFormatType.interval.Value;
            }

            if (textFormatType.timeInterval != null)
            {
                this._timeInterval = textFormatType.timeInterval.ToString();
            }

            if (textFormatType.decimals.HasValue)
            {
                this._decimals = (long)textFormatType.decimals.Value;
            }

            if (!string.IsNullOrEmpty(textFormatType.pattern))
            {
                this._pattern = textFormatType.pattern;
            }

            if (textFormatType.endTime != null)
            {
                this._endTime = new SdmxDateCore(textFormatType.endTime.ToString());
            }

            if (textFormatType.startTime != null)
            {
                this._startTime = new SdmxDateCore(textFormatType.startTime.ToString());
            }

            this.Validate();
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////BUILD FROM MUTABLE OBJECT                 //////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////    
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="TextFormatObjectCore"/> class.
        /// </summary>
        /// <param name="textFormatMutable">
        /// The text format mutable. 
        /// </param>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        public TextFormatObjectCore(ITextFormatMutableObject textFormatMutable, ISdmxObject parent)
            : base(textFormatMutable, parent)
        {
            this._isSequence = TertiaryBool.GetFromEnum(TertiaryBoolEnumType.Unset);
            this.multilingual = TertiaryBool.GetFromEnum(TertiaryBoolEnumType.Unset);
            this._textType = textFormatMutable.TextType;
            if (textFormatMutable.Sequence != null)
            {
                this._isSequence = textFormatMutable.Sequence;
            }

            this._maxLength = textFormatMutable.MaxLength;
            this._minLength = textFormatMutable.MinLength;
            this._startValue = textFormatMutable.StartValue;
            this._endValue = textFormatMutable.EndValue;
            this._maxValue = textFormatMutable.MaxValue;
            this._minValue = textFormatMutable.MinValue;
            this._interval = textFormatMutable.Interval;
            this._timeInterval = textFormatMutable.TimeInterval;
            this._decimals = textFormatMutable.Decimals;
            this._pattern = textFormatMutable.Pattern;
            this.Validate();
        }
 /// <summary>
 /// Write the attribute if it's value is not  null
 /// </summary>
 /// <param name="attribute">
 /// The attribute name
 /// </param>
 /// <param name="value">
 /// The attribute value
 /// </param>
 protected void TryWriteAttribute(AttributeNameTable attribute, TertiaryBool value)
 {
     if (value != null)
     {
         this.TryWriteAttribute(NameTableCache.GetAttributeName(attribute), value.EnumType);
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="TextFormatMutableCore"/> class.
        /// </summary>
        /// <param name="textFormat">
        /// The itxt. 
        /// </param>
        public TextFormatMutableCore(ITextFormat textFormat)
            : base(textFormat)
        {
            this.textType = textFormat.TextType;
            this.isSequence = textFormat.Sequence;
            this.maxLength = textFormat.MaxLength;
            this.minLength = textFormat.MinLength;
            this.startValue = textFormat.StartValue;
            this.endValue = textFormat.EndValue;
            this.interval = textFormat.Interval;
            this.maxValue = textFormat.MaxValue;
            this.minValue = textFormat.MinValue;
            this.isMultilingual = textFormat.Multilingual;
            if (textFormat.TimeInterval != null)
            {
                this.timeInterval = textFormat.TimeInterval;
            }

            this.decimals = textFormat.Decimals;
            this.pattern = textFormat.Pattern;
        }