Inheritance: MetadataAttribute
        /// <summary>
        /// Persists a simple metadata attribute is the database.
        /// </summary>
        /// <param name="entity">is an unsaved simple metadata attribute.</param>
        /// <returns>The saved attribute.</returns>
        /// <remarks>The method does not check duplicate names.</remarks>
        public MetadataSimpleAttribute Create(MetadataSimpleAttribute entity)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(entity.ShortName));
            Contract.Requires(entity.DataType != null && entity.DataType.Id >= 0);

            Contract.Ensures(Contract.Result<MetadataSimpleAttribute>() != null && Contract.Result<MetadataSimpleAttribute>().Id >= 0);

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<MetadataSimpleAttribute> repo = uow.GetRepository<MetadataSimpleAttribute>();
                repo.Put(entity);
                uow.Commit();
            }
            return (entity);
        }
Beispiel #2
0
        private void createMetadataAttribute()
        {
            //UnitManager um = new UnitManager();
            //Unit km = um.Create("Kilometer", "Km", "This is the Kilometer", "Length", MeasurementSystem.Metric);
            DataTypeManager dtManager = new DataTypeManager();
            DataType dt1 = dtManager.Repo.Get(p => p.Name.Equals("String")).FirstOrDefault();
            if (dt1 == null)
            {
                dt1 = dtManager.Create("String", "A test String", System.TypeCode.String);
            }

            MetadataAttributeManager maManager = new MetadataAttributeManager();

            // for unique name checks USE maManager.MetadataAttributeRepo that is searching both simple and compound attribute names
            var msa1 = maManager.MetadataAttributeRepo.Get(p => p.ShortName.Equals("Simple 1")).FirstOrDefault();
            if (msa1 == null)
            {
                msa1 = new MetadataSimpleAttribute()
                {
                    ShortName = "Simple 1",
                    DataType = dt1,
                };
                maManager.Create((MetadataSimpleAttribute)msa1);
            }
            var msa2 = maManager.MetadataAttributeRepo.Get(p => p.ShortName.Equals("Simple 2")).FirstOrDefault();
            if (msa2 == null)
            {
                msa2 = new MetadataSimpleAttribute()
                {
                    ShortName = "Simple 2",
                    DataType = dt1,
                };
                maManager.Create((MetadataSimpleAttribute)msa2);
            }

            MetadataCompoundAttribute mca1 = (MetadataCompoundAttribute)maManager.MetadataAttributeRepo.Get(p => p.ShortName.Equals("Compound 1")).FirstOrDefault();
            if (mca1 == null)
            {
                mca1 = new MetadataCompoundAttribute()
                {
                    ShortName = "Compound 1",
                    DataType = dt1,

                };
                MetadataNestedAttributeUsage u1 = new MetadataNestedAttributeUsage()
                {
                    Label = "First member",
                    Description = "I am a link between Compound 1 and Simple 1",
                    MinCardinality = 0,
                    MaxCardinality = 2,
                    Master = mca1,
                    Member = msa1,
                };
                mca1.MetadataNestedAttributeUsages.Add(u1);

                MetadataNestedAttributeUsage u2 = new MetadataNestedAttributeUsage()
                {
                    Label = "Second member",
                    Description = "I am a link between Compound 1 and Simple 2",
                    MinCardinality = 0,
                    MaxCardinality = 2,
                    Master = mca1,
                    Member = msa2,
                };
                mca1.MetadataNestedAttributeUsages.Add(u2);

                maManager.Create(mca1);
            }

            maManager.Delete(msa1);
        }
        /// <summary>
        /// Creates a simple metadata attribute and persists it in the database
        /// </summary>
        /// <param name="shortName"></param>
        /// <param name="name"></param>
        /// <param name="description"></param>
        /// <param name="isMultiValue">Indicates whether the attribute accepts multiple values.</param>
        /// <param name="isBuiltIn">If yes, the attribute is created by the system itself and is not delete-able</param>
        /// <param name="scope">Creates a context of ownership for the attribute so that the modules, or different parts of the system can use it i.e. for filtering.</param>
        /// <param name="measurementScale"></param>
        /// <param name="containerType"></param>
        /// <param name="entitySelectionPredicate"></param>
        /// <param name="dataType"></param>
        /// <param name="unit"></param>
        /// <param name="methodology"></param>
        /// <param name="functions"></param>
        /// <param name="globalizationInfos"></param>
        /// <param name="constraints"></param>
        /// <returns></returns>
        public MetadataSimpleAttribute Create(string shortName, string name, string description, bool isMultiValue, bool isBuiltIn, string scope, MeasurementScale measurementScale, DataContainerType containerType, string entitySelectionPredicate,
            DataType dataType, Unit unit, Methodology methodology,
            //Classifier classifier,
            ICollection<AggregateFunction> functions, ICollection<GlobalizationInfo> globalizationInfos, ICollection<Constraint> constraints
            )
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(shortName));
            Contract.Requires(dataType != null && dataType.Id >= 0);
            //Contract.Requires(unit != null && unit.Id >= 0);

            Contract.Ensures(Contract.Result<MetadataSimpleAttribute>() != null && Contract.Result<MetadataSimpleAttribute>().Id >= 0);

            MetadataSimpleAttribute entity = new MetadataSimpleAttribute()
            {
                ShortName = shortName,
                Name = name,
                Description = description,
                IsMultiValue = isMultiValue,
                IsBuiltIn = isBuiltIn,
                Scope = scope,
                MeasurementScale = measurementScale,
                ContainerType = containerType,
                EntitySelectionPredicate = entitySelectionPredicate,
                DataType = dataType,
                Unit = unit,
                Methodology = methodology,
                AggregateFunctions = functions,
                GlobalizationInfos = globalizationInfos,
                Constraints = constraints,
            };
            //if (classifier != null && classifier.Id > 0)
            //    entity.Classification = classifier;
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<MetadataSimpleAttribute> repo = uow.GetRepository<MetadataSimpleAttribute>();
                repo.Put(entity);
                uow.Commit();
            }
            return (entity);
        }