Пример #1
0
 private void VerifyEntityExists(SchemaXml.Entity schemaXML)
 {
     if (!this._Entities.ContainsKey(schemaXML.Name))
     {
         this._Entities[schemaXML.Name] = new BuilderEntityMetadata();
     }
 }
Пример #2
0
 private void AddMetadataFromSchema(SchemaXml.Entity schemaXML)
 {
     this._Entities[schemaXML.Name].PluginsDisabled = schemaXML.Disableplugins == "true";
     this._Entities[schemaXML.Name].SkipUpdate      = schemaXML.Skipupdate == "true";
     this._Entities[schemaXML.Name].Metadata        = Builders.XmlImporter.GenerateAdditionalMetadata(this._Entities[schemaXML.Name].Metadata, schemaXML);
 }
Пример #3
0
 private void AddMetadataFromSchema(SchemaXml.Entity schemaXML)
 {
     this._Entities[schemaXML.Name].Metadata = Builders.XmlImporter.GenerateAdditionalMetadata(this._Entities[schemaXML.Name].Metadata, schemaXML);
 }
        private static Entity GenerateEntityNode(string logicalName, BuilderEntityMetadata builderEntityMetadata)
        {
            SchemaXml.Entity entityNode = new SchemaXml.Entity()
            {
                Name             = logicalName,
                Displayname      = builderEntityMetadata.Metadata.DisplayName.LocalizedLabels[0].Label,
                Etc              = builderEntityMetadata.Metadata.ObjectTypeCode.ToString(),
                Primaryidfield   = builderEntityMetadata.Metadata.PrimaryIdAttribute,
                Primarynamefield = builderEntityMetadata.Metadata.PrimaryNameAttribute,
                Disableplugins   = (builderEntityMetadata.PluginsDisabled == null ||
                                    builderEntityMetadata.PluginsDisabled == false ? "false" : "true"),
                Skipupdate = (builderEntityMetadata.SkipUpdate == null ||
                              builderEntityMetadata.SkipUpdate == false ? "false" : "true"),
                Fields = new SchemaXml.Fields()
                {
                    Field = new List <SchemaXml.Field>()
                }
            };

            foreach (var attribute in builderEntityMetadata.Attributes)
            {
                var AttributeMetadata = builderEntityMetadata.Metadata.Attributes.Where(a => a.LogicalName == attribute).First();

                if (!IsSupportedAttributeType(AttributeMetadata.AttributeType))
                {
                    continue;
                }

                SchemaXml.Field field = new SchemaXml.Field()
                {
                    Displayname   = AttributeMetadata.DisplayName.LocalizedLabels[0].Label,
                    Name          = AttributeMetadata.LogicalName,
                    Type          = GetFieldNodeType(AttributeMetadata),
                    LookupType    = GetFieldNodeLookupType(AttributeMetadata),
                    UpdateCompare = (builderEntityMetadata.Identifiers.Contains(AttributeMetadata.LogicalName) ? "true" : null),
                    PrimaryKey    = (entityNode.Primaryidfield == AttributeMetadata.LogicalName ? "true" : null),
                    Customfield   = (AttributeMetadata.IsCustomAttribute == true ? "true" : null)
                };

                entityNode.Fields.Field.Add(field);
            }

            entityNode.Fields.Field.Sort((x, y) => string.Compare(x.Name, y.Name));

            if (builderEntityMetadata.RelatedEntities.Count > 0)
            {
                entityNode.Relationships = new SchemaXml.Relationships()
                {
                    Relationship = new List <SchemaXml.Relationship>()
                };

                foreach (var relationshipname in builderEntityMetadata.RelatedEntities.Keys)
                {
                    var relationshipMetadata = builderEntityMetadata.Metadata.ManyToManyRelationships.Where(x => x.IntersectEntityName == relationshipname).First();

                    string targetPrimaryKey = relationshipMetadata.Entity2IntersectAttribute;
                    if (relationshipMetadata.Entity1LogicalName == relationshipMetadata.Entity2LogicalName)
                    {
                        targetPrimaryKey = relationshipMetadata.Entity2IntersectAttribute.Substring(0, relationshipMetadata.Entity2IntersectAttribute.Length - 3);
                    }

                    entityNode.Relationships.Relationship.Add(new SchemaXml.Relationship()
                    {
                        Name                      = relationshipname,
                        ManyToMany                = "true",
                        Isreflexive               = (relationshipMetadata.Entity1LogicalName == relationshipMetadata.Entity2LogicalName).ToString().ToLower(),
                        RelatedEntityName         = relationshipMetadata.IntersectEntityName,
                        M2mTargetEntity           = relationshipMetadata.Entity2LogicalName,
                        M2mTargetEntityPrimaryKey = targetPrimaryKey
                    });
                }
            }

            return(entityNode);
        }