private static void FillDescriptionAttribute(List <string> lines, AttributeIntellisenseData attribute)
        {
            if (attribute.IsPrimaryIdAttribute.GetValueOrDefault())
            {
                lines.Add("PrimaryId");
            }

            if (attribute.IsPrimaryNameAttribute.GetValueOrDefault())
            {
                lines.Add("PrimaryName");
            }

            if (attribute.Targets != null && attribute.Targets.Count > 0)
            {
                if (attribute.Targets.Count <= 6)
                {
                    string targets = string.Join(",", attribute.Targets.OrderBy(s => s));

                    lines.Add(string.Format("Targets:\t{0}", targets));
                }
                else
                {
                    lines.Add(string.Format("Targets Count:\t{0}", attribute.Targets.Count));
                }
            }

            CreateFileHandler.FillLabelDisplayNameAndDescription(lines, true, attribute.DisplayName, attribute.Description);
        }
        public static void FillCompareValuesForAttribute(List <string> result, AttributeIntellisenseData attribute)
        {
            result.AddRange(GetCompareValues(attribute.DisplayName));

            result.Add(attribute.LogicalName);

            if (attribute.AttributeType.HasValue)
            {
                result.Add(attribute.AttributeType.ToString());
            }

            if (attribute.IsPrimaryIdAttribute.GetValueOrDefault())
            {
                result.Add("PrimaryId");
            }

            if (attribute.IsPrimaryNameAttribute.GetValueOrDefault())
            {
                result.Add("PrimaryName");
            }

            if (attribute.Targets != null && attribute.Targets.Count > 0)
            {
                result.AddRange(attribute.Targets);
            }
        }
        public static string GetDisplayTextAttribute(string entityName, AttributeIntellisenseData attribute)
        {
            StringBuilder result = new StringBuilder();

            result.AppendFormat("{0}.{1}", entityName, attribute.LogicalName);

            string temp = CreateFileHandler.GetLocalizedLabel(attribute.DisplayName);

            if (!string.IsNullOrEmpty(temp))
            {
                result.AppendFormat(" - {0}", temp);
            }

            if (attribute.IsPrimaryIdAttribute.GetValueOrDefault())
            {
                result.Append(" - PrimaryId");
            }

            if (attribute.IsPrimaryNameAttribute.GetValueOrDefault())
            {
                result.Append(" - PrimaryName");
            }

            if (attribute.AttributeType.HasValue)
            {
                result.AppendFormat(" - {0}", attribute.AttributeType.ToString());
            }

            return(result.ToString());
        }
        public static List <string> GetCompareValuesForAttribute(AttributeIntellisenseData attribute)
        {
            List <string> result = new List <string>();

            FillCompareValuesForAttribute(result, attribute);

            return(result);
        }
        public static string CreateAttributeDescription(string entityDescription, AttributeIntellisenseData attribute)
        {
            List <string> lines = new List <string>();

            if (!string.IsNullOrEmpty(entityDescription))
            {
                lines.Add(string.Format("Entity:\t{0}", entityDescription));
            }

            FillDescriptionAttribute(lines, attribute);

            return(string.Join(System.Environment.NewLine, lines));
        }
        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>()));
        }
        public static string CreateEntityAndAttributeDescription(EntityIntellisenseData entity, AttributeIntellisenseData attribute)
        {
            List <string> lines = new List <string>();

            if (entity.IsIntersectEntity)
            {
                lines.Add("IntersectEntity");

                if (entity.ManyToManyRelationships != null)
                {
                    var relations = entity.ManyToManyRelationships.Values.Where(r => string.Equals(r.IntersectEntityName, entity.EntityLogicalName, StringComparison.InvariantCultureIgnoreCase));

                    foreach (var rel in relations.OrderBy(r => r.Entity1Name).ThenBy(r => r.Entity2Name).ThenBy(r => r.Entity1IntersectAttributeName).ThenBy(r => r.Entity2IntersectAttributeName))
                    {
                        lines.Add(string.Format("{0} - {1}", rel.Entity1Name, rel.Entity2Name));
                    }
                }
            }

            CreateFileHandler.FillLabelEntity(lines, true, entity.DisplayName, entity.DisplayCollectionName, entity.Description);

            lines.Add(string.Empty);

            lines.Add(string.Format("Attribute:\t{0}", GetDisplayTextAttribute(entity.EntityLogicalName, attribute)));

            FillDescriptionAttribute(lines, attribute);

            return(string.Join(System.Environment.NewLine, lines));
        }