예제 #1
0
        private void FillEntityIntellisenseDataAttributes(IList <CompletionSet> completionSets, ITrackingSpan applicableTo, EntityIntellisenseData entityData)
        {
            if (entityData == null ||
                entityData.Attributes == null
                )
            {
                return;
            }

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

            string entityDescription = CrmIntellisenseCommon.GetDisplayTextEntity(entityData);

            foreach (var attribute in entityData.AttributesOrdered())
            {
                string attributeDescription = CrmIntellisenseCommon.GetDisplayTextAttribute(entityData.EntityLogicalName, attribute);

                List <string> compareValues = CrmIntellisenseCommon.GetCompareValuesForAttribute(attribute);

                list.Add(CreateCompletion(attributeDescription, attribute.LogicalName, CrmIntellisenseCommon.CreateAttributeDescription(entityDescription, attribute), _defaultGlyph, compareValues));
            }

            if (list.Count > 0)
            {
                completionSets.Add(new CrmCompletionSet(SourceNameMoniker, string.Format("{0} Attributes", entityData.EntityLogicalName), applicableTo, list, Enumerable.Empty <CrmCompletion>()));
            }
        }
예제 #2
0
        private void FillEntityNamesInList(IList <CompletionSet> completionSets, ITrackingSpan applicableTo, ConnectionIntellisenseData intellisenseData, bool isObjectTypeCode)
        {
            List <CrmCompletion> list = new List <CrmCompletion>();

            var entityList = intellisenseData.Entities.Values.OrderBy(e => e.IsIntersectEntity).ThenBy(e => e.EntityLogicalName).ToList();

            foreach (var entityData in entityList)
            {
                string entityDescription = CrmIntellisenseCommon.GetDisplayTextEntity(entityData);

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

                var insertionText = entityData.EntityLogicalName;

                if (isObjectTypeCode)
                {
                    insertionText = entityData.ObjectTypeCode.ToString();
                }

                list.Add(CreateCompletion(entityDescription, insertionText, CrmIntellisenseCommon.CreateEntityDescription(entityData), _defaultGlyph, compareValues));
            }

            if (list.Count > 0)
            {
                completionSets.Add(new CrmCompletionSet(SourceNameMoniker, "All Entities", applicableTo, list, Enumerable.Empty <CrmCompletion>()));
            }
        }
예제 #3
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>()));
            }
        }
예제 #4
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>()));
            }
        }
        private void FillLinkedEntityNames(IList <CompletionSet> completionSets, ITrackingSpan applicableTo, ConnectionIntellisenseDataRepository repository, XElement currentXmlNode)
        {
            var entityName = GetParentEntityName(currentXmlNode);

            if (string.IsNullOrEmpty(entityName))
            {
                return;
            }

            var connectionIntellisense = repository.GetEntitiesIntellisenseData();

            if (connectionIntellisense == null || connectionIntellisense.Entities == null)
            {
                return;
            }

            var entityData = repository.GetEntityAttributeIntellisense(entityName);

            if (entityData == null)
            {
                return;
            }

            HashSet <string> linkedEntities = entityData.GetLinkedEntities(connectionIntellisense);

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

            foreach (var linkedEntityName in linkedEntities.OrderBy(s => s))
            {
                if (connectionIntellisense.Entities.ContainsKey(linkedEntityName))
                {
                    var linkedEntityData = connectionIntellisense.Entities[linkedEntityName];

                    string entityDescription = CrmIntellisenseCommon.GetDisplayTextEntity(linkedEntityData);

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

                    list.Add(CreateCompletion(entityDescription, linkedEntityData.EntityLogicalName, CrmIntellisenseCommon.CreateEntityDescription(linkedEntityData), _defaultGlyph, compareValues));
                }
            }

            if (list.Count > 0)
            {
                completionSets.Add(new CrmCompletionSet(SourceNameMonikerLinkedEntites, "Linked Entities", applicableTo, list, Enumerable.Empty <CrmCompletion>()));
            }
        }
        private void FillEntityNamesInList(IList <CompletionSet> completionSets, ITrackingSpan applicableTo, ConnectionIntellisenseDataRepository repository, bool isObjectTypeCode, bool withNone = false)
        {
            var connectionIntellisense = repository.GetEntitiesIntellisenseData();

            if (connectionIntellisense == null || connectionIntellisense.Entities == null)
            {
                return;
            }

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

            if (withNone)
            {
                list.Add(CreateCompletion("none - 0", "0", "none", _defaultGlyph, new[] { "none", "0" }));
            }

            var keys = connectionIntellisense.Entities.Keys.ToList();

            foreach (var entityName in keys.OrderBy(s => s))
            {
                var entityData = connectionIntellisense.Entities[entityName];

                string entityDescription = CrmIntellisenseCommon.GetDisplayTextEntity(entityData);

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

                var insertionText = entityData.EntityLogicalName;

                if (isObjectTypeCode)
                {
                    insertionText = entityData.ObjectTypeCode.ToString();
                }

                list.Add(CreateCompletion(entityDescription, insertionText, CrmIntellisenseCommon.CreateEntityDescription(entityData), _defaultGlyph, compareValues));
            }

            if (list.Count > 0)
            {
                completionSets.Add(new CrmCompletionSet(SourceNameMonikerAllEntites, "All Entities", applicableTo, list, Enumerable.Empty <CrmCompletion>()));
            }
        }
예제 #7
0
        private void FillEntityAttributeIdInWebResourceDependencyXml(IList <CompletionSet> completionSets, ITrackingSpan applicableTo, ConnectionIntellisenseDataRepository repositoryEntities, XElement currentXmlNode)
        {
            var entityName    = GetAttributeValue(currentXmlNode, "entityName");
            var attributeName = GetAttributeValue(currentXmlNode, "attributeName");

            if (string.IsNullOrEmpty(entityName))
            {
                return;
            }

            var entityData = repositoryEntities.GetEntityAttributeIntellisense(entityName);

            if (entityData == null || entityData.Attributes == null || !entityData.Attributes.ContainsKey(attributeName))
            {
                return;
            }

            var attributeData = entityData.Attributes[attributeName];

            if (attributeData.MetadataId.HasValue)
            {
                List <CrmCompletion> list = new List <CrmCompletion>();

                string entityDescription    = CrmIntellisenseCommon.GetDisplayTextEntity(entityData);
                string attributeDescription = CrmIntellisenseCommon.GetDisplayTextAttribute(entityData.EntityLogicalName, attributeData);

                var attributeIdString = attributeData.MetadataId.Value.ToString("B");

                List <string> compareValues = CrmIntellisenseCommon.GetCompareValuesForAttribute(attributeData);
                compareValues.Add(attributeIdString);

                list.Add(CreateCompletion(attributeDescription, attributeIdString, CrmIntellisenseCommon.CreateAttributeDescription(entityDescription, attributeData), _defaultGlyph, compareValues));

                completionSets.Add(new CrmCompletionSet(SourceNameMonikerAllAttributes, string.Format("{0}.{1}", entityName, attributeName), applicableTo, list, Enumerable.Empty <CrmCompletion>()));
            }
        }
        private void FillEntityAttributeValues(IList <CompletionSet> completionSets, ITrackingSpan applicableTo, ConnectionIntellisenseDataRepository repository, string entityName, string attributeName)
        {
            if (string.IsNullOrEmpty(entityName) || string.IsNullOrEmpty(attributeName))
            {
                return;
            }

            var entityData = repository.GetEntityAttributeIntellisense(entityName);

            if (entityData == null || entityData.Attributes == null)
            {
                return;
            }

            if (!entityData.Attributes.ContainsKey(attributeName))
            {
                return;
            }

            var attributeData = entityData.Attributes[attributeName];

            if (attributeData.OptionSet != null && attributeData.OptionSet.IsBoolean)
            {
                List <CrmCompletion> list = new List <CrmCompletion>
                {
                    CreateCompletion("0", "0", null, _defaultGlyph, Enumerable.Empty <string>()),
                    CreateCompletion("1", "1", null, _defaultGlyph, Enumerable.Empty <string>()),
                    CreateCompletion("false", "false", null, _defaultGlyph, Enumerable.Empty <string>()),
                    CreateCompletion("true", "true", null, _defaultGlyph, Enumerable.Empty <string>())
                };

                if (attributeData.OptionSet != null && attributeData.OptionSet.OptionSetMetadata is BooleanOptionSetMetadata boolOptionSet)
                {
                    string entityDescription    = CrmIntellisenseCommon.GetDisplayTextEntity(entityData);
                    string attributeDescription = CrmIntellisenseCommon.GetDisplayTextAttribute(entityName, attributeData);

                    if (boolOptionSet.FalseOption != null)
                    {
                        string displayText = CrmIntellisenseCommon.GetDisplayTextOptionSetValue(entityData.EntityLogicalName, attributeData.LogicalName, boolOptionSet.FalseOption);

                        List <string> compareValues = CrmIntellisenseCommon.GetCompareValues(boolOptionSet.FalseOption.Label);

                        list.Add(CreateCompletion(displayText, boolOptionSet.FalseOption.Value.ToString(), CrmIntellisenseCommon.CreateOptionValueDescription(entityDescription, attributeDescription, boolOptionSet.FalseOption), _defaultGlyph, compareValues));
                    }

                    if (boolOptionSet.TrueOption != null)
                    {
                        string displayText = CrmIntellisenseCommon.GetDisplayTextOptionSetValue(entityData.EntityLogicalName, attributeData.LogicalName, boolOptionSet.TrueOption);

                        List <string> compareValues = CrmIntellisenseCommon.GetCompareValues(boolOptionSet.TrueOption.Label);

                        list.Add(CreateCompletion(displayText, boolOptionSet.TrueOption.Value.ToString(), CrmIntellisenseCommon.CreateOptionValueDescription(entityDescription, attributeDescription, boolOptionSet.TrueOption), _defaultGlyph, compareValues));
                    }
                }

                completionSets.Add(new CrmCompletionSet(SourceNameMonikerDefaultSingle, string.Format("{0}.{1} Values", entityName, attributeName), applicableTo, list, Enumerable.Empty <CrmCompletion>()));
            }
            else if (attributeData.IsEntityNameAttribute)
            {
                FillEntityNamesInList(completionSets, applicableTo, repository, true, true);
            }
            else if (attributeData.OptionSet != null)
            {
                if (attributeData.OptionSet != null && attributeData.OptionSet.OptionSetMetadata is OptionSetMetadata optionSet)
                {
                    List <CrmCompletion> list = new List <CrmCompletion>();

                    string entityDescription    = CrmIntellisenseCommon.GetDisplayTextEntity(entityData);
                    string attributeDescription = CrmIntellisenseCommon.GetDisplayTextAttribute(entityName, attributeData);

                    foreach (var item in optionSet.Options.OrderBy(e => e.Value))
                    {
                        string displayText = CrmIntellisenseCommon.GetDisplayTextOptionSetValue(entityData.EntityLogicalName, attributeData.LogicalName, item);

                        List <string> compareValues = CrmIntellisenseCommon.GetCompareValues(item.Label);

                        list.Add(CreateCompletion(displayText, item.Value.ToString(), CrmIntellisenseCommon.CreateOptionValueDescription(entityDescription, attributeDescription, item), _defaultGlyph, compareValues));
                    }

                    if (list.Count > 0)
                    {
                        completionSets.Add(new CrmCompletionSet(SourceNameMonikerDefaultSingle, string.Format("{0}.{1} Values", entityName, attributeName), applicableTo, list, Enumerable.Empty <CrmCompletion>()));
                    }
                }
            }
        }
        private void FillEntityPrimaryAttributeForGrid(IList <CompletionSet> completionSets, ITrackingSpan applicableTo, ConnectionIntellisenseDataRepository repository, XElement currentXmlNode, bool isNameAttribute)
        {
            int?entityTypeCode = GetParentEntityObjectTypeCode(currentXmlNode);

            if (!entityTypeCode.HasValue)
            {
                return;
            }

            var entityData = repository.GetEntityAttributeIntellisense(entityTypeCode.Value);

            if (entityData == null ||
                entityData.Attributes == null
                )
            {
                return;
            }

            if (isNameAttribute && string.IsNullOrEmpty(entityData.EntityPrimaryNameAttribute))
            {
                return;
            }

            AttributeIntellisenseData attribute = null;

            if (isNameAttribute)
            {
                if (entityData.Attributes.ContainsKey(entityData.EntityPrimaryNameAttribute))
                {
                    attribute = entityData.Attributes[entityData.EntityPrimaryNameAttribute];
                }
            }
            else
            {
                if (entityData.Attributes.ContainsKey(entityData.EntityPrimaryIdAttribute))
                {
                    attribute = entityData.Attributes[entityData.EntityPrimaryIdAttribute];
                }
            }

            if (attribute == null)
            {
                return;
            }

            string entityDescription = CrmIntellisenseCommon.GetDisplayTextEntity(entityData);

            string attributeDescription = CrmIntellisenseCommon.GetDisplayTextAttribute(entityData.EntityLogicalName, attribute);

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

            List <string> compareValues = CrmIntellisenseCommon.GetCompareValuesForAttribute(attribute);

            list.Add(CreateCompletion(attributeDescription, attribute.LogicalName, CrmIntellisenseCommon.CreateAttributeDescription(entityDescription, attribute), _defaultGlyph, compareValues));

            var displayName = string.Format("{0} PrimaryIdAttribute", entityData.EntityLogicalName);

            if (isNameAttribute)
            {
                displayName = string.Format("{0} PrimaryNameAttribute", entityData.EntityLogicalName);
            }

            completionSets.Add(new CrmCompletionSet(SourceNameMonikerPrimaryAttributes, displayName, applicableTo, list, Enumerable.Empty <CrmCompletion>()));
        }
        private void FillPrimaryEntityAttributes(IList <CompletionSet> completionSets, ITrackingSpan applicableTo, ConnectionIntellisenseDataRepository repository, string primaryEntityName, string secondaryName)
        {
            if (string.IsNullOrEmpty(primaryEntityName))
            {
                return;
            }

            var primaryEntityData = repository.GetEntityAttributeIntellisense(primaryEntityName);

            if (primaryEntityData == null || primaryEntityData.Attributes == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(secondaryName))
            {
                var secondaryEntityData = repository.GetEntityAttributeIntellisense(secondaryName);

                if (secondaryEntityData != null)
                {
                    var secondaryReferenceEntities = GetReferencedEntities(secondaryEntityData);

                    var primaryReferenceEntities = GetReferencedEntities(primaryEntityData);

                    var commonEntities = new HashSet <string>(secondaryReferenceEntities.Intersect(primaryReferenceEntities), StringComparer.InvariantCultureIgnoreCase);

                    if (commonEntities.Any())
                    {
                        var attributes = GetRefererenceAttributes(primaryEntityData, commonEntities);

                        if (attributes.Any())
                        {
                            List <CrmCompletion> list = new List <CrmCompletion>();

                            string entityDescription = CrmIntellisenseCommon.GetDisplayTextEntity(primaryEntityData);

                            foreach (var attribute in primaryEntityData.AttributesOrdered())
                            {
                                if (attributes.Contains(attribute.LogicalName))
                                {
                                    string attributeDescription = CrmIntellisenseCommon.GetDisplayTextAttribute(primaryEntityData.EntityLogicalName, attribute);

                                    List <string> compareValues = CrmIntellisenseCommon.GetCompareValuesForAttribute(attribute);

                                    list.Add(CreateCompletion(attributeDescription.ToString(), attribute.LogicalName, CrmIntellisenseCommon.CreateAttributeDescription(entityDescription, attribute), _defaultGlyph, compareValues));
                                }
                            }

                            if (list.Count > 0)
                            {
                                completionSets.Add(new CrmCompletionSet(SourceNameMonikerDefaultSingle, string.Format("{0} Calculated", primaryEntityData.EntityLogicalName), applicableTo, list, Enumerable.Empty <CrmCompletion>()));
                            }
                        }
                    }
                }
            }

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

                string entityDescription = CrmIntellisenseCommon.GetDisplayTextEntity(primaryEntityData);

                foreach (var attribute in primaryEntityData.AttributesOrdered())
                {
                    if (attribute.AttributeType == AttributeTypeCode.Uniqueidentifier ||
                        attribute.AttributeType == AttributeTypeCode.Customer ||
                        attribute.AttributeType == AttributeTypeCode.Lookup ||
                        attribute.AttributeType == AttributeTypeCode.Owner
                        )
                    {
                        string attributeDescription = CrmIntellisenseCommon.GetDisplayTextAttribute(primaryEntityData.EntityLogicalName, attribute);

                        List <string> compareValues = CrmIntellisenseCommon.GetCompareValuesForAttribute(attribute);

                        list.Add(CreateCompletion(attributeDescription.ToString(), attribute.LogicalName, CrmIntellisenseCommon.CreateAttributeDescription(entityDescription, attribute), _defaultGlyph, compareValues));
                    }
                }

                if (list.Count > 0)
                {
                    completionSets.Add(new CrmCompletionSet(SourceNameMonikerReferenceAttributes, string.Format("{0} References", primaryEntityData.EntityLogicalName), applicableTo, list, Enumerable.Empty <CrmCompletion>()));
                }
            }

            FillEntityIntellisenseDataAttributes(completionSets, applicableTo, primaryEntityData);
        }