Inheritance: BusinessEntity
Example #1
0
        public MetadataAttributeUsage AddMetadataAtributeUsage(MetadataPackage package, MetadataAttribute attribute, string label, string description, int minCardinality, int maxCardinality)
        {
            Contract.Requires(package != null && package.Id >= 0);
            Contract.Requires(attribute != null && attribute.Id >= 0);

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

            MetadataPackageRepo.Reload(package);
            MetadataPackageRepo.LoadIfNot(package.MetadataAttributeUsages);
            int count = 0;
            try
            {
                count = (from v in package.MetadataAttributeUsages
                 where v.MetadataAttribute.Id.Equals(attribute.Id)
                 select v
                         )
                         .Count();
            }
            catch { }

            MetadataAttributeUsage usage = new MetadataAttributeUsage()
            {
                MetadataPackage = package,
                MetadataAttribute = attribute,
                // if there is no label provided, use the attribute name and a sequence number calculated by the number of occurrences of that attribute in the current structure
                Label = !string.IsNullOrWhiteSpace(label) ? label : (count <= 0 ? attribute.Name : string.Format("{0} ({1})", attribute.Name, count)),
                Description = description,
                MinCardinality = minCardinality,
                MaxCardinality = maxCardinality,
            };
            package.MetadataAttributeUsages.Add(usage);
            attribute.UsedIn.Add(usage);

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<MetadataAttributeUsage> repo = uow.GetRepository<MetadataAttributeUsage>();
                repo.Put(usage);
                uow.Commit();
            }
            return (usage);
        }
Example #2
0
        public bool Delete(MetadataPackage entity)
        {
            Contract.Requires(entity != null);
            Contract.Requires(entity.Id >= 0);

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<MetadataPackage> repo = uow.GetRepository<MetadataPackage>();
                entity = repo.Reload(entity);
                repo.Delete(entity);
                uow.Commit();
            }
            // if any problem was detected during the commit, an exception will be thrown!
            return (true);
        }
Example #3
0
        public MetadataPackage Create(string name, string description, bool isEnabled = false)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(name));

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

            MetadataPackage e = new MetadataPackage()
            {
                Name = name,
                Description = description,
                IsEnabled = isEnabled,
            };
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<MetadataPackage> repo = uow.GetRepository<MetadataPackage>();
                repo.Put(e);
                uow.Commit();
            }
            return (e);
        }
Example #4
0
        public MetadataPackage Update(MetadataPackage entity)
        {
            Contract.Requires(entity != null, "provided entity can not be null");
            Contract.Requires(entity.Id >= 0, "provided entity must have a permanent ID");

            Contract.Ensures(Contract.Result<MetadataPackage>() != null && Contract.Result<MetadataPackage>().Id >= 0, "No entity is persisted!");

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<MetadataPackage> repo = uow.GetRepository<MetadataPackage>();
                repo.Put(entity); // Merge is required here!!!!
                uow.Commit();
            }
            return (entity);
        }
Example #5
0
        private void addMetadataAttributeToMetadataPackageUsage(MetadataPackage packageUsage, XmlSchemaElement element, string internalXPath, string externalXPath)
        {
            MetadataAttribute attribute = createMetadataAttribute(element);

                if (attribute != null)
                {
                    int min = 0;

                    if (element.MinOccurs > int.MinValue)
                        min = Convert.ToInt32(element.MinOccurs);
                    else
                        min = int.MinValue;

                    int max = 0;
                    if (element.MaxOccurs < int.MaxValue)
                        max = Convert.ToInt32(element.MaxOccurs);
                    else
                        max = int.MaxValue;

                    if (packageUsage.MetadataAttributeUsages.Where(p => p.MetadataAttribute == attribute).Count() <= 0)
                        metadataPackageManager.AddMetadataAtributeUsage(packageUsage, attribute, element.Name, attribute.Description, min, max);

                #region generate  MappingRoute

                addToExportMappingFile(mappingFileInternalToExternal, internalXPath, externalXPath, max, element.Name, attribute.Name);
                addToImportMappingFile(mappingFileExternalToInternal, externalXPath, internalXPath, max, element.Name, attribute.Name);

                #endregion
            }
        }
Example #6
0
 private void addMetadataAttributesToMetadataPackageUsage(MetadataPackage packageUsage, List<XmlSchemaElement> elements, string internalXPath, string externalXPath)
 {
     for (int i = 0; i<elements.Count();i++)
     {
         addMetadataAttributeToMetadataPackageUsage(packageUsage, elements.ElementAt(i), internalXPath, externalXPath);
     }
 }
Example #7
0
        private void addUsageFromMetadataCompoundAttributeToPackage(MetadataPackage package, MetadataCompoundAttribute compoundAttribute, XmlSchemaElement element)
        {
            if (package.MetadataAttributeUsages.Where(p => p.Label == element.Name).Count() <= 0)
            {
                int min = 0;

                if (element.MinOccurs > int.MinValue)
                    min = Convert.ToInt32(element.MinOccurs);
                else
                    min = int.MinValue;

                int max = 0;
                if (element.MaxOccurs < int.MaxValue)
                    max = Convert.ToInt32(element.MaxOccurs);
                else
                    max = int.MaxValue;

                metadataPackageManager.AddMetadataAtributeUsage(package, compoundAttribute, element.Name, GetDescription(element.Annotation), min, max);
            }
        }