示例#1
0
        private void FillMultiLinkForEntity(IList <CompletionSet> completionSets, ITrackingSpan applicableTo, ConnectionIntellisenseData intellisenseData, EntityIntellisenseData entityData)
        {
            TupleList <string, string> childEntities = new TupleList <string, string>();

            if (entityData.OneToManyRelationships != null)
            {
                foreach (var item in entityData.OneToManyRelationships.Values)
                {
                    childEntities.Add(item.ChildEntityName, item.ChildEntityAttributeName);
                }
            }

            if (!entityData.IsIntersectEntity.GetValueOrDefault() && entityData.ManyToManyRelationships != null)
            {
                foreach (var item in entityData.ManyToManyRelationships.Values)
                {
                    if (string.Equals(entityData.EntityLogicalName, item.Entity1Name, StringComparison.InvariantCultureIgnoreCase))
                    {
                        childEntities.Add(item.IntersectEntityName, item.Entity1IntersectAttributeName);
                    }
                    else if (string.Equals(entityData.EntityLogicalName, item.Entity2Name, StringComparison.InvariantCultureIgnoreCase))
                    {
                        childEntities.Add(item.IntersectEntityName, item.Entity2IntersectAttributeName);
                    }
                }
            }

            List <CrmCompletion> list = new List <CrmCompletion>();

            foreach (var relation in childEntities.OrderBy(e => e.Item1).ThenBy(e => e.Item2))
            {
                if (intellisenseData.Entities.ContainsKey(relation.Item1))
                {
                    var childEntityData = intellisenseData.Entities[relation.Item1];

                    if (childEntityData.Attributes != null && childEntityData.Attributes.ContainsKey(relation.Item2))
                    {
                        var childAttribute = childEntityData.Attributes[relation.Item2];

                        List <string> compareValues = CrmIntellisenseCommon.GetCompareValuesForEntity(childEntityData);

                        compareValues.Add(relation.Item2);

                        var insertText = string.Format("multi {0} {1}", relation.Item2, relation.Item1);

                        list.Add(CreateCompletion(CrmIntellisenseCommon.GetDisplayTextEntityAndAttribute(childEntityData, childAttribute), insertText, CrmIntellisenseCommon.CreateEntityAndAttributeDescription(childEntityData, childAttribute), _defaultGlyph, compareValues));
                    }
                }
            }

            if (list.Count > 0)
            {
                completionSets.Add(new CrmCompletionSet(SourceNameMoniker, "Child Entities", applicableTo, list, Enumerable.Empty <CrmCompletion>()));
            }
        }
示例#2
0
        private void FillAttributeReferencedEntities(IList <CompletionSet> completionSets, ITrackingSpan applicableTo, IEnumerable <EntityIntellisenseData> entities)
        {
            List <CrmCompletion> list = new List <CrmCompletion>();

            foreach (var entityData in entities)
            {
                if (entityData.Attributes != null)
                {
                    string entityDescription = CrmIntellisenseCommon.GetDisplayTextEntity(entityData);

                    if (!string.IsNullOrEmpty(entityData.EntityPrimaryIdAttribute) &&
                        entityData.Attributes != null &&
                        entityData.Attributes.ContainsKey(entityData.EntityPrimaryIdAttribute) &&
                        entityData.Attributes[entityData.EntityPrimaryIdAttribute].AttributeType == AttributeTypeCode.Uniqueidentifier
                        )
                    {
                        List <string> compareValues = CrmIntellisenseCommon.GetCompareValuesForEntity(entityData);
                        compareValues.Add(entityData.EntityPrimaryIdAttribute);

                        var insertText = string.Format("multi {0} {1}", entityData.EntityPrimaryIdAttribute, entityData.EntityLogicalName);

                        list.Add(CreateCompletion(CrmIntellisenseCommon.GetDisplayTextEntity(entityData), insertText, CrmIntellisenseCommon.CreateEntityDescription(entityData), _defaultGlyph, compareValues));
                    }

                    foreach (var attribute in entityData.Attributes
                             .Values
                             .Where(e => !string.Equals(e.LogicalName, entityData.EntityPrimaryIdAttribute, StringComparison.InvariantCultureIgnoreCase) && e.AttributeType == AttributeTypeCode.Uniqueidentifier)
                             .OrderBy(e => e.LogicalName)
                             )
                    {
                        List <string> compareValues = CrmIntellisenseCommon.GetCompareValuesForEntity(entityData);

                        CrmIntellisenseCommon.FillCompareValuesForAttribute(compareValues, attribute);

                        var insertText = string.Format("multi {0} {1}", entityData.EntityPrimaryIdAttribute, entityData.EntityLogicalName);

                        list.Add(CreateCompletion(CrmIntellisenseCommon.GetDisplayTextEntityAndAttribute(entityData, attribute), insertText, CrmIntellisenseCommon.CreateEntityAndAttributeDescription(entityData, attribute), _defaultGlyph, compareValues));
                    }
                }
            }

            if (list.Count > 0)
            {
                completionSets.Add(new CrmCompletionSet(SourceNameMoniker, "Entities", applicableTo, list, Enumerable.Empty <CrmCompletion>()));
            }
        }