Ejemplo n.º 1
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.º 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 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;
        }