示例#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);
        }
        /// <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);
            }
        }
示例#3
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())));
        }
示例#4
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);
            }
        }
示例#5
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>
        /// 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);
            }
        }
示例#8
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);
            }
        }