Exemple #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>()));
            }
        }
Exemple #2
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 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 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 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);
        }