Пример #1
0
        public string GetNameForRelationship(
            EntityMetadata entityMetadata
            , RelationshipMetadataBase relationshipMetadata
            , EntityRole?reflexiveRole
            , ICodeGenerationServiceProvider iCodeGenerationServiceProvider
            )
        {
            string str = reflexiveRole.HasValue ? reflexiveRole.Value.ToString() : string.Empty;

            string keyRelationship = entityMetadata.MetadataId.Value.ToString() + relationshipMetadata.MetadataId.Value + str;

            if (this._knowNames.ContainsKey(keyRelationship))
            {
                return(this._knowNames[keyRelationship]);
            }

            string validName = NamingService.CreateValidName(relationshipMetadata.SchemaName + (!reflexiveRole.HasValue ? string.Empty : reflexiveRole.Value == EntityRole.Referenced ? "_Referenced" : "_Referencing"));

            Dictionary <string, string> knownNamesForEntityMetadata = this._knowNames.Where(d => d.Key.StartsWith(entityMetadata.MetadataId.Value.ToString())).ToDictionary(d => d.Key, d => d.Value);

            validName = ResolveConflictName(validName, s => this._reservedAttributeNames.Contains(s) || knownNamesForEntityMetadata.ContainsValue(s) || string.Equals(s, _typeName, StringComparison.InvariantCultureIgnoreCase));

            this._knowNames.Add(keyRelationship, validName);

            return(validName);
        }
Пример #2
0
 public RelationshipMetadataProxy(List <EntityMetadataProxy> entities, EntityMetadataProxy originatingentity, ManyToManyRelationshipMetadata relationshipMetadata)
 {
     this.originatingentity = originatingentity;
     Parent   = entities.FirstOrDefault(e => e.LogicalName == relationshipMetadata.Entity1LogicalName);
     Child    = entities.FirstOrDefault(e => e.LogicalName == relationshipMetadata.Entity2LogicalName);
     Metadata = relationshipMetadata;
 }
Пример #3
0
 public String GetNameForRelationship(
     EntityMetadata entityMetadata, RelationshipMetadataBase relationshipMetadata,
     EntityRole?reflexiveRole, IServiceProvider services)
 {
     return(DefaultNamingService.GetNameForRelationship(
                entityMetadata, relationshipMetadata, reflexiveRole, services));
 }
Пример #4
0
        public void WriteData(IConnection connection, IDatabaseInterface databaseInterface, IDatastore dataObject, ReportProgressMethod reportProgress)
        {
            this.reportProgress = reportProgress;

            reportProgress(new SimpleProgressReport("Connection to crm"));
            CrmConnection crmConnection = (CrmConnection)connection.GetConnection();

            this.service    = new OrganizationService(crmConnection);
            this.dataObject = dataObject;

            reportProgress(new SimpleProgressReport("Load required metadata from crm"));
            entity1Metadata      = Crm2013Wrapper.Crm2013Wrapper.GetEntityMetadata(this.service, this.Configuration.Entity1Name);
            entity2Metadata      = Crm2013Wrapper.Crm2013Wrapper.GetEntityMetadata(this.service, this.Configuration.Entity2Name.Split(';')[0]);
            relationshipMetadata = Crm2013Wrapper.Crm2013Wrapper.GetRelationshipMetadata(this.service, this.Configuration.Entity2Name.Split(';')[1]) as ManyToManyRelationshipMetadata;

            reportProgress(new SimpleProgressReport("Cache keys of existing " + entity1Metadata.LogicalName + "-records"));
            var entity1Resolver = new JoinResolver(this.service, entity1Metadata, this.Configuration.Entity1Mapping);

            this.existingEntities1 = entity1Resolver.BuildMassResolverIndex();

            reportProgress(new SimpleProgressReport("Cache keys of existing " + entity2Metadata.LogicalName + "-records"));
            var entity2Resolver = new JoinResolver(this.service, entity2Metadata, this.Configuration.Entity2Mapping);

            this.existingEntities2 = entity2Resolver.BuildMassResolverIndex();

            RelateEntities();
        }
Пример #5
0
        /// <inheritdoc />
        public string GetNameForRelationship(EntityMetadata entityMetadata, RelationshipMetadataBase relationshipMetadata, EntityRole?reflexiveRole, IServiceProvider services)
        {
            string value = _defaultService.GetNameForRelationship(entityMetadata, relationshipMetadata, reflexiveRole, services);

            value = ModifyPublisher(value);
            return(value);
        }
        public void FillSolutionComponent(ICollection <SolutionComponent> result, SolutionImageComponent solutionImageComponent)
        {
            if (solutionImageComponent == null ||
                string.IsNullOrEmpty(solutionImageComponent.SchemaName)
                )
            {
                return;
            }

            RelationshipMetadataBase metaData = _source.GetRelationshipMetadata(solutionImageComponent.SchemaName);

            if (metaData != null)
            {
                var component = new SolutionComponent()
                {
                    ComponentType = new OptionSetValue(this.ComponentTypeValue),

                    ObjectId = metaData.MetadataId.Value,

                    RootComponentBehaviorEnum = SolutionComponent.Schema.OptionSets.rootcomponentbehavior.Include_Subcomponents_0,
                };

                if (solutionImageComponent.RootComponentBehavior.HasValue)
                {
                    component.RootComponentBehavior = new OptionSetValue(solutionImageComponent.RootComponentBehavior.Value);
                }

                result.Add(component);
            }
        }
        public string GetFileName(string connectionName, Guid objectId, string fieldTitle, FileExtension extension)
        {
            RelationshipMetadataBase metaData = _source.GetRelationshipMetadata(objectId);

            if (metaData != null)
            {
                if (metaData is OneToManyRelationshipMetadata)
                {
                    var relationship = metaData as OneToManyRelationshipMetadata;

                    return(string.Format("{0}.{1}.{2}.{3} - {4}.{5}"
                                         , connectionName
                                         , relationship.ReferencingEntity
                                         , relationship.ReferencingAttribute
                                         , relationship.SchemaName
                                         , fieldTitle
                                         , extension.ToStr()
                                         ));
                }
                else if (metaData is ManyToManyRelationshipMetadata)
                {
                    var relationship = metaData as ManyToManyRelationshipMetadata;

                    return(string.Format("{0}.{1} - {2}.{3} - {4}.{5}", connectionName, relationship.Entity1LogicalName, relationship.Entity2LogicalName, relationship.SchemaName, fieldTitle, extension.ToStr()));
                }
            }

            return(string.Format("{0}.ComponentType {1} - {2} - {3}.{4}", connectionName, this.ComponentTypeValue, objectId, fieldTitle, extension.ToStr()));
        }
        public override bool GenerateRelationship(RelationshipMetadataBase relationshipMetadata, EntityMetadata otherEntityMetadata, IServiceProvider services)
        {
            bool whitelist, blacklist = false;

            whitelist = _whitelistFilters.Any(filter => filter.GenerateRelationship(relationshipMetadata, otherEntityMetadata, services));

            if (whitelist)
            {
                Trace.TraceInformation($"Whitelist: {relationshipMetadata.SchemaName} is on the whitelist and will be generated.");
            }
            else
            {
                if (Configuration.Filtering.HasWhitelist && Configuration.Filtering.Whitelist.Filter == WhitelistFilter.Exclusive)
                {
                    return(false);
                }

                blacklist = _blacklistFilters.Any(filter => filter.GenerateRelationship(relationshipMetadata, otherEntityMetadata, services));

                if (!blacklist)
                {
                    Trace.TraceInformation($"Blacklist: {relationshipMetadata.SchemaName} is on the blacklist and will not be generated.");
                }
            }

            return(whitelist || blacklist);
        }
Пример #9
0
        public override string GetNameForRelationship(EntityMetadata entityMetadata, RelationshipMetadataBase relationshipMetadata, EntityRole?reflexiveRole, IServiceProvider services)
        {
            string returnValue  = string.Empty;
            string defaultValue = base.GetNameForRelationship(entityMetadata, relationshipMetadata, reflexiveRole, services);

            foreach (var namer in _namers)
            {
                Trace.Debug($"Executing naming rule {nameof(GetNameForRelationship)} using {namer.GetType().FullName}");

                returnValue = namer.GetNameForRelationship(entityMetadata, relationshipMetadata, reflexiveRole, services);
            }

            if (string.IsNullOrEmpty(returnValue))
            {
                returnValue = defaultValue;
            }

            var cacheItem = DynamicsMetadataCache.Relationships.GetOrParse(relationshipMetadata);

            if (cacheItem != null)
            {
                cacheItem.GeneratedTypeName = returnValue;
            }

            DynamicsMetadataCache.Relationships.Set(cacheItem);

            return(string.IsNullOrEmpty(returnValue) ? defaultValue : returnValue);
        }
        public string GetDisplayName(SolutionComponent solutionComponent)
        {
            RelationshipMetadataBase metaData = _source.GetRelationshipMetadata(solutionComponent.ObjectId.Value);

            if (metaData != null)
            {
                if (metaData is OneToManyRelationshipMetadata)
                {
                    var relationship = metaData as OneToManyRelationshipMetadata;

                    return(string.Format("{0}.{1} ManyToOne -> {2}"
                                         , relationship.ReferencingEntity
                                         , relationship.ReferencingAttribute
                                         , relationship.ReferencedEntity
                                         ));
                }
                else if (metaData is ManyToManyRelationshipMetadata)
                {
                    var relationship = metaData as ManyToManyRelationshipMetadata;

                    return(string.Format("{0} - {1} ManyToMany", relationship.Entity1LogicalName, relationship.Entity2LogicalName));
                }
            }

            return(null);
        }
Пример #11
0
        public EntityRelationship(RelationshipMetadataBase relation, EntityRole role, string originatingEntity, FetchXmlBuilder fxb, string originatingParent = "")
        {
            Relationship = relation;
            Role         = role;

            if (relation is OneToManyRelationshipMetadata om)
            {
                if (role == EntityRole.Referenced)
                {
                    Name = fxb.GetEntityDisplayName(om.ReferencedEntity) + "." + om.ReferencedAttribute + " <- " +
                           fxb.GetEntityDisplayName(om.ReferencingEntity) + "." + om.ReferencingAttribute;
                }
                else
                {
                    Name = fxb.GetEntityDisplayName(om.ReferencingEntity) + "." + om.ReferencingAttribute + " -> " +
                           fxb.GetEntityDisplayName(om.ReferencedEntity) + "." + om.ReferencedAttribute;
                }
            }
            else if (relation is ManyToManyRelationshipMetadata mm)
            {
                if (fxb.NeedToLoadEntity(mm.Entity1LogicalName))
                {
                    fxb.LoadEntityDetails(mm.Entity1LogicalName, null, false);
                }

                if (fxb.NeedToLoadEntity(mm.Entity2LogicalName))
                {
                    fxb.LoadEntityDetails(mm.Entity2LogicalName, null, false);
                }

                var entity1PrimaryKey = fxb.GetPrimaryIdAttribute(mm.Entity1LogicalName);
                var entity2PrimaryKey = fxb.GetPrimaryIdAttribute(mm.Entity2LogicalName);

                if (mm.Entity1LogicalName == originatingEntity && role == EntityRole.Referencing)
                {
                    Name = fxb.GetEntityDisplayName(mm.Entity1LogicalName) + "." + entity1PrimaryKey + " -> " + mm.IntersectEntityName + "." + mm.Entity1IntersectAttribute;
                }
                else if (mm.Entity2LogicalName == originatingEntity && role == EntityRole.Referenced)
                {
                    Name = fxb.GetEntityDisplayName(mm.Entity2LogicalName) + "." + entity2PrimaryKey + " -> " + mm.IntersectEntityName + "." + mm.Entity2IntersectAttribute;
                }
                else if (mm.IntersectEntityName == originatingEntity)
                {
                    if (mm.Entity1LogicalName == originatingParent && role == EntityRole.Referencing)
                    {
                        Name = mm.IntersectEntityName + "." + mm.Entity2IntersectAttribute + " -> " + fxb.GetEntityDisplayName(mm.Entity2LogicalName) + "." + entity2PrimaryKey;
                    }
                    else if (mm.Entity2LogicalName == originatingParent && role == EntityRole.Referenced)
                    {
                        Name = mm.IntersectEntityName + "." + mm.Entity1IntersectAttribute + " -> " + fxb.GetEntityDisplayName(mm.Entity1LogicalName) + "." + entity1PrimaryKey;
                    }
                }
                if (string.IsNullOrEmpty(Name))
                {
                    Name = "? " + mm.IntersectEntityName + ": " + mm.Entity1LogicalName + "." + mm.Entity1IntersectAttribute + " -> " +
                           mm.Entity2LogicalName + "." + mm.Entity2IntersectAttribute;
                }
            }
        }
Пример #12
0
 public bool GenerateRelationship(RelationshipMetadataBase relationshipMetadata, EntityMetadata otherEntityMetadata, IServiceProvider services)
 {
     if (!GenerateEntityRelationships)
     {
         return(false);
     }
     return(DefaultService.GenerateRelationship(relationshipMetadata, otherEntityMetadata, services));
 }
 public CodeTypeReference GetTypeForRelationship(
     RelationshipMetadataBase relationshipMetadata
     , EntityMetadata otherEntityMetadata
     , ICodeGenerationServiceProvider iCodeGenerationServiceProvider
     )
 {
     return(this.TypeRef(iCodeGenerationServiceProvider.NamingService.GetNameForEntity(otherEntityMetadata, iCodeGenerationServiceProvider)));
 }
Пример #14
0
        public string GetNameForRelationship(EntityMetadata entityMetadata, RelationshipMetadataBase relationshipMetadata, EntityRole?reflexiveRole, IServiceProvider services)
        {
            var defaultName = DefaultService.GetNameForRelationship(entityMetadata, relationshipMetadata, reflexiveRole, services);

            return(CamelCaseMemberNames
                ? CamelCaser.Case(defaultName)
                : defaultName);
        }
Пример #15
0
        async Task <CodeTypeReference> ITypeMappingService.GetTypeForRelationshipAsync(
            RelationshipMetadataBase relationshipMetadata, EntityMetadata otherEntityMetadata,
            IServiceProvider services)
        {
            var nameForEntity = await((INamingService)services?.GetService(typeof(INamingService)))?.GetNameForEntityAsync(otherEntityMetadata, services);

            return(this.TypeRef(nameForEntity));
        }
 public bool GenerateRelationship(RelationshipMetadataBase relationshipMetadata, EntityMetadata otherEntityMetadata, IServiceProvider services)
 {
     if (!GenerateEntityRelationships)
     {
         return false;
     }
     return DefaultService.GenerateRelationship(relationshipMetadata, otherEntityMetadata, services);
 }
Пример #17
0
        public bool GenerateRelationship(RelationshipMetadataBase relationshipMetadata, EntityMetadata otherEntityMetadata,
                                         IServiceProvider services)
        {
            if (relationshipMetadata.IsCustomRelationship.HasValue && relationshipMetadata.IsCustomRelationship.Value)
            {
                return(false);
            }

            return(defaultService.GenerateRelationship(relationshipMetadata, otherEntityMetadata, services));
        }
Пример #18
0
        private void UpdateRelationshipMetadata(RelationshipMetadataBase relationshipMetadataBase)
        {
            var request = new UpdateRelationshipRequest()
            {
                Relationship = relationshipMetadataBase,
                MergeLabels  = false,
            };

            var response = (UpdateRelationshipResponse)_service.Execute(request);
        }
Пример #19
0
        public bool GenerateRelationship(RelationshipMetadataBase relationshipMetadata, EntityMetadata otherEntityMetadata, IServiceProvider services)
        {
            if (relationshipMetadata == null)
            {
                throw new ArgumentNullException(nameof(relationshipMetadata));
            }

            //Console.WriteLine("Added relationship '{0}'.", relationshipMetadata.SchemaName);
            //return _defaultService.GenerateRelationship(relationshipMetadata, otherEntityMetadata, services);
            return(false);
        }
        public string GetManagedName(SolutionComponent solutionComponent)
        {
            RelationshipMetadataBase metaData = _source.GetRelationshipMetadata(solutionComponent.ObjectId.Value);

            if (metaData != null)
            {
                return(metaData.IsManaged.ToString());
            }

            return(null);
        }
Пример #21
0
        public void DeleteRelationship(string entity, string fromEntity, string attributeHint = null)
        {
            RelationshipMetadataBase relationship = FindAssociationRelationship(fromEntity, entity, attributeHint);

            if (relationship == null)
            {
                // No relationship between entities. Throw exception
                throw new KeyNotFoundException(string.Format("No (unique) relationship from {0} to {1}", entity, fromEntity));
            }

            DeleteRelationship(relationship.SchemaName);
        }
Пример #22
0
        protected internal override void SetParametersOnRelationship(RelationshipMetadataBase relationship)
        {
            base.SetParametersOnRelationship(relationship);

            if (relationship is OneToManyRelationshipMetadata)
            {
                if (IsHierarchical.HasValue)
                {
                    ((OneToManyRelationshipMetadata)relationship).IsHierarchical = IsHierarchical.Value;
                }
            }
        }
Пример #23
0
        protected override bool?GenerateRelationship(RelationshipMetadataBase relationshipMetadata, EntityMetadata otherEntityMetadata)
        {
            if (relationshipMetadata.IsCustomRelationship.HasValue && relationshipMetadata.IsCustomRelationship.Value && FilterConfiguration.Customizations.CustomizationStrategy == CustomizationStrategy.UncustomizedOnly)
            {
                return(false);
            }
            else if (relationshipMetadata.IsCustomRelationship.HasValue && !relationshipMetadata.IsCustomRelationship.Value && FilterConfiguration.Customizations.CustomizationStrategy == CustomizationStrategy.CustomOnly)
            {
                return(false);
            }

            return(FilterConfiguration.Customizations.CustomizationStrategy == CustomizationStrategy.Default ? (bool?)null : true);
        }
Пример #24
0
        bool ICodeWriterFilterService.GenerateRelationship(RelationshipMetadataBase relationshipMetadata, EntityMetadata otherEntityMetadata,
                                                           IServiceProvider services)
        {
            HashSet <string> relationships;

            if (!allRelationships.Contains(relationshipMetadata.SchemaName) &&
                entityRelationships.TryGetValue(relationshipMetadata.SchemaName, out relationships) &&
                relationships.Any() && !relationships.Contains(relationshipMetadata.SchemaName))
            {
                return(false);
            }
            return(this.DefaultService.GenerateRelationship(relationshipMetadata, otherEntityMetadata, services));
        }
Пример #25
0
        protected internal override void SetParametersOnRelationship(RelationshipMetadataBase relationship)
        {
            base.SetParametersOnRelationship(relationship);

            if (relationship is OneToManyRelationshipMetadata internalRelationship)
            {
                if (IsHierarchical.HasValue)
                {
                    if (string.Equals(internalRelationship.ReferencingEntity, internalRelationship.ReferencedEntity, StringComparison.InvariantCultureIgnoreCase))
                    {
                        ((OneToManyRelationshipMetadata)relationship).IsHierarchical = IsHierarchical.Value;
                    }
                }
            }
        }
Пример #26
0
        public void Disassociate(string addEntity, Guid addEntityId, string toEntity, Guid toEntityId, string addAttributeHint = null)
        {
            MetadataRepository       repository   = new MetadataRepository();
            RelationshipMetadataBase relationship = repository.FindAssociationRelationship(toEntity, addEntity, addAttributeHint);

            if (relationship == null)
            {
                // No relationship between entities. Throw exception
                throw new KeyNotFoundException(string.Format("No (unique) relationship from {0} to {1}", addEntity, toEntity));
            }

            CrmContext.OrganizationProxy.Disassociate(toEntity, toEntityId, new Relationship(relationship.SchemaName), new EntityReferenceCollection()
            {
                new EntityReference(addEntity, addEntityId)
            });
        }
        public string GetName(SolutionComponent solutionComponent)
        {
            if (solutionComponent == null || !solutionComponent.ObjectId.HasValue)
            {
                return("null");
            }

            RelationshipMetadataBase metaData = _source.GetRelationshipMetadata(solutionComponent.ObjectId.Value);

            if (metaData != null)
            {
                return(metaData.SchemaName);
            }

            return(solutionComponent.ObjectId.ToString());
        }
        public override bool GenerateRelationship(RelationshipMetadataBase relationshipMetadata, EntityMetadata otherEntityMetadata, IServiceProvider services)
        {
            if (DynamicsMetadataCache.Relationships.HasBy(relationshipMetadata))
            {
                return(true);
            }

            Services = services;
            bool?value = GenerateRelationship(relationshipMetadata, otherEntityMetadata);

            switch (Strategy)
            {
            case FilterListStrategy.Whitelist:
                var whitelistConfig = FilterConfiguration as WhitelistElement;

                if (value.HasValue)
                {
                    if (value.Value)
                    {
                        DynamicsMetadataCache.Relationships.AddBy(relationshipMetadata);
                    }

                    return(value.Value);
                }
                else
                {
                    var cacheItem = DynamicsMetadataCache.Relationships.Parse(relationshipMetadata);

                    // We said that we want to generate the entity, so by default we'll cache the relationships for the entity as well.
                    if ((!string.IsNullOrEmpty(cacheItem.FromEntity) &&
                         DynamicsMetadataCache.Entities.HasBy(cacheItem.FromEntity)) ||
                        (!string.IsNullOrEmpty(cacheItem.ToEntity) &&
                         DynamicsMetadataCache.Entities.HasBy(cacheItem.ToEntity)))
                    {
                        DynamicsMetadataCache.Relationships.AddBy(relationshipMetadata);
                    }
                }

                return(whitelistConfig.Filter == WhitelistFilter.Inclusive);

            case FilterListStrategy.Blacklist:
                return(!value.HasValue ? true : !value.Value);
            }

            // never gets here.
            return(value.Value);
        }
Пример #29
0
        public bool GenerateRelationship(
            RelationshipMetadataBase relationshipMetadata
            , EntityMetadata otherEntityMetadata
            , CodeGenerationRelationshipType relationshipType
            , ICodeGenerationServiceProvider iCodeGenerationServiceProvider
            )
        {
            if (otherEntityMetadata == null)
            {
                return(false);
            }

            if (relationshipType == CodeGenerationRelationshipType.ManyToManyRelationship)
            {
                if (!_config.GenerateManyToMany)
                {
                    return(false);
                }
            }
            else if (relationshipType == CodeGenerationRelationshipType.OneToManyRelationship)
            {
                if (!_config.GenerateOneToMany)
                {
                    return(false);
                }
            }
            else if (relationshipType == CodeGenerationRelationshipType.ManyToOneRelationship)
            {
                if (!_config.GenerateManyToOne)
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            var generateEntity = GenerateEntity(otherEntityMetadata, iCodeGenerationServiceProvider);

            if (!generateEntity)
            {
                return(false);
            }

            return(true);
        }
Пример #30
0
        public void UpdateRelationship(RelationshipMetadataBase relationship)
        {
            OrganizationRequest request = new OrganizationRequest("UpdateRelationship")
            {
                Parameters = new ParameterCollection
                {
                    { "Relationship", relationship },
                    { "MergeLabels", true }
                }
            };

            if (CrmContext.ActiveSolution != null)
            {
                request.Parameters.Add("SolutionUniqueName", CrmContext.ActiveSolution);
            }

            OrganizationResponse response = CrmContext.OrganizationProxy.Execute(request);
        }
        public void FillSolutionImageComponent(ICollection <SolutionImageComponent> result, SolutionComponent solutionComponent)
        {
            RelationshipMetadataBase metaData = _source.GetRelationshipMetadata(solutionComponent.ObjectId.GetValueOrDefault());

            if (metaData != null)
            {
                result.Add(new SolutionImageComponent()
                {
                    ComponentType = (int)ComponentType.EntityRelationship,

                    SchemaName = metaData.SchemaName,

                    RootComponentBehavior = (int)solutionComponent.RootComponentBehaviorEnum.GetValueOrDefault(SolutionComponent.Schema.OptionSets.rootcomponentbehavior.Include_Subcomponents_0),

                    Description = GenerateDescriptionSingle(solutionComponent, true, false, false),
                });
            }
        }
 public EntityRelationship(RelationshipMetadataBase relation, string originatingEntity, string originatingParent = "")
 {
     Relationship = relation;
     if (relation is OneToManyRelationshipMetadata)
     {
         var om = (OneToManyRelationshipMetadata)relation;
         Name = FetchXmlBuilder.GetEntityDisplayName(om.ReferencingEntity) + "." + om.ReferencingAttribute + " -> " +
             FetchXmlBuilder.GetEntityDisplayName(om.ReferencedEntity) + "." + om.ReferencedAttribute;
     }
     else if (relation is ManyToManyRelationshipMetadata)
     {
         var mm = (ManyToManyRelationshipMetadata)relation;
         if (mm.Entity1LogicalName == originatingEntity)
         {
             Name = mm.IntersectEntityName + "." + mm.Entity1IntersectAttribute + " -> " + mm.Entity1IntersectAttribute;
         }
         else if (mm.Entity2LogicalName == originatingEntity)
         {
             Name = mm.IntersectEntityName + "." + mm.Entity2IntersectAttribute + " -> " + mm.Entity2IntersectAttribute;
         }
         else if (mm.IntersectEntityName == originatingEntity)
         {
             if (mm.Entity1LogicalName == originatingParent)
             {
                 Name = mm.Entity2IntersectAttribute + " -> " + mm.Entity2LogicalName + "." + mm.Entity2IntersectAttribute;
             }
             else if (mm.Entity2LogicalName == originatingParent)
             {
                 Name = mm.Entity1IntersectAttribute + " -> " + mm.Entity1LogicalName + "." + mm.Entity1IntersectAttribute;
             }
         }
         if (string.IsNullOrEmpty(Name))
         {
             Name = "? " + mm.IntersectEntityName + ": " + mm.Entity1LogicalName + "." + mm.Entity1IntersectAttribute + " -> " +
                 mm.Entity2LogicalName + "." + mm.Entity2IntersectAttribute;
         }
     }
     //Name = Name.Replace(FetchXmlBuilder.GetEntityDisplayName(originatingEntity) + ".", "");
 }
Пример #33
0
 bool ICodeWriterFilterService.GenerateRelationship(RelationshipMetadataBase relationshipMetadata, EntityMetadata otherEntityMetadata,
 IServiceProvider services)
 {
     return this.DefaultService.GenerateRelationship(relationshipMetadata, otherEntityMetadata, services);
 }
Пример #34
0
 public String GetNameForRelationship(
     EntityMetadata entityMetadata, RelationshipMetadataBase relationshipMetadata,
     EntityRole? reflexiveRole, IServiceProvider services)
 {
     return DefaultNamingService.GetNameForRelationship(
         entityMetadata, relationshipMetadata, reflexiveRole, services);
 }
 /// <summary>
 /// We don't want to generate any relationships.
 /// </summary>
 public bool GenerateRelationship(RelationshipMetadataBase relationshipMetadata, EntityMetadata otherEntityMetadata, IServiceProvider services)
 {
     return false;
 }
Пример #36
0
        /// <summary>
        /// Draw on a Visio page the entity relationships defined in the passed-in relationship collection.
        /// </summary>
        /// <param name="entity">Core entity</param>
        /// <param name="rect">Shape representing the core entity</param>
        /// <param name="relationshipCollection">Collection of entity relationships to draw</param>
        /// <param name="areReferencingRelationships">Whether or not the core entity is the referencing entity in the relationship</param>
        private void DrawRelationships(EntityMetadata entity, VisioApi.Shape rect, RelationshipMetadataBase[] relationshipCollection, bool areReferencingRelationships)
        {
            ManyToManyRelationshipMetadata currentManyToManyRelationship = null;
            OneToManyRelationshipMetadata currentOneToManyRelationship = null;
            EntityMetadata entity2 = null;
            AttributeMetadata attribute2 = null;
            AttributeMetadata attribute = null;
            Guid metadataID = Guid.NewGuid();
            bool isManyToMany = false;

            // Draw each relationship in the relationship collection.
            foreach (RelationshipMetadataBase entityRelationship in relationshipCollection)
            {
                entity2 = null;

                if (entityRelationship is ManyToManyRelationshipMetadata)
                {
                    isManyToMany = true;
                    currentManyToManyRelationship = entityRelationship as ManyToManyRelationshipMetadata;
                    // The entity passed in is not necessarily the originator of this relationship.
                    if (String.Compare(entity.LogicalName, currentManyToManyRelationship.Entity1LogicalName, true) != 0)
                    {
                        entity2 = GetEntityMetadata(currentManyToManyRelationship.Entity1LogicalName);
                    }
                    else
                    {
                        entity2 = GetEntityMetadata(currentManyToManyRelationship.Entity2LogicalName);
                    }
                    attribute2 = GetAttributeMetadata(entity2, entity2.PrimaryIdAttribute);
                    attribute = GetAttributeMetadata(entity, entity.PrimaryIdAttribute);
                    metadataID = currentManyToManyRelationship.MetadataId.Value;
                }
                else if (entityRelationship is OneToManyRelationshipMetadata)
                {
                    isManyToMany = false;
                    currentOneToManyRelationship = entityRelationship as OneToManyRelationshipMetadata;
                    entity2 = GetEntityMetadata(areReferencingRelationships ? currentOneToManyRelationship.ReferencingEntity : currentOneToManyRelationship.ReferencedEntity);
                    attribute2 = GetAttributeMetadata(entity2, areReferencingRelationships ? currentOneToManyRelationship.ReferencingAttribute : currentOneToManyRelationship.ReferencedAttribute);
                    attribute = GetAttributeMetadata(entity, areReferencingRelationships ? currentOneToManyRelationship.ReferencedAttribute : currentOneToManyRelationship.ReferencingAttribute);
                    metadataID = currentOneToManyRelationship.MetadataId.Value;
                }
                // Verify relationship is either ManyToManyMetadata or OneToManyMetadata
                if (entity2 != null)
                {
                    if (_processedRelationships.Contains(metadataID))
                    {
                        // Skip relationships we have already drawn
                        continue;
                    }
                    else
                    {
                        // Record we are drawing this relationship
                        _processedRelationships.Add(metadataID);

                        // Define convenience variables based upon the direction of referencing with respect to the core entity.
                        VisioApi.Shape rect2;


                        // Do not draw relationships involving the entity itself, SystemUser, BusinessUnit,
                        // or those that are intentionally excluded.
                        if (String.Compare(entity2.LogicalName, "systemuser", true) != 0 &&
                            String.Compare(entity2.LogicalName, "businessunit", true) != 0 &&
                            String.Compare(entity2.LogicalName, rect.Name, true) != 0 &&
                            String.Compare(entity.LogicalName, "systemuser", true) != 0 &&
                            String.Compare(entity.LogicalName, "businessunit", true) != 0 &&
                            !_excludedEntityTable.ContainsKey(entity2.LogicalName.GetHashCode()) &&
                       !_excludedRelationsTable.ContainsKey(attribute.LogicalName.GetHashCode()))
                        {
                            // Either find or create a shape that represents this secondary entity, and add the name of
                            // the involved attribute to the shape's text.
                            try
                            {
                                rect2 = rect.ContainingPage.Shapes.get_ItemU(entity2.SchemaName);

                                if (rect2.Text.IndexOf(attribute2.SchemaName) == -1)
                                {
                                    rect2.get_CellsSRC(VISIO_SECTION_OJBECT_INDEX, (short)VisioApi.VisRowIndices.visRowXFormOut, (short)VisioApi.VisCellIndices.visXFormHeight).ResultIU += 0.25;
                                    rect2.Text += "\n" + attribute2.SchemaName;

                                    // If the attribute is a primary key for the entity, append a [PK] label to the attribute name to indicate this.
                                    if (String.Compare(entity2.PrimaryIdAttribute, attribute2.LogicalName) == 0)
                                    {
                                        rect2.Text += "  [PK]";
                                    }
                                }
                            }
                            catch (System.Runtime.InteropServices.COMException)
                            {
                                rect2 = DrawEntityRectangle(rect.ContainingPage, entity2.SchemaName, entity2.OwnershipType.Value);
                                rect2.Text += "\n" + attribute2.SchemaName;

                                // If the attribute is a primary key for the entity, append a [PK] label to the attribute name to indicate so.
                                if (String.Compare(entity2.PrimaryIdAttribute, attribute2.LogicalName) == 0)
                                {
                                    rect2.Text += "  [PK]";
                                }
                            }

                            // Add the name of the involved attribute to the core entity's text, if not already present.
                            if (rect.Text.IndexOf(attribute.SchemaName) == -1)
                            {
                                rect.get_CellsSRC(VISIO_SECTION_OJBECT_INDEX, (short)VisioApi.VisRowIndices.visRowXFormOut, (short)VisioApi.VisCellIndices.visXFormHeight).ResultIU += HEIGHT;
                                rect.Text += "\n" + attribute.SchemaName;

                                // If the attribute is a primary key for the entity, append a [PK] label to the attribute name to indicate so.
                                if (String.Compare(entity.PrimaryIdAttribute, attribute.LogicalName) == 0)
                                {
                                    rect.Text += "  [PK]";
                                }
                            }

                            // Update the style of the entity name
                            VisioApi.Characters characters = rect.Characters;
                            VisioApi.Characters characters2 = rect2.Characters;
                           
                            //set the font family of the text to segoe for the visio 2013.
                            if (VersionName == "15.0")
                            {
                                characters.set_CharProps((short)VisioApi.VisCellIndices.visCharacterFont, (short)FONT_STYLE);
                                characters2.set_CharProps((short)VisioApi.VisCellIndices.visCharacterFont, (short)FONT_STYLE);
                            }
                            switch (entity2.OwnershipType)
                            {
                                case OwnershipTypes.BusinessOwned:
                                    // set the font color of the text
                                    characters.set_CharProps((short)VisioApi.VisCellIndices.visCharacterColor, (short)VisioApi.VisDefaultColors.visBlack);
                                    characters2.set_CharProps((short)VisioApi.VisCellIndices.visCharacterColor, (short)VisioApi.VisDefaultColors.visBlack);
                                    break;
                                case OwnershipTypes.OrganizationOwned:
                                    // set the font color of the text
                                    characters.set_CharProps((short)VisioApi.VisCellIndices.visCharacterColor, (short)VisioApi.VisDefaultColors.visBlack);
                                    characters2.set_CharProps((short)VisioApi.VisCellIndices.visCharacterColor, (short)VisioApi.VisDefaultColors.visBlack);
                                    break;
                                case OwnershipTypes.UserOwned:
                                    // set the font color of the text
                                    characters.set_CharProps((short)VisioApi.VisCellIndices.visCharacterColor, (short)VisioApi.VisDefaultColors.visWhite);
                                    characters2.set_CharProps((short)VisioApi.VisCellIndices.visCharacterColor, (short)VisioApi.VisDefaultColors.visWhite);
                                    break;
                                default:
                                    break;
                            }

                            // Draw the directional, dynamic connector between the two entity shapes.
                            if (areReferencingRelationships)
                            {
                                DrawDirectionalDynamicConnector(rect, rect2, isManyToMany);
                            }
                            else
                            {
                                DrawDirectionalDynamicConnector(rect2, rect, isManyToMany);
                            }
                        }
                        else
                        {
                            Debug.WriteLine(String.Format("<{0} - {1}> not drawn.", rect.Name, entity2.LogicalName), "Relationship");
                        }
                    }
                }
            }
        }
Пример #37
0
 CodeTypeReference ITypeMappingService.GetTypeForRelationship(RelationshipMetadataBase relationshipMetadata, EntityMetadata otherEntityMetadata, IServiceProvider services)
 {
     var nameForEntity = ((INamingService) services.GetService(typeof (INamingService))).GetNameForEntity(otherEntityMetadata, services);
     return TypeRef(nameForEntity);
 }
Пример #38
0
        /// <summary>
        /// Draw on a Visio page the entity relationships defined in the passed-in relationship collection.
        /// </summary>
        /// <param name="entity">Core entity</param>
        /// <param name="rect">Shape representing the core entity</param>
        /// <param name="relationshipCollection">Collection of entity relationships to draw</param>
        /// <param name="areReferencingRelationships">Whether or not the core entity is the referencing entity in the relationship</param>
        /// <param name="worker">The worker.</param>
        /// <param name="e">The <see cref="DoWorkEventArgs"/> instance containing the event data.</param>
        private void DrawRelationships(EntityMetadata entity, VisioApi.Shape rect, RelationshipMetadataBase[] relationshipCollection, bool areReferencingRelationships, BackgroundWorker worker, DoWorkEventArgs e)
        {
            ManyToManyRelationshipMetadata currentManyToManyRelationship = null;
            OneToManyRelationshipMetadata currentOneToManyRelationship = null;
            EntityMetadata entity2 = null;
            AttributeMetadata attribute2 = null;
            AttributeMetadata attribute = null;
            Guid metadataID = Guid.NewGuid();
            bool isManyToMany = false;

            // Draw each relationship in the relationship collection.
            foreach (RelationshipMetadataBase entityRelationship in relationshipCollection)
            {
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                entity2 = null;

                if (entityRelationship is ManyToManyRelationshipMetadata)
                {
                    isManyToMany = true;
                    currentManyToManyRelationship = entityRelationship as ManyToManyRelationshipMetadata;
                    // The entity passed in is not necessarily the originator of this relationship.
                    if (String.Compare(entity.LogicalName, currentManyToManyRelationship.Entity1LogicalName, true) != 0)
                    {
                        entity2 = GetEntityMetadata(currentManyToManyRelationship.Entity1LogicalName);
                    }
                    else
                    {
                        entity2 = GetEntityMetadata(currentManyToManyRelationship.Entity2LogicalName);
                    }
                    attribute2 = GetAttributeMetadata(entity2, entity2.PrimaryIdAttribute);
                    attribute = GetAttributeMetadata(entity, entity.PrimaryIdAttribute);
                    metadataID = currentManyToManyRelationship.MetadataId.Value;
                }
                else if (entityRelationship is OneToManyRelationshipMetadata)
                {
                    isManyToMany = false;
                    currentOneToManyRelationship = entityRelationship as OneToManyRelationshipMetadata;
                    entity2 = GetEntityMetadata(areReferencingRelationships ? currentOneToManyRelationship.ReferencingEntity : currentOneToManyRelationship.ReferencedEntity);
                    attribute2 = GetAttributeMetadata(entity2, areReferencingRelationships ? currentOneToManyRelationship.ReferencingAttribute : currentOneToManyRelationship.ReferencedAttribute);
                    attribute = GetAttributeMetadata(entity, areReferencingRelationships ? currentOneToManyRelationship.ReferencedAttribute : currentOneToManyRelationship.ReferencingAttribute);
                    metadataID = currentOneToManyRelationship.MetadataId.Value;
                }
                // Verify relationship is either ManyToManyMetadata or OneToManyMetadata
                if (entity2 != null)
                {
                    if (_processedRelationships.Contains(metadataID))
                    {
                        // Skip relationships we have already drawn
                        continue;
                    }
                    else
                    {
                        // Record we are drawing this relationship
                        _processedRelationships.Add(metadataID);

                        // Define convenience variables based upon the direction of referencing with respect to the core entity.
                        VisioApi.Shape rect2;

                        // Do not draw relationships involving the entity itself, SystemUser, BusinessUnit,
                        // or those that are intentionally excluded.
                        string selectedEntityFound = selectedEntitiesNames.Find(en => en == entity2.LogicalName);
                        if (String.Compare(entity2.LogicalName, "systemuser", true) != 0 &&
                            String.Compare(entity2.LogicalName, "businessunit", true) != 0 &&
                            String.Compare(entity2.LogicalName, rect.Name, true) != 0 &&
                            (selectedEntityFound != null) &&
                            String.Compare(entity.LogicalName, "systemuser", true) != 0 &&
                            String.Compare(entity.LogicalName, "businessunit", true) != 0)
                        {
                            // Either find or create a shape that represents this secondary entity, and add the name of
                            // the involved attribute to the shape's text.
                            try
                            {
                                rect2 = rect.ContainingPage.Shapes.get_ItemU(entity2.LogicalName);

                                if (rect2.Text.IndexOf(attribute2.LogicalName) == -1)
                                {
                                    rect2.get_CellsSRC(VISIO_SECTION_OJBECT_INDEX, (short)VisioApi.VisRowIndices.visRowXFormOut, (short)VisioApi.VisCellIndices.visXFormHeight).ResultIU += 0.25;
                                    rect2.Text += "\n" + attribute2.LogicalName;

                                    // If the attribute is a primary key for the entity, append a [PK] label to the attribute name to indicate this.
                                    if (String.Compare(entity2.PrimaryIdAttribute, attribute2.LogicalName) == 0)
                                    {
                                        rect2.Text += "  [PK]";
                                    }
                                }
                            }
                            catch (System.Runtime.InteropServices.COMException)
                            {
                                rect2 = DrawEntityRectangle(rect.ContainingPage, entity2.LogicalName, entity2.OwnershipType.Value);
                                rect2.Text += "\n" + attribute2.LogicalName;

                                // If the attribute is a primary key for the entity, append a [PK] label to the attribute name to indicate so.
                                if (String.Compare(entity2.PrimaryIdAttribute, attribute2.LogicalName) == 0)
                                {
                                    rect2.Text += "  [PK]";
                                }
                            }

                            // Add the name of the involved attribute to the core entity's text, if not already present.
                            if (rect.Text.IndexOf(attribute.LogicalName) == -1)
                            {
                                rect.get_CellsSRC(VISIO_SECTION_OJBECT_INDEX, (short)VisioApi.VisRowIndices.visRowXFormOut, (short)VisioApi.VisCellIndices.visXFormHeight).ResultIU += HEIGHT;
                                rect.Text += "\n" + attribute.LogicalName;

                                // If the attribute is a primary key for the entity, append a [PK] label to the attribute name to indicate so.
                                if (String.Compare(entity.PrimaryIdAttribute, attribute.LogicalName) == 0)
                                {
                                    rect.Text += "  [PK]";
                                }
                            }

                            // Draw the directional, dynamic connector between the two entity shapes.
                            if (areReferencingRelationships)
                            {
                                DrawDirectionalDynamicConnector(rect, rect2, isManyToMany);
                            }
                            else
                            {
                                DrawDirectionalDynamicConnector(rect2, rect, isManyToMany);
                            }
                        }
                    }
                }
            }
        }
Пример #39
0
 static CodeStatementCollection BuildRelationshipSet(string methodName, RelationshipMetadataBase relationship, CodeTypeReference targetType, EntityRole? entityRole)
 {
     var statements = new CodeStatementCollection();
     var expression = entityRole.HasValue ? (FieldRef(typeof (EntityRole), entityRole.ToString())) : ((CodeExpression) Null());
     statements.Add(ThisMethodInvoke(methodName, targetType, new[] {StringLiteral(relationship.SchemaName), expression, VarRef("value")}));
     return statements;
 }
Пример #40
0
 static CodeStatement BuildRelationshipGet(string methodName, RelationshipMetadataBase relationship, CodeTypeReference targetType, EntityRole? entityRole)
 {
     var expression = entityRole.HasValue ? (FieldRef(typeof (EntityRole), entityRole.ToString())) : ((CodeExpression) Null());
     return Return(ThisMethodInvoke(methodName, targetType, new[] {StringLiteral(relationship.SchemaName), expression}));
 }
 internal override void StoreResult(HttpResponseMessage httpResponse)
 {
     XDocument xdoc = XDocument.Parse(httpResponse.Content.ReadAsStringAsync().Result, LoadOptions.None);
     foreach (var result in xdoc.Descendants(Util.ns.a + "Results").Elements(Util.ns.a + "KeyValuePairOfstringanyType"))
     {
         if (result.Element(Util.ns.b + "key").Value == "RelationshipMetadata")
             this.RelationshipMetadata = RelationshipMetadataBase.LoadFromXml(result.Element(Util.ns.b + "value"));
     }
 }
Пример #42
0
 bool ICodeWriterFilterService.GenerateRelationship(RelationshipMetadataBase relationshipMetadata, EntityMetadata otherEntityMetadata, IServiceProvider services)
 {
     var service = (ICodeWriterFilterService) services.GetService(typeof (ICodeWriterFilterService));
     if (otherEntityMetadata == null)
     {
         return false;
     }
     if (string.Equals(otherEntityMetadata.LogicalName, "calendarrule", StringComparison.Ordinal))
     {
         return false;
     }
     if (string.Equals(relationshipMetadata.SchemaName, "team_PostFollows", StringComparison.Ordinal))
     {
         return false;
     }
     return service.GenerateEntity(otherEntityMetadata, services);
 }
Пример #43
0
 string INamingService.GetNameForRelationship(EntityMetadata entityMetadata, RelationshipMetadataBase relationshipMetadata, EntityRole? reflexiveRole, IServiceProvider services)
 {
     var str = reflexiveRole.HasValue ? reflexiveRole.Value.ToString() : string.Empty;
     if (_knowNames.ContainsKey(entityMetadata.MetadataId.Value.ToString() + relationshipMetadata.MetadataId.Value + str))
     {
         return _knowNames[entityMetadata.MetadataId.Value.ToString() + relationshipMetadata.MetadataId.Value + str];
     }
     var name = !reflexiveRole.HasValue ? relationshipMetadata.SchemaName : (((reflexiveRole.Value) == EntityRole.Referenced) ? ("Referenced" + relationshipMetadata.SchemaName) : ("Referencing" + relationshipMetadata.SchemaName));
     name = CreateValidName(name);
     var service = (INamingService) services.GetService(typeof (INamingService));
     if (_reservedAttributeNames.Contains(name) || (name == service.GetNameForEntity(entityMetadata, services)))
     {
         name = name + "1";
     }
     _knowNames.Add(entityMetadata.MetadataId.Value.ToString() + relationshipMetadata.MetadataId.Value + str, name);
     return name;
 }