Ejemplo n.º 1
0
        /// <summary>
        /// Persists a compound metadata attribute in the database
        /// </summary>
        /// <param name="entity">is an unsaved compound metadata data attribute</param>
        /// <returns>The saved compound metadata attribute</returns>
        /// <remarks>The attribute should have at least two other attributes as its member to be considered a compound! Also it should have at least a non empty short name.</remarks>     
        public MetadataCompoundAttribute Create(MetadataCompoundAttribute entity)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(entity.ShortName));
            //Contract.Requires(entity.DataType != null && entity.DataType.Id >= 0);
            //Contract.Requires(entity.Unit != null && entity.Unit.Id >= 0);
            Contract.Requires(entity.MetadataNestedAttributeUsages != null && entity.MetadataNestedAttributeUsages.Count >= 2);

            Contract.Ensures(Contract.Result<MetadataCompoundAttribute>() != null && Contract.Result<MetadataCompoundAttribute>().Id >= 0);
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<MetadataCompoundAttribute> repo = uow.GetRepository<MetadataCompoundAttribute>();
                repo.Put(entity);
                uow.Commit();
            }
            return (entity);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        private void addMetadataAttributeToMappingFile(MetadataCompoundAttribute compoundAttribute, XmlSchemaElement element, string internalXPath, string externalXPath)
        {
            MetadataAttribute attribute;

                if (metadataAttributeManager.MetadataAttributeRepo != null &&
                        metadataAttributeManager.MetadataAttributeRepo.Get().Where(m => m.Name.Equals(GetTypeOfName(element.Name))).Count() > 0)
                {
                    attribute = metadataAttributeManager.MetadataAttributeRepo.Get().Where(m => m.Name.Equals(GetTypeOfName(element.Name))).First();
                }
                else
                {
                    attribute = createMetadataAttribute(element);
                }

                #region generate  MappingRoute

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

                #endregion

                //Debug.WriteLine("SimpleAttribute :");
                //Debug.WriteLine("--- internal :" + childInternalXPath);
                //Debug.WriteLine("--- external :" + childExternalXPath);
                //Debug.WriteLine("--- sequence :" + element);
        }
Ejemplo n.º 4
0
        private MetadataCompoundAttribute addMetadataAttributeToMetadataCompoundAttribute(MetadataCompoundAttribute compoundAttribute, XmlSchemaElement element, string internalXPath, string externalXPath)
        {
            MetadataAttribute attribute;

                if (metadataAttributeManager.MetadataAttributeRepo != null &&
                    getExistingMetadataAttribute(GetTypeOfName(element.Name)) != null)
                {
                    attribute = metadataAttributeManager.MetadataAttributeRepo.Get().Where(m => m.Name.Equals(GetTypeOfName(element.Name))).First();
                }
                else
                {
                    attribute = createMetadataAttribute(element);
                }

                if (attribute != null)
                {
                    int min = 0;
                    if (element.MinOccurs > int.MinValue)
                    {
                        min = Convert.ToInt32(element.MinOccurs);
                    }
                    int max = 0;
                    if (element.MaxOccurs < int.MaxValue)
                        max = Convert.ToInt32(element.MaxOccurs);
                    else
                        max = int.MaxValue;

                    #region choice
                    //if element is a choise
                    XmlDocument extra = new XmlDocument();
                    //check if element is a choice
                    if (XmlSchemaUtility.IsChoiceType(element))
                    {
                        extra = XmlDatasetHelper.AddReferenceToXml(new XmlDocument(), "choice", "true", "elementType", @"extra/type");
                    }
                #endregion

                MetadataNestedAttributeUsage u1 = new MetadataNestedAttributeUsage()
                {
                    Label = element.Name,
                    Description = attribute.Description,
                    MinCardinality = min,
                    MaxCardinality = max,
                    Master = compoundAttribute,
                    Member = attribute
                };

                if (extra.DocumentElement != null) u1.Extra = extra;

                #region generate  MappingRoute

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

                #endregion

                if (compoundAttribute.MetadataNestedAttributeUsages.Where(n => n.Label.Equals(attribute.Name)).Count()==0)
                        compoundAttribute.MetadataNestedAttributeUsages.Add(u1);
                }

            return compoundAttribute;
        }
Ejemplo n.º 5
0
        private MetadataCompoundAttribute addMetadataAttributesToMetadataCompoundAttribute(MetadataCompoundAttribute compoundAttribute, List<XmlSchemaElement> elements, string internalXPath, string externalXPath)
        {
            for (int i = 0; i < elements.Count(); i++)
            {
                addMetadataAttributeToMetadataCompoundAttribute(compoundAttribute, elements.ElementAt(i), internalXPath, externalXPath);
            }

            return compoundAttribute;
        }
Ejemplo n.º 6
0
        private MetadataCompoundAttribute createMetadataCompoundAttribute(XmlSchemaElement element)
        {
            // create a compoundAttribute
            int i = 0;
            MetadataCompoundAttribute mca = getExistingMetadataCompoundAttribute(element.Name + "Type"); ;// = metadataAttributeManager.MetadataCompoundAttributeRepo.Get(p => p.Name == element.Name+"Type").FirstOrDefault();
            //Debug.WriteLine("createMetadataCompoundAttribute" + i++);
            DataType dt1 = dataTypeManager.Repo.Get(p => p.Name.ToLower().Equals("string")).FirstOrDefault();
            if (dt1 == null)
            {
                dt1 = dataTypeManager.Create("string", "A test String", System.TypeCode.String);
            }

            if (mca == null)
            {
                mca = new MetadataCompoundAttribute
                {
                    ShortName = GetTypeOfName(element.Name),
                    Name = GetTypeOfName(element.Name),
                    Description = "",
                    DataType = dt1
                };
            }

            return mca;
        }
Ejemplo n.º 7
0
        private MetadataCompoundAttribute createMetadataCompoundAttribute(XmlSchemaComplexType complexType)
        {
            // create a compoundAttribute
            MetadataCompoundAttribute mca = getExistingMetadataCompoundAttribute(complexType.Name);// = metadataAttributeManager.MetadataCompoundAttributeRepo.Get(p => p.Name == complexType.Name).FirstOrDefault();

            DataType dt1 = dataTypeManager.Repo.Get(p => p.Name.ToLower().Equals("string")).FirstOrDefault();
            if (dt1 == null)
            {
                dt1 = dataTypeManager.Create("String", "A test String", System.TypeCode.String);
            }

            if (mca == null)
            {
                mca = new MetadataCompoundAttribute
                {
                    ShortName = complexType.Name,
                    Name = complexType.Name,
                    Description = GetDescription(complexType.Annotation),
                    DataType = dt1
                };
            }

            return mca;
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
0
        private MetadataCompoundAttribute addUsageFromMetadataCompoundAttributeToMetadataCompoundAttribute(MetadataCompoundAttribute parent, MetadataCompoundAttribute compoundAttribute, XmlSchemaElement element)
        {
            if (parent.MetadataNestedAttributeUsages.Where(p => p.Label == element.Name).Count() <= 0)
            {
                 //get max
                int max = Int32.MaxValue;
                if (element.MaxOccurs < Int32.MaxValue)
                {
                    max = Convert.ToInt32(element.MaxOccurs);
                }

                MetadataNestedAttributeUsage usage = new MetadataNestedAttributeUsage()
                {
                    Label = element.Name,
                    Description = GetDescription(element.Annotation),
                    MinCardinality = Convert.ToInt32(element.MinOccurs),
                    MaxCardinality = max,
                    Master = parent,
                    Member = compoundAttribute,

                };

                #region choice
                //if element is a choise
                XmlDocument extra = new XmlDocument();
                    //check if element is a choice
                    if (XmlSchemaUtility.IsChoiceType(element))
                    {
                        extra = XmlDatasetHelper.AddReferenceToXml(new XmlDocument(), "choice", "true", "elementType",@"extra/type");
                    }

                    if (extra.DocumentElement != null) usage.Extra = extra;
                #endregion

                parent.MetadataNestedAttributeUsages.Add(usage);

            }

            return parent;
        }