/// <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);
            }
        }
        /// <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);
            }
        }
Example #4
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);
            }
        }
        /// <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>
        /// 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);
            }
        }