private void FillSessionsXmlNodeText(IList <CompletionSet> completionSets, ITrackingSpan applicableTo, ConnectionData connectionData, XElement doc, XElement currentXmlNode)
        {
            if (string.Equals(doc.Name.ToString(), Commands.AbstractDynamicCommandXsdSchemas.FetchRoot, StringComparison.InvariantCultureIgnoreCase) ||
                string.Equals(doc.Name.ToString(), Commands.AbstractDynamicCommandXsdSchemas.SavedQueryRoot, StringComparison.InvariantCultureIgnoreCase)
                )
            {
                var repository = ConnectionIntellisenseDataRepository.GetRepository(connectionData);

                HashSet <string> usedEntities = GetUsedEntities(doc);

                if (usedEntities.Any())
                {
                    repository.GetEntityDataForNamesAsync(usedEntities);
                }

                if (string.Equals(currentXmlNode.Name.LocalName, "value", StringComparison.InvariantCultureIgnoreCase))
                {
                    var nodeCondition = currentXmlNode.Parent;

                    if (nodeCondition != null && string.Equals(nodeCondition.Name.LocalName, "condition", StringComparison.InvariantCultureIgnoreCase))
                    {
                        Dictionary <string, string> aliases = GetEntityAliases(doc);

                        FillEntityAttributeValuesInList(completionSets, applicableTo, repository, nodeCondition, aliases);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 private void FillSessionForWebResourceDependencyXmlCompletionSet(
     IList <CompletionSet> completionSets
     , XElement doc
     , ConnectionData connectionData
     , ConnectionIntellisenseDataRepository repositoryEntities
     , WebResourceIntellisenseDataRepository repositoryWebResource
     , XElement currentXmlNode
     , string currentNodeName
     , string currentAttributeName
     , ITrackingSpan applicableTo
     )
 {
     try
     {
         if (string.Equals(currentNodeName, "Attribute", StringComparison.InvariantCultureIgnoreCase))
         {
             if (string.Equals(currentAttributeName, "entityName", StringComparison.InvariantCultureIgnoreCase))
             {
                 FillEntityNamesInList(completionSets, applicableTo, repositoryEntities, false);
             }
             else if (string.Equals(currentAttributeName, "attributeName", StringComparison.InvariantCultureIgnoreCase))
             {
                 FillEntityAttributesInWebResourceDependencyXml(completionSets, applicableTo, repositoryEntities, currentXmlNode);
             }
             else if (string.Equals(currentAttributeName, "attributeId", StringComparison.InvariantCultureIgnoreCase))
             {
                 FillEntityAttributeIdInWebResourceDependencyXml(completionSets, applicableTo, repositoryEntities, currentXmlNode);
             }
         }
         else if (string.Equals(currentNodeName, "Library", StringComparison.InvariantCultureIgnoreCase))
         {
             if (string.Equals(currentAttributeName, "name", StringComparison.InvariantCultureIgnoreCase))
             {
                 FillWebResourcesNames(completionSets, applicableTo, repositoryWebResource.GetConnectionWebResourceIntellisenseData()?.WebResourcesAll?.Values?.ToList(), "WebResources");
             }
             else if (string.Equals(currentAttributeName, "description", StringComparison.InvariantCultureIgnoreCase))
             {
                 FillSingleWebResourceAttribute(completionSets, applicableTo, repositoryWebResource.GetConnectionWebResourceIntellisenseData()?.WebResourcesAll?.Values?.ToList(), currentXmlNode, WebResource.Schema.Attributes.description, w => w.Description);
             }
             else if (string.Equals(currentAttributeName, "displayName", StringComparison.InvariantCultureIgnoreCase))
             {
                 FillSingleWebResourceAttribute(completionSets, applicableTo, repositoryWebResource.GetConnectionWebResourceIntellisenseData()?.WebResourcesAll?.Values?.ToList(), currentXmlNode, WebResource.Schema.Attributes.displayname, w => w.DisplayName);
             }
             else if (string.Equals(currentAttributeName, "languagecode", StringComparison.InvariantCultureIgnoreCase))
             {
                 FillSingleWebResourceAttribute(completionSets, applicableTo, repositoryWebResource.GetConnectionWebResourceIntellisenseData()?.WebResourcesAll?.Values?.ToList(), currentXmlNode, WebResource.Schema.Attributes.languagecode, w => w.LanguageCode.ToString());
             }
             else if (string.Equals(currentAttributeName, "libraryUniqueId", StringComparison.InvariantCultureIgnoreCase))
             {
                 FillNewGuid(completionSets, applicableTo);
             }
         }
     }
     catch (Exception ex)
     {
         DTEHelper.WriteExceptionToOutput(connectionData, ex);
     }
 }
        private void FillSessionForGridXmlCompletionSet(
            IList <CompletionSet> completionSets
            , ConnectionData connectionData
            , ConnectionIntellisenseDataRepository repositoryEntities
            , WebResourceIntellisenseDataRepository repositoryWebResource
            , XElement currentXmlNode
            , string currentNodeName
            , string currentAttributeName
            , ITrackingSpan applicableTo
            )
        {
            try
            {
                if (string.Equals(currentNodeName, "grid", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (string.Equals(currentAttributeName, "object", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillEntityNamesInList(completionSets, applicableTo, repositoryEntities, true);
                    }
                    else if (string.Equals(currentAttributeName, "jump", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillEntityPrimaryAttributeForGrid(completionSets, applicableTo, repositoryEntities, currentXmlNode, true);

                        FillEntityAttributesInListForGrid(completionSets, applicableTo, repositoryEntities, currentXmlNode);
                    }
                }
                else if (string.Equals(currentNodeName, "row", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (string.Equals(currentAttributeName, "id", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillEntityPrimaryAttributeForGrid(completionSets, applicableTo, repositoryEntities, currentXmlNode, false);

                        FillEntityAttributesInListForGrid(completionSets, applicableTo, repositoryEntities, currentXmlNode);
                    }
                }
                else if (string.Equals(currentNodeName, "cell", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (string.Equals(currentAttributeName, "name", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillEntityAttributesInListForGrid(completionSets, applicableTo, repositoryEntities, currentXmlNode);
                    }
                    else if (string.Equals(currentAttributeName, "imageproviderwebresource", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillWebResourcesTextWithWebResourcePrefix(completionSets, applicableTo, repositoryWebResource.GetConnectionWebResourceIntellisenseData()?.GetJavaScriptWebResources()?.ToList(), "WebResources");
                    }
                }
            }
            catch (Exception ex)
            {
                DTEHelper.WriteExceptionToOutput(connectionData, ex);
            }
        }
Ejemplo n.º 4
0
        private EntityIntellisenseData GetEntityIntellisenseData(string entityName)
        {
            var result = this.ConnectionData.GetEntityIntellisenseData(entityName);

            if (result != null)
            {
                return(result);
            }

            EntityQueryExpression entityQueryExpression = ConnectionIntellisenseDataRepository.GetEntityQueryExpression();

            entityQueryExpression.Criteria.Conditions.Add(new MetadataConditionExpression(nameof(Entity.LogicalName), MetadataConditionOperator.Equals, entityName));

            var response = (RetrieveMetadataChangesResponse)this.ExecuteWithSyncMetadataHandling(
                new RetrieveMetadataChangesRequest()
            {
                ClientVersionStamp = null,
                Query = entityQueryExpression,
            }
                );

            return(this.ConnectionData.GetEntityIntellisenseData(entityName));
        }
        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>()));
            }
        }
        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 FillSessionForSiteMap(
            SnapshotPoint triggerPoint
            , ICompletionSession session
            , IList <CompletionSet> completionSets
            , ITextSnapshot snapshot
            , XElement doc
            , ConnectionData connectionData
            , ConnectionIntellisenseDataRepository repositoryEntities
            , SiteMapIntellisenseDataRepository repositorySiteMap
            , WebResourceIntellisenseDataRepository repositoryWebResource
            )
        {
            {
                HashSet <string> usedEntities = GetUsedEntities(doc);

                if (usedEntities.Any())
                {
                    repositoryEntities.GetEntityDataForNamesAsync(usedEntities);
                }
            }

            SnapshotPoint currentPoint = (session.TextView.Caret.Position.BufferPosition) - 1;

            var spans = _classifier.GetClassificationSpans(new SnapshotSpan(snapshot, 0, snapshot.Length));

            var firstSpans = spans.Where(s =>
                                         s.Span.Start <= currentPoint.Position
                                         )
                             .OrderByDescending(s => s.Span.Start.Position)
                             .ToList();

            var firstDelimiter = firstSpans.FirstOrDefault(s => s.ClassificationType.IsOfType("XML Attribute Quotes"));

            var lastSpans = spans.Where(s =>
                                        s.Span.Start > currentPoint.Position
                                        )
                            .OrderBy(s => s.Span.Start.Position)
                            .ToList();

            var lastDelimiter = lastSpans.FirstOrDefault(s => s.ClassificationType.IsOfType("XML Attribute Quotes"));

            SnapshotSpan?extentTemp = null;

            if (firstDelimiter != null && firstDelimiter.Span.GetText() == "\"\"")
            {
                extentTemp = new SnapshotSpan(firstDelimiter.Span.Start.Add(1), firstDelimiter.Span.Start.Add(1));
            }
            else if (firstDelimiter != null && lastDelimiter != null && firstDelimiter.Span.GetText() == "\"" && lastDelimiter.Span.GetText() == "\"")
            {
                extentTemp = new SnapshotSpan(firstDelimiter.Span.End, lastDelimiter.Span.Start);
            }

            if (!extentTemp.HasValue)
            {
                return;
            }

            var extent = extentTemp.Value;

            {
                var extentText = extent.GetText();

                if (extentText == ",\"")
                {
                    extent = new SnapshotSpan(extent.Snapshot, extent.Start, extent.Length - 1);
                }
            }

            var currentXmlNode = GetCurrentXmlNode(doc, extent);

            if (currentXmlNode == null)
            {
                return;
            }

            var containingAttributeSpans = spans
                                           .Where(s => s.Span.Contains(extent.Start) &&
                                                  s.Span.Contains(extent) &&
                                                  s.ClassificationType.IsOfType("XML Attribute Value"))
                                           .OrderByDescending(s => s.Span.Start.Position)
                                           .ToList();

            var containingAttributeValue = containingAttributeSpans.FirstOrDefault();

            if (containingAttributeValue == null)
            {
                containingAttributeValue = spans
                                           .Where(s => s.Span.Contains(extent.Start) &&
                                                  s.Span.Contains(extent) &&
                                                  s.ClassificationType.IsOfType("XML Attribute Quotes") &&
                                                  s.Span.GetText() == "\"\""
                                                  )
                                           .OrderByDescending(s => s.Span.Start.Position)
                                           .FirstOrDefault();
            }

            if (containingAttributeValue == null)
            {
                return;
            }

            ClassificationSpan currentAttr = GetCurrentXmlAttributeName(snapshot, containingAttributeValue, spans);

            if (currentAttr == null)
            {
                return;
            }

            string currentNodeName = currentXmlNode.Name.LocalName;

            string currentAttributeName = currentAttr.Span.GetText();

            ITrackingSpan applicableTo = snapshot.CreateTrackingSpan(extent, SpanTrackingMode.EdgeInclusive);

            try
            {
                if (string.Equals(currentNodeName, "SiteMap", StringComparison.InvariantCultureIgnoreCase))
                {
                    #region Urls

                    if (string.Equals(currentAttributeName, "Url", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().Urls, "Urls");

                        FillWebResourcesText(completionSets, applicableTo, repositoryWebResource.GetWebResourceIntellisenseData()?.WebResourcesHtml?.Values?.ToList(), "WebResources");
                    }

                    #endregion Urls
                }
                else if (string.Equals(currentNodeName, "Area", StringComparison.InvariantCultureIgnoreCase))
                {
                    #region Urls

                    if (string.Equals(currentAttributeName, "Url", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().Urls, "Urls");

                        FillWebResourcesText(completionSets, applicableTo, repositoryWebResource.GetWebResourceIntellisenseData()?.WebResourcesHtml?.Values?.ToList(), "WebResources");
                    }

                    #endregion Urls

                    #region Icons

                    else if (string.Equals(currentAttributeName, "Icon", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().Icons, "Icons");

                        FillWebResourcesIcons(completionSets, applicableTo, repositoryWebResource.GetWebResourceIntellisenseData()?.WebResourcesIcon?.Values?.ToList(), "WebResources");
                    }

                    #endregion Icons

                    #region Resources

                    else if (string.Equals(currentAttributeName, "ResourceId", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().ResourceIds, "Resources");
                    }
                    else if (string.Equals(currentAttributeName, "DescriptionResourceId", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().DescriptionResourceIds, "Resources");
                    }
                    else if (string.Equals(currentAttributeName, "ToolTipResourseId", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().ToolTipResourseIds, "Resources");
                    }

                    #endregion Resources
                }
                else if (string.Equals(currentNodeName, "Group", StringComparison.InvariantCultureIgnoreCase))
                {
                    #region Urls

                    if (string.Equals(currentAttributeName, "Url", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().Urls, "Urls");

                        FillWebResourcesText(completionSets, applicableTo, repositoryWebResource.GetWebResourceIntellisenseData()?.WebResourcesHtml?.Values?.ToList(), "WebResources");
                    }

                    #endregion Urls

                    #region Icons

                    else if (string.Equals(currentAttributeName, "Icon", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().Icons, "Icons");

                        FillWebResourcesIcons(completionSets, applicableTo, repositoryWebResource.GetWebResourceIntellisenseData()?.WebResourcesIcon?.Values?.ToList(), "WebResources");
                    }

                    #endregion Icons

                    #region Resources

                    else if (string.Equals(currentAttributeName, "ResourceId", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().ResourceIds, "Resources");
                    }
                    else if (string.Equals(currentAttributeName, "DescriptionResourceId", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().DescriptionResourceIds, "Resources");
                    }
                    else if (string.Equals(currentAttributeName, "ToolTipResourseId", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().ToolTipResourseIds, "Resources");
                    }

                    #endregion Resources
                }
                else if (string.Equals(currentNodeName, "SubArea", StringComparison.InvariantCultureIgnoreCase))
                {
                    #region Urls

                    if (string.Equals(currentAttributeName, "Url", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().Urls, "Urls");

                        FillWebResourcesText(completionSets, applicableTo, repositoryWebResource.GetWebResourceIntellisenseData()?.WebResourcesHtml?.Values?.ToList(), "WebResources");
                    }

                    #endregion Urls

                    #region Icons

                    else if (string.Equals(currentAttributeName, "Icon", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().Icons, "Icons");

                        FillWebResourcesIcons(completionSets, applicableTo, repositoryWebResource.GetWebResourceIntellisenseData()?.WebResourcesIcon?.Values?.ToList(), "WebResources");
                    }
                    else if (string.Equals(currentAttributeName, "OutlookShortcutIcon", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().Icons, "Icons");

                        FillWebResourcesIcons(completionSets, applicableTo, repositoryWebResource.GetWebResourceIntellisenseData()?.WebResourcesIcon?.Values?.ToList(), "WebResources");
                    }

                    #endregion Icons

                    #region Resources

                    else if (string.Equals(currentAttributeName, "ResourceId", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().ResourceIds, "Resources");
                    }
                    else if (string.Equals(currentAttributeName, "DescriptionResourceId", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().DescriptionResourceIds, "Resources");
                    }
                    else if (string.Equals(currentAttributeName, "ToolTipResourseId", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().ToolTipResourseIds, "Resources");
                    }

                    #endregion Resources

                    #region Panes

                    else if (string.Equals(currentAttributeName, "GetStartedPanePath", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().GetStartedPanePaths, "Panes");
                    }
                    else if (string.Equals(currentAttributeName, "GetStartedPanePathOutlook", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().GetStartedPanePathOutlooks, "Panes");
                    }
                    else if (string.Equals(currentAttributeName, "GetStartedPanePathAdmin", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().GetStartedPanePathAdmins, "Panes");
                    }
                    else if (string.Equals(currentAttributeName, "GetStartedPanePathAdminOutlook", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().GetStartedPanePathAdminOutlooks, "Panes");
                    }

                    #endregion Panes

                    else if (string.Equals(currentAttributeName, "Entity", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillEntityNamesInList(completionSets, applicableTo, repositoryEntities, false);
                    }
                    else if (string.Equals(currentAttributeName, "Sku", StringComparison.InvariantCultureIgnoreCase))
                    {
                        applicableTo = SkipComma(snapshot, extent, applicableTo);

                        FillSku(completionSets, applicableTo);
                    }
                    else if (string.Equals(currentAttributeName, "Client", StringComparison.InvariantCultureIgnoreCase))
                    {
                        applicableTo = SkipComma(snapshot, extent, applicableTo);

                        FillClient(completionSets, applicableTo);
                    }

                    else if (string.Equals(currentAttributeName, "DefaultDashboard", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillDashboards(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData()?.Dashboards?.Values?.ToList(), "Dashboards");
                    }

                    else if (string.Equals(currentAttributeName, "CheckExtensionProperty", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().CheckExtensionProperties, "Properties");
                    }
                }
                else if (string.Equals(currentNodeName, "Privilege", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (string.Equals(currentAttributeName, "Entity", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillEntityNamesInList(completionSets, applicableTo, repositoryEntities, false);
                    }
                    else if (string.Equals(currentAttributeName, "Privilege", StringComparison.InvariantCultureIgnoreCase))
                    {
                        applicableTo = SkipComma(snapshot, extent, applicableTo);

                        FillPrivileges(completionSets, applicableTo);
                    }
                }
                else if (string.Equals(currentNodeName, "Title", StringComparison.InvariantCultureIgnoreCase) ||
                         string.Equals(currentNodeName, "Description", StringComparison.InvariantCultureIgnoreCase)
                         )
                {
                    if (string.Equals(currentAttributeName, "LCID", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillLCID(completionSets, applicableTo);
                    }
                }
            }
            catch (Exception ex)
            {
                DTEHelper.WriteExceptionToOutput(connectionData, ex);
            }
        }
Ejemplo n.º 8
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 FillSessionForRibbonDiffXml(
            SnapshotPoint triggerPoint
            , ICompletionSession session
            , IList <CompletionSet> completionSets
            , ITextSnapshot snapshot
            , XElement doc
            , ConnectionData connectionData
            , ConnectionIntellisenseDataRepository repositoryEntities
            , WebResourceIntellisenseDataRepository repositoryWebResource
            , RibbonIntellisenseDataRepository repositoryRibbon
            )
        {
            SnapshotPoint currentPoint = (session.TextView.Caret.Position.BufferPosition) - 1;

            var spans = _classifier.GetClassificationSpans(new SnapshotSpan(snapshot, 0, snapshot.Length));

            var firstSpans = spans
                             .Where(s => s.Span.Start <= currentPoint.Position)
                             .OrderByDescending(s => s.Span.Start.Position)
                             .ToList();

            var firstDelimiter = firstSpans.FirstOrDefault(s => s.ClassificationType.IsOfType("XML Attribute Quotes"));

            var lastSpans = spans
                            .Where(s => s.Span.Start > currentPoint.Position)
                            .OrderBy(s => s.Span.Start.Position)
                            .ToList();

            var lastDelimiter = lastSpans.FirstOrDefault(s => s.ClassificationType.IsOfType("XML Attribute Quotes"));

            SnapshotSpan?extentTemp = null;

            if (firstDelimiter != null && firstDelimiter.Span.GetText() == "\"\"")
            {
                extentTemp = new SnapshotSpan(firstDelimiter.Span.Start.Add(1), firstDelimiter.Span.Start.Add(1));
            }
            else if (firstDelimiter != null && lastDelimiter != null && firstDelimiter.Span.GetText() == "\"" && lastDelimiter.Span.GetText() == "\"")
            {
                extentTemp = new SnapshotSpan(firstDelimiter.Span.End, lastDelimiter.Span.Start);
            }

            if (!extentTemp.HasValue)
            {
                return;
            }

            var extent = extentTemp.Value;

            {
                var extentText = extent.GetText();

                if (extentText == ",\"")
                {
                    extent = new SnapshotSpan(extent.Snapshot, extent.Start, extent.Length - 1);
                }
            }

            var currentXmlNode = GetCurrentXmlNode(doc, extent);

            if (currentXmlNode == null)
            {
                return;
            }

            var containingAttributeSpans = spans
                                           .Where(s => s.Span.Contains(extent.Start) &&
                                                  s.Span.Contains(extent) &&
                                                  s.ClassificationType.IsOfType("XML Attribute Value"))
                                           .OrderByDescending(s => s.Span.Start.Position)
                                           .ToList();

            var containingAttributeValue = containingAttributeSpans.FirstOrDefault();

            if (containingAttributeValue == null)
            {
                containingAttributeValue = spans
                                           .Where(s => s.Span.Contains(extent.Start) &&
                                                  s.Span.Contains(extent) &&
                                                  s.ClassificationType.IsOfType("XML Attribute Quotes") &&
                                                  s.Span.GetText() == "\"\""
                                                  )
                                           .OrderByDescending(s => s.Span.Start.Position)
                                           .FirstOrDefault();
            }

            if (containingAttributeValue == null)
            {
                return;
            }

            ClassificationSpan currentAttr = GetCurrentXmlAttributeName(snapshot, containingAttributeValue, spans);

            if (currentAttr == null)
            {
                return;
            }

            string currentNodeName = currentXmlNode.Name.LocalName;

            string currentAttributeName = currentAttr.Span.GetText();

            ITrackingSpan applicableTo = snapshot.CreateTrackingSpan(extent, SpanTrackingMode.EdgeInclusive);

            try
            {
                RibbonIntellisenseData ribbonIntellisenseData = null;

                var attrEntityName = doc.Attribute(IntellisenseContext.IntellisenseContextAttributeEntityName);

                if (attrEntityName != null)
                {
                    if (!string.IsNullOrEmpty(attrEntityName.Value))
                    {
                        var connectionIntellisense = repositoryEntities.GetEntitiesIntellisenseData();

                        if (connectionIntellisense != null &&
                            connectionIntellisense.Entities != null &&
                            connectionIntellisense.Entities.ContainsKey(attrEntityName.Value)
                            )
                        {
                            ribbonIntellisenseData = repositoryRibbon.GetRibbonIntellisenseData(attrEntityName.Value);
                        }
                    }
                    else
                    {
                        ribbonIntellisenseData = repositoryRibbon.GetRibbonIntellisenseData(string.Empty);
                    }
                }

                if (_controlsWithImagesXmlElements.Contains(currentNodeName) &&
                    ImagesXmlAttributes.Contains(currentAttributeName)
                    )
                {
                    FillWebResourcesIcons(completionSets, applicableTo, repositoryWebResource.GetWebResourceIntellisenseData()?.WebResourcesIcon?.Values?.ToList(), "WebResources");

                    if (ribbonIntellisenseData != null)
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, ribbonIntellisenseData.Images, "Images");
                    }
                }

                if (string.Equals(currentAttributeName, "ModernImage", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (ribbonIntellisenseData != null)
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, ribbonIntellisenseData.ModernImages, "ModernImages");
                    }
                }

                if (string.Equals(currentNodeName, "CustomAction", StringComparison.InvariantCultureIgnoreCase) &&
                    string.Equals(currentAttributeName, "Location", StringComparison.InvariantCultureIgnoreCase)
                    )
                {
                    if (ribbonIntellisenseData != null)
                    {
                        var sorted = new SortedSet <string>(ribbonIntellisenseData.Locations.Keys);

                        FillRibbonLocations(completionSets, applicableTo, sorted, "Locations");
                    }
                }

                if (string.Equals(currentAttributeName, "Sequence", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (ribbonIntellisenseData != null)
                    {
                        FillRibbonSequences(completionSets, applicableTo, currentXmlNode, ribbonIntellisenseData.Locations, "Locations");
                    }
                }

                if (LabelXmlAttributes.Contains(currentAttributeName))
                {
                    bool isTitleElement = string.Equals(currentNodeName, "Title", StringComparison.InvariantCultureIgnoreCase) &&
                                          currentXmlNode.Parent != null &&
                                          string.Equals(currentXmlNode.Parent.Name.LocalName, "Titles", StringComparison.InvariantCultureIgnoreCase) &&
                                          currentXmlNode.Parent.Parent != null &&
                                          string.Equals(currentXmlNode.Parent.Parent.Name.LocalName, "LocLabel", StringComparison.InvariantCultureIgnoreCase);

                    if (!isTitleElement)
                    {
                        var localValues = FillLocLables(completionSets, applicableTo, doc, "LocLabels");

                        if (ribbonIntellisenseData != null)
                        {
                            var sorted = new SortedSet <string>(ribbonIntellisenseData.LabelTexts.Where(s => !localValues.Contains(s)));

                            FillIntellisenseBySet(completionSets, applicableTo, sorted, "Labels in Ribbon");
                        }
                    }
                }

                if (CommandXmlAttributes.Contains(currentAttributeName))
                {
                    var localValues = FillCommandsLocal(completionSets, applicableTo, doc, "Commands");

                    if (ribbonIntellisenseData != null)
                    {
                        var sorted = new SortedSet <string>(ribbonIntellisenseData.CommandDefinitions.Keys.Where(s => !localValues.Contains(s)));

                        FillIntellisenseBySet(completionSets, applicableTo, sorted, "Commands in Ribbon");
                    }
                }

                if (string.Equals(currentNodeName, "EnableRule", StringComparison.InvariantCultureIgnoreCase) &&
                    string.Equals(currentAttributeName, "Id", StringComparison.InvariantCultureIgnoreCase) &&
                    currentXmlNode.Parent != null &&
                    string.Equals(currentXmlNode.Parent.Name.LocalName, "EnableRules", StringComparison.InvariantCultureIgnoreCase) &&
                    currentXmlNode.Parent.Parent != null &&
                    string.Equals(currentXmlNode.Parent.Parent.Name.LocalName, "CommandDefinition", StringComparison.InvariantCultureIgnoreCase)
                    )
                {
                    var localValues = FillEnableRulesLocal(completionSets, applicableTo, doc, "EnableRules");

                    if (ribbonIntellisenseData != null)
                    {
                        var sorted = new SortedSet <string>(ribbonIntellisenseData.EnableRules.Keys.Where(s => !localValues.Contains(s)));

                        FillIntellisenseBySet(completionSets, applicableTo, sorted, "EnableRules in Ribbon");
                    }
                }

                if (string.Equals(currentNodeName, "DisplayRule", StringComparison.InvariantCultureIgnoreCase) &&
                    string.Equals(currentAttributeName, "Id", StringComparison.InvariantCultureIgnoreCase) &&
                    currentXmlNode.Parent != null &&
                    string.Equals(currentXmlNode.Parent.Name.LocalName, "DisplayRules", StringComparison.InvariantCultureIgnoreCase) &&
                    currentXmlNode.Parent.Parent != null &&
                    string.Equals(currentXmlNode.Parent.Parent.Name.LocalName, "CommandDefinition", StringComparison.InvariantCultureIgnoreCase)
                    )
                {
                    var localValues = FillDisplayRulesLocal(completionSets, applicableTo, doc, "DisplayRules");

                    if (ribbonIntellisenseData != null)
                    {
                        var sorted = new SortedSet <string>(ribbonIntellisenseData.DisplayRules.Keys.Where(s => !localValues.Contains(s)).Select(s => s));

                        FillIntellisenseBySet(completionSets, applicableTo, sorted, "DisplayRules in Ribbon");
                    }
                }

                if (string.Equals(currentAttributeName, "EntityName", StringComparison.InvariantCultureIgnoreCase)
                    &&
                    (
                        string.Equals(currentNodeName, "EntityRule", StringComparison.InvariantCultureIgnoreCase) ||
                        string.Equals(currentNodeName, "EntityPropertyRule", StringComparison.InvariantCultureIgnoreCase) ||
                        string.Equals(currentNodeName, "FormEntityContextRule", StringComparison.InvariantCultureIgnoreCase) ||
                        string.Equals(currentNodeName, "EntityPrivilegeRule", StringComparison.InvariantCultureIgnoreCase)
                    )
                    )
                {
                    FillEntityNamesInList(completionSets, applicableTo, repositoryEntities, false, false);
                }

                if (string.Equals(currentAttributeName, IntellisenseContext.NameIntellisenseContextName + ":" + IntellisenseContext.NameIntellisenseContextAttributeEntityName, StringComparison.InvariantCultureIgnoreCase)
                    &&
                    (
                        string.Equals(currentNodeName, Commands.AbstractDynamicCommandXsdSchemas.RootRibbonDiffXml, StringComparison.InvariantCultureIgnoreCase) ||
                        string.Equals(currentNodeName, Commands.AbstractDynamicCommandXsdSchemas.RootRibbonDefinitions, StringComparison.InvariantCultureIgnoreCase)
                    )
                    )
                {
                    FillEntityNamesInList(completionSets, applicableTo, repositoryEntities, false, false);
                }

                if (string.Equals(currentNodeName, "ValueRule", StringComparison.InvariantCultureIgnoreCase) &&
                    string.Equals(currentAttributeName, "Field", StringComparison.InvariantCultureIgnoreCase)
                    )
                {
                    if (attrEntityName != null &&
                        !string.IsNullOrEmpty(attrEntityName.Value)
                        )
                    {
                        var entityIntellisenseData = repositoryEntities.GetEntitiesIntellisenseData();

                        if (entityIntellisenseData != null &&
                            entityIntellisenseData.Entities.ContainsKey(attrEntityName.Value)
                            )
                        {
                            FillEntityIntellisenseDataAttributes(completionSets, applicableTo, entityIntellisenseData.Entities[attrEntityName.Value]);
                        }
                    }
                }

                if (string.Equals(currentNodeName, "ValueRule", StringComparison.InvariantCultureIgnoreCase) &&
                    string.Equals(currentAttributeName, "Value", StringComparison.InvariantCultureIgnoreCase)
                    )
                {
                    if (attrEntityName != null &&
                        !string.IsNullOrEmpty(attrEntityName.Value) &&
                        currentXmlNode.Attribute("Field") != null &&
                        !string.IsNullOrEmpty(currentXmlNode.Attribute("Field").Value)
                        )
                    {
                        FillEntityAttributeValues(completionSets, applicableTo, repositoryEntities, attrEntityName.Value, currentXmlNode.Attribute("Field").Value);
                    }
                }

                if (string.Equals(currentNodeName, "CustomRule", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (string.Equals(currentAttributeName, "Library", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillWebResourcesText(completionSets, applicableTo, repositoryWebResource.GetWebResourceIntellisenseData()?.WebResourcesJavaScript?.Values?.ToList(), "WebResources");

                        if (ribbonIntellisenseData != null)
                        {
                            FillIntellisenseBySet(completionSets, applicableTo, ribbonIntellisenseData.Libraries, "Library from Ribbon");
                        }
                    }
                    else if (string.Equals(currentAttributeName, "FunctionName", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (ribbonIntellisenseData != null)
                        {
                            FillIntellisenseBySet(completionSets, applicableTo, ribbonIntellisenseData.FunctionsNames, "FunctionName from Ribbon");
                        }
                    }
                }
                else if (string.Equals(currentNodeName, "JavaScriptFunction", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (string.Equals(currentAttributeName, "Library", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillWebResourcesText(completionSets, applicableTo, repositoryWebResource.GetWebResourceIntellisenseData()?.WebResourcesJavaScript?.Values?.ToList(), "WebResources");

                        if (ribbonIntellisenseData != null)
                        {
                            FillIntellisenseBySet(completionSets, applicableTo, ribbonIntellisenseData.Libraries, "Library from Ribbon");
                        }
                    }
                    else if (string.Equals(currentAttributeName, "FunctionName", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (ribbonIntellisenseData != null)
                        {
                            FillIntellisenseBySet(completionSets, applicableTo, ribbonIntellisenseData.FunctionsNames, "FunctionName from Ribbon");
                        }
                    }
                }
                else if (string.Equals(currentNodeName, "Title", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (string.Equals(currentAttributeName, "languagecode", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillLCID(completionSets, applicableTo);
                    }
                }
            }
            catch (Exception ex)
            {
                DTEHelper.WriteExceptionToOutput(connectionData, ex);
            }
        }
        private void FillSessionForFetchXmlCompletionSet(
            IList <CompletionSet> completionSets
            , XElement doc
            , ConnectionData connectionData
            , ConnectionIntellisenseDataRepository repositoryEntities
            , XElement currentXmlNode
            , string currentNodeName
            , string currentAttributeName
            , ITrackingSpan applicableTo
            )
        {
            try
            {
                if (string.Equals(currentNodeName, "entity", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (string.Equals(currentAttributeName, "name", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillEntityNamesInList(completionSets, applicableTo, repositoryEntities, false);
                    }
                }
                else if (string.Equals(currentNodeName, "attribute", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (string.Equals(currentAttributeName, "name", StringComparison.InvariantCultureIgnoreCase))
                    {
                        Dictionary <string, string> aliases = GetEntityAliases(doc);

                        FillEntityAttributesInList(completionSets, applicableTo, repositoryEntities, currentXmlNode, aliases);
                    }
                }
                else if (string.Equals(currentNodeName, "order", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (string.Equals(currentAttributeName, "attribute", StringComparison.InvariantCultureIgnoreCase))
                    {
                        Dictionary <string, string> aliases = GetEntityAliases(doc);

                        FillEntityAttributesInList(completionSets, applicableTo, repositoryEntities, currentXmlNode, aliases);
                    }
                }
                else if (string.Equals(currentNodeName, "condition", StringComparison.InvariantCultureIgnoreCase))
                {
                    Dictionary <string, string> aliases = GetEntityAliases(doc);

                    if (string.Equals(currentAttributeName, "attribute", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillEntityAttributesInList(completionSets, applicableTo, repositoryEntities, currentXmlNode, aliases);
                    }
                    else if (string.Equals(currentAttributeName, "value", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillEntityAttributeValuesInList(completionSets, applicableTo, repositoryEntities, currentXmlNode, aliases);
                    }
                    else if (string.Equals(currentAttributeName, "entityname", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillAliases(completionSets, applicableTo, aliases);
                    }
                }
                else if (string.Equals(currentNodeName, "link-entity", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (string.Equals(currentAttributeName, "name", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillLinkedEntityNames(completionSets, applicableTo, repositoryEntities, currentXmlNode);

                        FillEntityNamesInList(completionSets, applicableTo, repositoryEntities, false);
                    }
                    else if (string.Equals(currentAttributeName, "from", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillLinkedEntityFromField(completionSets, applicableTo, repositoryEntities, currentXmlNode);
                    }
                    else if (string.Equals(currentAttributeName, "to", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillLinkedEntityToField(completionSets, applicableTo, repositoryEntities, currentXmlNode);
                    }
                }
            }
            catch (Exception ex)
            {
                DTEHelper.WriteExceptionToOutput(connectionData, ex);
            }
        }
        public void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            if (_isDisposed)
            {
                return;
            }

            var connectionConfig = ConnectionConfiguration.Get();

            if (connectionConfig?.CurrentConnectionData == null)
            {
                return;
            }

            ITextSnapshot snapshot     = _buffer.CurrentSnapshot;
            var           triggerPoint = session.GetTriggerPoint(snapshot);

            if (triggerPoint == null)
            {
                return;
            }

            XElement doc = ReadXmlDocument(snapshot.GetText());

            if (doc == null)
            {
                return;
            }

            if (string.Equals(doc.Name.ToString(), Commands.AbstractDynamicCommandXsdSchemas.RootFetch, StringComparison.InvariantCultureIgnoreCase))
            {
                var repository = ConnectionIntellisenseDataRepository.GetRepository(connectionConfig.CurrentConnectionData);

                FillSessionForFetchXml(session, completionSets, snapshot, doc, connectionConfig.CurrentConnectionData, repository);
            }
            else if (string.Equals(doc.Name.ToString(), Commands.AbstractDynamicCommandXsdSchemas.RootGrid, StringComparison.InvariantCultureIgnoreCase))
            {
                var repository = ConnectionIntellisenseDataRepository.GetRepository(connectionConfig.CurrentConnectionData);

                FillSessionForGridXml(session, completionSets, snapshot, doc, connectionConfig.CurrentConnectionData, repository);
            }
            else if (string.Equals(doc.Name.ToString(), Commands.AbstractDynamicCommandXsdSchemas.RootSavedQuery, StringComparison.InvariantCultureIgnoreCase))
            {
                var repository = ConnectionIntellisenseDataRepository.GetRepository(connectionConfig.CurrentConnectionData);

                FillSessionForFetchXml(session, completionSets, snapshot, doc, connectionConfig.CurrentConnectionData, repository);

                FillSessionForGridXml(session, completionSets, snapshot, doc, connectionConfig.CurrentConnectionData, repository);
            }
            else if (string.Equals(doc.Name.ToString(), Commands.AbstractDynamicCommandXsdSchemas.RootSiteMap, StringComparison.InvariantCultureIgnoreCase))
            {
                var repositoryEntities    = ConnectionIntellisenseDataRepository.GetRepository(connectionConfig.CurrentConnectionData);
                var repositorySiteMap     = SiteMapIntellisenseDataRepository.GetRepository(connectionConfig.CurrentConnectionData);
                var repositoryWebResource = WebResourceIntellisenseDataRepository.GetRepository(connectionConfig.CurrentConnectionData);

                FillSessionForSiteMap(triggerPoint.Value, session, completionSets, snapshot, doc, connectionConfig.CurrentConnectionData, repositoryEntities, repositorySiteMap, repositoryWebResource);
            }
            else if (string.Equals(doc.Name.ToString(), Commands.AbstractDynamicCommandXsdSchemas.RootRibbonDiffXml, StringComparison.InvariantCultureIgnoreCase) ||
                     string.Equals(doc.Name.ToString(), Commands.AbstractDynamicCommandXsdSchemas.RootRibbonDefinitions, StringComparison.InvariantCultureIgnoreCase)
                     )
            {
                var repositoryEntities    = ConnectionIntellisenseDataRepository.GetRepository(connectionConfig.CurrentConnectionData);
                var repositoryWebResource = WebResourceIntellisenseDataRepository.GetRepository(connectionConfig.CurrentConnectionData);

                var repositoryRibbon = RibbonIntellisenseDataRepository.GetRepository(connectionConfig.CurrentConnectionData);

                FillSessionForRibbonDiffXml(triggerPoint.Value, session, completionSets, snapshot, doc, connectionConfig.CurrentConnectionData, repositoryEntities, repositoryWebResource, repositoryRibbon);
            }
        }
        private void FillSessionForSiteMapCompletionSet(IList <CompletionSet> completionSets, ITextSnapshot snapshot, ConnectionData connectionData, ConnectionIntellisenseDataRepository repositoryEntities, SiteMapIntellisenseDataRepository repositorySiteMap, WebResourceIntellisenseDataRepository repositoryWebResource, SnapshotSpan extent, string currentNodeName, string currentAttributeName, ITrackingSpan applicableTo)
        {
            try
            {
                if (string.Equals(currentNodeName, "SiteMap", StringComparison.InvariantCultureIgnoreCase))
                {
                    #region Urls

                    if (string.Equals(currentAttributeName, "Url", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().Urls, "Urls");

                        FillWebResourcesTextWithWebResourcePrefix(completionSets, applicableTo, repositoryWebResource.GetConnectionWebResourceIntellisenseData()?.GetHtmlWebResources()?.ToList(), "WebResources");
                    }

                    #endregion Urls
                }
                else if (string.Equals(currentNodeName, "Area", StringComparison.InvariantCultureIgnoreCase))
                {
                    #region Urls

                    if (string.Equals(currentAttributeName, "Url", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().Urls, "Urls");

                        FillWebResourcesTextWithWebResourcePrefix(completionSets, applicableTo, repositoryWebResource.GetConnectionWebResourceIntellisenseData()?.GetHtmlWebResources()?.ToList(), "WebResources");
                    }

                    #endregion Urls

                    #region Icons

                    else if (string.Equals(currentAttributeName, "Icon", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().Icons, "Icons");

                        FillWebResourcesIcons(completionSets, applicableTo, repositoryWebResource.GetWebResourcesIcon()?.Values?.ToList(), "WebResources");
                    }

                    #endregion Icons

                    #region Resources

                    else if (string.Equals(currentAttributeName, "ResourceId", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().ResourceIds, "Resources");
                    }
                    else if (string.Equals(currentAttributeName, "DescriptionResourceId", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().DescriptionResourceIds, "Resources");
                    }
                    else if (string.Equals(currentAttributeName, "ToolTipResourseId", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().ToolTipResourseIds, "Resources");
                    }

                    #endregion Resources
                }
                else if (string.Equals(currentNodeName, "Group", StringComparison.InvariantCultureIgnoreCase))
                {
                    #region Urls

                    if (string.Equals(currentAttributeName, "Url", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().Urls, "Urls");

                        FillWebResourcesTextWithWebResourcePrefix(completionSets, applicableTo, repositoryWebResource.GetConnectionWebResourceIntellisenseData()?.GetHtmlWebResources()?.ToList(), "WebResources");
                    }

                    #endregion Urls

                    #region Icons

                    else if (string.Equals(currentAttributeName, "Icon", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().Icons, "Icons");

                        FillWebResourcesIcons(completionSets, applicableTo, repositoryWebResource.GetWebResourcesIcon()?.Values?.ToList(), "WebResources");
                    }

                    #endregion Icons

                    #region Resources

                    else if (string.Equals(currentAttributeName, "ResourceId", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().ResourceIds, "Resources");
                    }
                    else if (string.Equals(currentAttributeName, "DescriptionResourceId", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().DescriptionResourceIds, "Resources");
                    }
                    else if (string.Equals(currentAttributeName, "ToolTipResourseId", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().ToolTipResourseIds, "Resources");
                    }

                    #endregion Resources
                }
                else if (string.Equals(currentNodeName, "SubArea", StringComparison.InvariantCultureIgnoreCase))
                {
                    #region Urls

                    if (string.Equals(currentAttributeName, "Url", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().Urls, "Urls");

                        FillWebResourcesTextWithWebResourcePrefix(completionSets, applicableTo, repositoryWebResource.GetConnectionWebResourceIntellisenseData()?.GetHtmlWebResources()?.ToList(), "WebResources");
                    }

                    #endregion Urls

                    #region Icons

                    else if (string.Equals(currentAttributeName, "Icon", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().Icons, "Icons");

                        FillWebResourcesIcons(completionSets, applicableTo, repositoryWebResource.GetWebResourcesIcon()?.Values?.ToList(), "WebResources");
                    }
                    else if (string.Equals(currentAttributeName, "OutlookShortcutIcon", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().Icons, "Icons");

                        FillWebResourcesIcons(completionSets, applicableTo, repositoryWebResource.GetWebResourcesIcon()?.Values?.ToList(), "WebResources");
                    }

                    #endregion Icons

                    #region Resources

                    else if (string.Equals(currentAttributeName, "ResourceId", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().ResourceIds, "Resources");
                    }
                    else if (string.Equals(currentAttributeName, "DescriptionResourceId", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().DescriptionResourceIds, "Resources");
                    }
                    else if (string.Equals(currentAttributeName, "ToolTipResourseId", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().ToolTipResourseIds, "Resources");
                    }

                    #endregion Resources

                    #region Panes

                    else if (string.Equals(currentAttributeName, "GetStartedPanePath", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().GetStartedPanePaths, "Panes");
                    }
                    else if (string.Equals(currentAttributeName, "GetStartedPanePathOutlook", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().GetStartedPanePathOutlooks, "Panes");
                    }
                    else if (string.Equals(currentAttributeName, "GetStartedPanePathAdmin", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().GetStartedPanePathAdmins, "Panes");
                    }
                    else if (string.Equals(currentAttributeName, "GetStartedPanePathAdminOutlook", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().GetStartedPanePathAdminOutlooks, "Panes");
                    }

                    #endregion Panes

                    else if (string.Equals(currentAttributeName, "Entity", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillEntityNamesInList(completionSets, applicableTo, repositoryEntities, false);
                    }
                    else if (string.Equals(currentAttributeName, "Sku", StringComparison.InvariantCultureIgnoreCase))
                    {
                        applicableTo = SkipComma(snapshot, extent, applicableTo);

                        FillSku(completionSets, applicableTo);
                    }
                    else if (string.Equals(currentAttributeName, "Client", StringComparison.InvariantCultureIgnoreCase))
                    {
                        applicableTo = SkipComma(snapshot, extent, applicableTo);

                        FillClient(completionSets, applicableTo);
                    }

                    else if (string.Equals(currentAttributeName, "DefaultDashboard", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillDashboards(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData()?.Dashboards?.Values?.ToList(), "Dashboards");
                    }

                    else if (string.Equals(currentAttributeName, "CheckExtensionProperty", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, repositorySiteMap.GetSiteMapIntellisenseData().CheckExtensionProperties, "Properties");
                    }
                }
                else if (string.Equals(currentNodeName, "Privilege", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (string.Equals(currentAttributeName, "Entity", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillEntityNamesInList(completionSets, applicableTo, repositoryEntities, false);
                    }
                    else if (string.Equals(currentAttributeName, "Privilege", StringComparison.InvariantCultureIgnoreCase))
                    {
                        applicableTo = SkipComma(snapshot, extent, applicableTo);

                        FillPrivileges(completionSets, applicableTo);
                    }
                }
                else if (string.Equals(currentNodeName, "Title", StringComparison.InvariantCultureIgnoreCase) ||
                         string.Equals(currentNodeName, "Description", StringComparison.InvariantCultureIgnoreCase)
                         )
                {
                    if (string.Equals(currentAttributeName, "LCID", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillLCID(completionSets, applicableTo);
                    }
                }
            }
            catch (Exception ex)
            {
                DTEHelper.WriteExceptionToOutput(connectionData, ex);
            }
        }
        private void FillEntityAttributesInList(IList <CompletionSet> completionSets, ITrackingSpan applicableTo, ConnectionIntellisenseDataRepository repository, XElement currentXmlNode, Dictionary <string, string> aliases)
        {
            var entityName = string.Empty;

            if (string.Equals(currentXmlNode.Name.LocalName, "condition", StringComparison.InvariantCultureIgnoreCase))
            {
                var entityNameInCondition = GetAttributeValue(currentXmlNode, "entityname");

                if (!string.IsNullOrEmpty(entityNameInCondition) && aliases.ContainsKey(entityNameInCondition))
                {
                    entityName = aliases[entityNameInCondition];
                }
            }

            if (string.IsNullOrEmpty(entityName))
            {
                entityName = GetParentEntityName(currentXmlNode);
            }

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

            var entityData = repository.GetEntityAttributeIntellisense(entityName);

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

            FillEntityIntellisenseDataAttributes(completionSets, applicableTo, entityData);
        }
        private void FillEntityAttributesInListForGrid(IList <CompletionSet> completionSets, ITrackingSpan applicableTo, ConnectionIntellisenseDataRepository repository, XElement currentXmlNode)
        {
            int?entityTypeCode = GetParentEntityObjectTypeCode(currentXmlNode);

            if (!entityTypeCode.HasValue)
            {
                return;
            }

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

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

            FillEntityIntellisenseDataAttributes(completionSets, applicableTo, entityData);
        }
Ejemplo n.º 17
0
        private void FillSessionForRibbonDiffXmlCompletionSet(
            IList <CompletionSet> completionSets
            , XElement doc
            , ConnectionData connectionData
            , ConnectionIntellisenseDataRepository repositoryEntities
            , WebResourceIntellisenseDataRepository repositoryWebResource
            , RibbonIntellisenseDataRepository repositoryRibbon
            , XElement currentXmlNode
            , string currentNodeName
            , string currentAttributeName
            , ITrackingSpan applicableTo
            )
        {
            try
            {
                RibbonIntellisenseData ribbonIntellisenseData = null;

                var attrEntityName = doc.Attribute(IntellisenseContext.IntellisenseContextAttributeEntityName);

                if (attrEntityName != null)
                {
                    if (!string.IsNullOrEmpty(attrEntityName.Value))
                    {
                        var connectionIntellisense = repositoryEntities.GetEntitiesIntellisenseData();

                        if (connectionIntellisense != null &&
                            connectionIntellisense.Entities != null &&
                            connectionIntellisense.Entities.ContainsKey(attrEntityName.Value)
                            )
                        {
                            ribbonIntellisenseData = repositoryRibbon.GetRibbonIntellisenseData(attrEntityName.Value);
                        }
                    }
                    else
                    {
                        ribbonIntellisenseData = repositoryRibbon.GetRibbonIntellisenseData(string.Empty);
                    }
                }

                if (ControlsWithImagesXmlElements.Contains(currentNodeName) &&
                    ImagesXmlAttributes.Contains(currentAttributeName)
                    )
                {
                    FillWebResourcesIcons(completionSets, applicableTo, repositoryWebResource.GetWebResourcesIcon()?.Values?.ToList(), "WebResources");

                    if (ribbonIntellisenseData != null)
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, ribbonIntellisenseData.Images, "Images");
                    }
                }

                if (string.Equals(currentAttributeName, "ModernImage", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (ribbonIntellisenseData != null)
                    {
                        FillIntellisenseBySet(completionSets, applicableTo, ribbonIntellisenseData.ModernImages, "ModernImages");
                    }
                }

                if (string.Equals(currentNodeName, "CustomAction", StringComparison.InvariantCultureIgnoreCase) &&
                    string.Equals(currentAttributeName, "Location", StringComparison.InvariantCultureIgnoreCase)
                    )
                {
                    if (ribbonIntellisenseData != null)
                    {
                        var sorted = new SortedSet <string>(ribbonIntellisenseData.Locations.Keys);

                        FillRibbonLocations(completionSets, applicableTo, sorted, "Locations");
                    }
                }

                if (string.Equals(currentAttributeName, "Sequence", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (ribbonIntellisenseData != null)
                    {
                        FillRibbonSequences(completionSets, applicableTo, currentXmlNode, ribbonIntellisenseData.Locations, "Locations");
                    }
                }

                if (string.Equals(currentAttributeName, "TemplateAlias", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (ribbonIntellisenseData != null)
                    {
                        FillRibbonTemplateAliases(completionSets, applicableTo, currentXmlNode, ribbonIntellisenseData.Locations, "TemplateAliases");
                    }
                }

                if (LabelXmlAttributes.Contains(currentAttributeName))
                {
                    bool isTitleElement = string.Equals(currentNodeName, "Title", StringComparison.InvariantCultureIgnoreCase) &&
                                          currentXmlNode.Parent != null &&
                                          string.Equals(currentXmlNode.Parent.Name.LocalName, "Titles", StringComparison.InvariantCultureIgnoreCase) &&
                                          currentXmlNode.Parent.Parent != null &&
                                          string.Equals(currentXmlNode.Parent.Parent.Name.LocalName, "LocLabel", StringComparison.InvariantCultureIgnoreCase);

                    if (!isTitleElement)
                    {
                        var localValues = FillLocLables(completionSets, applicableTo, doc, "LocLabels");

                        if (ribbonIntellisenseData != null)
                        {
                            var sorted = new SortedSet <string>(ribbonIntellisenseData.LabelTexts.Where(s => !localValues.Contains(s)));

                            FillIntellisenseBySet(completionSets, applicableTo, sorted, "Labels in Ribbon");
                        }
                    }
                }

                if (CommandXmlAttributes.Contains(currentAttributeName))
                {
                    var localValues = FillCommandsLocal(completionSets, applicableTo, doc, "Commands");

                    if (ribbonIntellisenseData != null)
                    {
                        var sorted = new SortedSet <string>(ribbonIntellisenseData.CommandDefinitions.Keys.Where(s => !localValues.Contains(s)));

                        FillIntellisenseBySet(completionSets, applicableTo, sorted, "Commands in Ribbon");
                    }
                }

                if (string.Equals(currentNodeName, "EnableRule", StringComparison.InvariantCultureIgnoreCase) &&
                    string.Equals(currentAttributeName, "Id", StringComparison.InvariantCultureIgnoreCase) &&
                    currentXmlNode.Parent != null &&
                    string.Equals(currentXmlNode.Parent.Name.LocalName, "EnableRules", StringComparison.InvariantCultureIgnoreCase) &&
                    currentXmlNode.Parent.Parent != null &&
                    string.Equals(currentXmlNode.Parent.Parent.Name.LocalName, "CommandDefinition", StringComparison.InvariantCultureIgnoreCase)
                    )
                {
                    var localValues = FillEnableRulesLocal(completionSets, applicableTo, doc, "EnableRules");

                    if (ribbonIntellisenseData != null)
                    {
                        var sorted = new SortedSet <string>(ribbonIntellisenseData.EnableRules.Keys.Where(s => !localValues.Contains(s)));

                        FillIntellisenseBySet(completionSets, applicableTo, sorted, "EnableRules in Ribbon");
                    }
                }

                if (string.Equals(currentNodeName, "DisplayRule", StringComparison.InvariantCultureIgnoreCase) &&
                    string.Equals(currentAttributeName, "Id", StringComparison.InvariantCultureIgnoreCase) &&
                    currentXmlNode.Parent != null &&
                    string.Equals(currentXmlNode.Parent.Name.LocalName, "DisplayRules", StringComparison.InvariantCultureIgnoreCase) &&
                    currentXmlNode.Parent.Parent != null &&
                    string.Equals(currentXmlNode.Parent.Parent.Name.LocalName, "CommandDefinition", StringComparison.InvariantCultureIgnoreCase)
                    )
                {
                    var localValues = FillDisplayRulesLocal(completionSets, applicableTo, doc, "DisplayRules");

                    if (ribbonIntellisenseData != null)
                    {
                        var sorted = new SortedSet <string>(ribbonIntellisenseData.DisplayRules.Keys.Where(s => !localValues.Contains(s)).Select(s => s));

                        FillIntellisenseBySet(completionSets, applicableTo, sorted, "DisplayRules in Ribbon");
                    }
                }

                if (string.Equals(currentAttributeName, "EntityName", StringComparison.InvariantCultureIgnoreCase)
                    &&
                    (
                        string.Equals(currentNodeName, "EntityRule", StringComparison.InvariantCultureIgnoreCase) ||
                        string.Equals(currentNodeName, "EntityPropertyRule", StringComparison.InvariantCultureIgnoreCase) ||
                        string.Equals(currentNodeName, "FormEntityContextRule", StringComparison.InvariantCultureIgnoreCase) ||
                        string.Equals(currentNodeName, "EntityPrivilegeRule", StringComparison.InvariantCultureIgnoreCase)
                    )
                    )
                {
                    FillEntityNamesInList(completionSets, applicableTo, repositoryEntities, false, false);
                }

                if (string.Equals(currentAttributeName, IntellisenseContext.IntellisenseContextNamespacePrefix + ":" + IntellisenseContext.NameIntellisenseContextAttributeEntityName, StringComparison.InvariantCultureIgnoreCase)
                    &&
                    (
                        string.Equals(currentNodeName, Commands.AbstractDynamicCommandXsdSchemas.RibbonDiffXmlRoot, StringComparison.InvariantCultureIgnoreCase) ||
                        string.Equals(currentNodeName, Commands.AbstractDynamicCommandXsdSchemas.RibbonXmlRoot, StringComparison.InvariantCultureIgnoreCase)
                    )
                    )
                {
                    FillEntityNamesInList(completionSets, applicableTo, repositoryEntities, false, false);
                }

                if (string.Equals(currentNodeName, "ValueRule", StringComparison.InvariantCultureIgnoreCase) &&
                    string.Equals(currentAttributeName, "Field", StringComparison.InvariantCultureIgnoreCase)
                    )
                {
                    if (attrEntityName != null &&
                        !string.IsNullOrEmpty(attrEntityName.Value)
                        )
                    {
                        var entityIntellisenseData = repositoryEntities.GetEntitiesIntellisenseData();

                        if (entityIntellisenseData != null &&
                            entityIntellisenseData.Entities.ContainsKey(attrEntityName.Value)
                            )
                        {
                            FillEntityIntellisenseDataAttributes(completionSets, applicableTo, entityIntellisenseData.Entities[attrEntityName.Value]);
                        }
                    }
                }

                if (string.Equals(currentNodeName, "ValueRule", StringComparison.InvariantCultureIgnoreCase) &&
                    string.Equals(currentAttributeName, "Value", StringComparison.InvariantCultureIgnoreCase)
                    )
                {
                    if (attrEntityName != null &&
                        !string.IsNullOrEmpty(attrEntityName.Value) &&
                        currentXmlNode.Attribute("Field") != null &&
                        !string.IsNullOrEmpty(currentXmlNode.Attribute("Field").Value)
                        )
                    {
                        FillEntityAttributeValues(completionSets, applicableTo, repositoryEntities, attrEntityName.Value, currentXmlNode.Attribute("Field").Value);
                    }
                }

                if (string.Equals(currentNodeName, "CustomRule", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (string.Equals(currentAttributeName, "Library", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillWebResourcesTextWithWebResourcePrefix(completionSets, applicableTo, repositoryWebResource.GetConnectionWebResourceIntellisenseData()?.GetJavaScriptWebResources()?.ToList(), "WebResources");

                        if (ribbonIntellisenseData != null)
                        {
                            FillIntellisenseBySet(completionSets, applicableTo, ribbonIntellisenseData.Libraries, "Library from Ribbon");
                        }
                    }
                    else if (string.Equals(currentAttributeName, "FunctionName", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (ribbonIntellisenseData != null)
                        {
                            FillIntellisenseBySet(completionSets, applicableTo, ribbonIntellisenseData.FunctionsNames, "FunctionName from Ribbon");
                        }
                    }
                }
                else if (string.Equals(currentNodeName, "JavaScriptFunction", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (string.Equals(currentAttributeName, "Library", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillWebResourcesTextWithWebResourcePrefix(completionSets, applicableTo, repositoryWebResource.GetConnectionWebResourceIntellisenseData()?.GetJavaScriptWebResources()?.ToList(), "WebResources");

                        if (ribbonIntellisenseData != null)
                        {
                            FillIntellisenseBySet(completionSets, applicableTo, ribbonIntellisenseData.Libraries, "Library from Ribbon");
                        }
                    }
                    else if (string.Equals(currentAttributeName, "FunctionName", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (ribbonIntellisenseData != null)
                        {
                            FillIntellisenseBySet(completionSets, applicableTo, ribbonIntellisenseData.FunctionsNames, "FunctionName from Ribbon");
                        }
                    }
                }
                else if (string.Equals(currentNodeName, "Title", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (string.Equals(currentAttributeName, "languagecode", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillLCID(completionSets, applicableTo);
                    }
                }
            }
            catch (Exception ex)
            {
                DTEHelper.WriteExceptionToOutput(connectionData, ex);
            }
        }
        private void FillEntityAttributeValuesInList(IList <CompletionSet> completionSets, ITrackingSpan applicableTo, ConnectionIntellisenseDataRepository repository, XElement nodeCondition, Dictionary <string, string> aliases)
        {
            string entityName = string.Empty;

            var attributeName = GetAttributeValue(nodeCondition, "attribute");

            var entityNameInCondition = GetAttributeValue(nodeCondition, "entityname");

            if (!string.IsNullOrEmpty(entityNameInCondition) && aliases.ContainsKey(entityNameInCondition))
            {
                entityName = aliases[entityNameInCondition];
            }
            else
            {
                entityName = GetParentEntityName(nodeCondition);
            }

            FillEntityAttributeValues(completionSets, applicableTo, repository, entityName, attributeName);
        }
        private void FillSessionForFetchXml(ICompletionSession session
                                            , IList <CompletionSet> completionSets
                                            , ITextSnapshot snapshot
                                            , XElement doc
                                            , ConnectionData connectionData
                                            , ConnectionIntellisenseDataRepository repository
                                            )
        {
            {
                HashSet <string> usedEntities = GetUsedEntities(doc);

                if (usedEntities.Any())
                {
                    repository.GetEntityDataForNamesAsync(usedEntities);
                }
            }

            SnapshotPoint currentPoint = (session.TextView.Caret.Position.BufferPosition) - 1;

            var spans = _classifier.GetClassificationSpans(new SnapshotSpan(snapshot, 0, snapshot.Length));

            var firstSpans = spans.Where(s =>
                                         s.Span.Start <= currentPoint.Position
                                         )
                             .OrderByDescending(s => s.Span.Start.Position)
                             .ToList();

            var lastSpans = spans.Where(s =>
                                        s.Span.Start > currentPoint.Position
                                        )
                            .OrderBy(s => s.Span.Start.Position)
                            .ToList();

            SnapshotSpan?extentTemp = null;

            if (!extentTemp.HasValue)
            {
                var firstDelimiter = firstSpans.FirstOrDefault(s => s.ClassificationType.IsOfType("XML Attribute Quotes"));

                if (firstDelimiter != null && firstDelimiter.Span.GetText() == "\"\"")
                {
                    extentTemp = new SnapshotSpan(firstDelimiter.Span.Start.Add(1), firstDelimiter.Span.Start.Add(1));
                }
            }

            if (!extentTemp.HasValue)
            {
                var firstDelimiter = firstSpans.FirstOrDefault(s => s.ClassificationType.IsOfType("XML Attribute Quotes"));
                var lastDelimiter  = lastSpans.FirstOrDefault(s => s.ClassificationType.IsOfType("XML Attribute Quotes"));

                if (firstDelimiter != null && lastDelimiter != null && firstDelimiter.Span.GetText() == "\"" && lastDelimiter.Span.GetText() == "\"")
                {
                    extentTemp = new SnapshotSpan(firstDelimiter.Span.End, lastDelimiter.Span.Start);
                }
            }

            if (extentTemp.HasValue)
            {
                var extent = extentTemp.Value;

                {
                    var extentText = extent.GetText();

                    if (extentText == ",\"")
                    {
                        extent = new SnapshotSpan(extent.Snapshot, extent.Start, extent.Length - 1);
                    }
                }

                var currentXmlNode = GetCurrentXmlNode(doc, extent);

                if (currentXmlNode == null)
                {
                    return;
                }

                var containingAttributeSpans = spans
                                               .Where(s => s.Span.Contains(extent.Start) &&
                                                      s.Span.Contains(extent) &&
                                                      s.ClassificationType.IsOfType("XML Attribute Value"))
                                               .OrderByDescending(s => s.Span.Start.Position)
                                               .ToList();

                var containingAttributeValue = containingAttributeSpans.FirstOrDefault();

                if (containingAttributeValue == null)
                {
                    containingAttributeValue = spans
                                               .Where(s => s.Span.Contains(extent.Start) &&
                                                      s.Span.Contains(extent) &&
                                                      s.ClassificationType.IsOfType("XML Attribute Quotes") &&
                                                      s.Span.GetText() == "\"\""
                                                      )
                                               .OrderByDescending(s => s.Span.Start.Position)
                                               .FirstOrDefault();
                }

                if (containingAttributeValue != null)
                {
                    ClassificationSpan currentAttr = GetCurrentXmlAttributeName(snapshot, containingAttributeValue, spans);

                    if (currentAttr == null)
                    {
                        return;
                    }

                    string currentNodeName = currentXmlNode.Name.LocalName;

                    string currentAttributeName = currentAttr.Span.GetText();

                    ITrackingSpan applicableTo = snapshot.CreateTrackingSpan(extent, SpanTrackingMode.EdgeInclusive);

                    try
                    {
                        if (string.Equals(currentNodeName, "entity", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (string.Equals(currentAttributeName, "name", StringComparison.InvariantCultureIgnoreCase))
                            {
                                FillEntityNamesInList(completionSets, applicableTo, repository, false);
                            }
                        }
                        else if (string.Equals(currentNodeName, "attribute", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (string.Equals(currentAttributeName, "name", StringComparison.InvariantCultureIgnoreCase))
                            {
                                Dictionary <string, string> aliases = GetEntityAliases(doc);

                                FillEntityAttributesInList(completionSets, applicableTo, repository, currentXmlNode, aliases);
                            }
                        }
                        else if (string.Equals(currentNodeName, "order", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (string.Equals(currentAttributeName, "attribute", StringComparison.InvariantCultureIgnoreCase))
                            {
                                Dictionary <string, string> aliases = GetEntityAliases(doc);

                                FillEntityAttributesInList(completionSets, applicableTo, repository, currentXmlNode, aliases);
                            }
                        }
                        else if (string.Equals(currentNodeName, "condition", StringComparison.InvariantCultureIgnoreCase))
                        {
                            Dictionary <string, string> aliases = GetEntityAliases(doc);

                            if (string.Equals(currentAttributeName, "attribute", StringComparison.InvariantCultureIgnoreCase))
                            {
                                FillEntityAttributesInList(completionSets, applicableTo, repository, currentXmlNode, aliases);
                            }
                            else if (string.Equals(currentAttributeName, "value", StringComparison.InvariantCultureIgnoreCase))
                            {
                                FillEntityAttributeValuesInList(completionSets, applicableTo, repository, currentXmlNode, aliases);
                            }
                            else if (string.Equals(currentAttributeName, "entityname", StringComparison.InvariantCultureIgnoreCase))
                            {
                                FillAliases(completionSets, applicableTo, aliases);
                            }
                        }
                        else if (string.Equals(currentNodeName, "link-entity", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (string.Equals(currentAttributeName, "name", StringComparison.InvariantCultureIgnoreCase))
                            {
                                FillLinkedEntityNames(completionSets, applicableTo, repository, currentXmlNode);

                                FillEntityNamesInList(completionSets, applicableTo, repository, false);
                            }
                            else if (string.Equals(currentAttributeName, "from", StringComparison.InvariantCultureIgnoreCase))
                            {
                                FillLinkedEntityFromField(completionSets, applicableTo, repository, currentXmlNode);
                            }
                            else if (string.Equals(currentAttributeName, "to", StringComparison.InvariantCultureIgnoreCase))
                            {
                                FillLinkedEntityToField(completionSets, applicableTo, repository, currentXmlNode);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        DTEHelper.WriteExceptionToOutput(connectionData, ex);
                    }
                }
            }
            else
            {
                extentTemp = null;

                if (!extentTemp.HasValue)
                {
                    var firstDelimiter = firstSpans.FirstOrDefault(s => s.ClassificationType.IsOfType("XML Delimiter") && s.Span.GetText().EndsWith("></"));

                    if (firstDelimiter != null && firstDelimiter.Span.GetText() == "></")
                    {
                        extentTemp = new SnapshotSpan(firstDelimiter.Span.Start.Add(1), firstDelimiter.Span.Start.Add(1));
                    }
                }

                if (!extentTemp.HasValue)
                {
                    var firstDelimiter = firstSpans.FirstOrDefault(s => s.ClassificationType.IsOfType("XML Delimiter") && s.Span.GetText().Trim().EndsWith(">"));
                    var lastDelimiter  = lastSpans.FirstOrDefault(s => s.ClassificationType.IsOfType("XML Delimiter") && s.Span.GetText().Trim().StartsWith("</"));

                    if (firstDelimiter != null && lastDelimiter != null)
                    {
                        var temp = new SnapshotSpan(firstDelimiter.Span.End, lastDelimiter.Span.Start);

                        if (string.IsNullOrWhiteSpace(temp.GetText()))
                        {
                            extentTemp = new SnapshotSpan(firstDelimiter.Span.End, 0);
                        }
                        else
                        {
                            int spacesStart = temp.GetText().TakeWhile(ch => char.IsWhiteSpace(ch)).Count();
                            int spacesEnd   = temp.GetText().Reverse().TakeWhile(ch => char.IsWhiteSpace(ch)).Count();

                            extentTemp = new SnapshotSpan(firstDelimiter.Span.End.Add(spacesStart), lastDelimiter.Span.Start.Add(-spacesEnd));
                        }
                    }
                }

                if (!extentTemp.HasValue)
                {
                    return;
                }

                var extent = extentTemp.Value;

                var currentXmlNode = GetCurrentXmlNode(doc, extent);

                if (currentXmlNode == null)
                {
                    return;
                }

                if (!string.Equals(currentXmlNode.Name.LocalName, "value", StringComparison.InvariantCultureIgnoreCase))
                {
                    return;
                }

                var nodeCondition = currentXmlNode.Parent;

                if (nodeCondition == null || !string.Equals(nodeCondition.Name.LocalName, "condition", StringComparison.InvariantCultureIgnoreCase))
                {
                    return;
                }

                ITrackingSpan applicableTo = snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeInclusive);

                Dictionary <string, string> aliases = GetEntityAliases(doc);

                FillEntityAttributeValuesInList(completionSets, applicableTo, repository, nodeCondition, aliases);
            }
        }
Ejemplo n.º 20
0
        private void FillEntityAttributesInWebResourceDependencyXml(IList <CompletionSet> completionSets, ITrackingSpan applicableTo, ConnectionIntellisenseDataRepository repositoryEntities, XElement currentXmlNode)
        {
            var entityName = GetAttributeValue(currentXmlNode, "entityName");

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

            var entityData = repositoryEntities.GetEntityAttributeIntellisense(entityName);

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

            FillEntityIntellisenseDataAttributes(completionSets, applicableTo, entityData);
        }
        private void FillSessionForGridXml(ICompletionSession session
                                           , IList <CompletionSet> completionSets
                                           , ITextSnapshot snapshot
                                           , XElement doc
                                           , ConnectionData connectionData
                                           , ConnectionIntellisenseDataRepository repository
                                           )
        {
            {
                HashSet <int> usedEntityCodes = GetUsedEntityObjectTypeCodes(doc);

                if (usedEntityCodes.Any())
                {
                    repository.GetEntityDataForObjectTypeCodesAsync(usedEntityCodes);
                }
            }

            SnapshotPoint currentPoint = (session.TextView.Caret.Position.BufferPosition) - 1;

            var spans = _classifier.GetClassificationSpans(new SnapshotSpan(snapshot, 0, snapshot.Length));

            var firstSpans = spans.Where(s =>
                                         s.Span.Start <= currentPoint.Position
                                         )
                             .OrderByDescending(s => s.Span.Start.Position)
                             .ToList();

            var firstDelimiter = firstSpans.FirstOrDefault(s => s.ClassificationType.IsOfType("XML Attribute Quotes"));

            var lastSpans = spans.Where(s =>
                                        s.Span.Start > currentPoint.Position
                                        )
                            .OrderBy(s => s.Span.Start.Position)
                            .ToList();

            var lastDelimiter = lastSpans.FirstOrDefault(s => s.ClassificationType.IsOfType("XML Attribute Quotes"));

            SnapshotSpan?extentTemp = null;

            if (firstDelimiter != null && firstDelimiter.Span.GetText() == "\"\"")
            {
                extentTemp = new SnapshotSpan(firstDelimiter.Span.Start.Add(1), firstDelimiter.Span.Start.Add(1));
            }
            else if (firstDelimiter != null && lastDelimiter != null && firstDelimiter.Span.GetText() == "\"" && lastDelimiter.Span.GetText() == "\"")
            {
                extentTemp = new SnapshotSpan(firstDelimiter.Span.End, lastDelimiter.Span.Start);
            }

            if (!extentTemp.HasValue)
            {
                return;
            }

            var extent = extentTemp.Value;

            {
                var extentText = extent.GetText();

                if (extentText == ",\"")
                {
                    extent = new SnapshotSpan(extent.Snapshot, extent.Start, extent.Length - 1);
                }
            }

            var currentXmlNode = GetCurrentXmlNode(doc, extent);

            if (currentXmlNode == null)
            {
                return;
            }

            var containingAttributeSpans = spans
                                           .Where(s => s.Span.Contains(extent.Start) &&
                                                  s.Span.Contains(extent) &&
                                                  s.ClassificationType.IsOfType("XML Attribute Value"))
                                           .OrderByDescending(s => s.Span.Start.Position)
                                           .ToList();

            var containingAttributeValue = containingAttributeSpans.FirstOrDefault();

            if (containingAttributeValue == null)
            {
                containingAttributeValue = spans
                                           .Where(s => s.Span.Contains(extent.Start) &&
                                                  s.Span.Contains(extent) &&
                                                  s.ClassificationType.IsOfType("XML Attribute Quotes") &&
                                                  s.Span.GetText() == "\"\""
                                                  )
                                           .OrderByDescending(s => s.Span.Start.Position)
                                           .FirstOrDefault();
            }

            if (containingAttributeValue == null)
            {
                return;
            }

            ClassificationSpan currentAttr = GetCurrentXmlAttributeName(snapshot, containingAttributeValue, spans);

            if (currentAttr == null)
            {
                return;
            }

            string currentNodeName = currentXmlNode.Name.LocalName;

            string currentAttributeName = currentAttr.Span.GetText();

            ITrackingSpan applicableTo = snapshot.CreateTrackingSpan(extent, SpanTrackingMode.EdgeInclusive);

            try
            {
                if (string.Equals(currentNodeName, "grid", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (string.Equals(currentAttributeName, "object", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillEntityNamesInList(completionSets, applicableTo, repository, true);
                    }
                    else if (string.Equals(currentAttributeName, "jump", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillEntityPrimaryAttributeForGrid(completionSets, applicableTo, repository, currentXmlNode, true);

                        FillEntityAttributesInListForGrid(completionSets, applicableTo, repository, currentXmlNode);
                    }
                }
                else if (string.Equals(currentNodeName, "row", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (string.Equals(currentAttributeName, "id", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillEntityPrimaryAttributeForGrid(completionSets, applicableTo, repository, currentXmlNode, false);

                        FillEntityAttributesInListForGrid(completionSets, applicableTo, repository, currentXmlNode);
                    }
                }
                else if (string.Equals(currentNodeName, "cell", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (string.Equals(currentAttributeName, "name", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FillEntityAttributesInListForGrid(completionSets, applicableTo, repository, currentXmlNode);
                    }
                }
            }
            catch (Exception ex)
            {
                DTEHelper.WriteExceptionToOutput(connectionData, ex);
            }
        }
        private void FillLinkedEntityToField(IList <CompletionSet> completionSets, ITrackingSpan applicableTo, ConnectionIntellisenseDataRepository repository, XElement currentXmlNode)
        {
            var parentEntityName = GetParentEntityName(currentXmlNode);

            var linkEntityName = GetAttributeValue(currentXmlNode, "name");

            FillPrimaryEntityAttributes(completionSets, applicableTo, repository, parentEntityName, linkEntityName);
        }
        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);
        }
Ejemplo n.º 24
0
        public void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            if (_isDisposed)
            {
                return;
            }

            var connectionConfig = ConnectionConfiguration.Get();

            if (connectionConfig?.CurrentConnectionData == null)
            {
                return;
            }

            ITextSnapshot snapshot     = _buffer.CurrentSnapshot;
            var           triggerPoint = session.GetTriggerPoint(snapshot);

            if (triggerPoint == null)
            {
                return;
            }

            var repository = ConnectionIntellisenseDataRepository.GetRepository(connectionConfig.CurrentConnectionData);

            SnapshotSpan extent = FindTokenSpanAtPosition(session).GetSpan(snapshot);

            ITrackingSpan applicableTo = null;

            if (extent.GetText() == ".")
            {
                extent = new SnapshotSpan(extent.Start + 1, extent.End);
            }

            var line = triggerPoint.Value.GetContainingLine().Extent;

            var relativePath = string.Empty;

            if (line.Start <= extent.Start)
            {
                relativePath = new SnapshotSpan(line.Start, extent.Start).GetText().TrimEnd('.');
            }

            applicableTo = snapshot.CreateTrackingSpan(extent, SpanTrackingMode.EdgeInclusive);

            var intellisenseData = repository.GetEntitiesIntellisenseData();

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

            try
            {
                if (string.IsNullOrEmpty(relativePath))
                {
                    FillEntityNamesInList(completionSets, applicableTo, intellisenseData, false);
                }
                else
                {
                    var usedEntities = GetUsedEntitiesFromPath(relativePath, intellisenseData);

                    if (usedEntities.Any())
                    {
                        repository.GetEntityDataForNamesAsync(usedEntities);
                    }

                    var entityNameHash = GetEntityNameFromPath(relativePath, intellisenseData, out bool isGuid);

                    if (entityNameHash != null)
                    {
                        if (entityNameHash.Count == 1)
                        {
                            var entityName = entityNameHash.First();

                            var entityData = repository.GetEntityAttributeIntellisense(entityName);

                            if (entityData != null)
                            {
                                FillEntityIntellisenseDataAttributes(completionSets, applicableTo, entityData);

                                FillMultiLinkForEntity(completionSets, applicableTo, intellisenseData, entityData);
                            }
                        }
                        else if (entityNameHash.Count > 0)
                        {
                            FillMultiLinkEntityForEntities(completionSets, applicableTo, entityNameHash, intellisenseData);
                        }
                        else if (isGuid)
                        {
                            FillMultiLinkEntityForAll(completionSets, applicableTo, intellisenseData);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                DTEHelper.WriteExceptionToOutput(connectionConfig.CurrentConnectionData, ex);
            }
        }
        private void FillSessionsXmlAttribute(IList <CompletionSet> completionSets, ITrackingSpan applicableTo, ConnectionData connectionData, ITextSnapshot snapshot, SnapshotSpan extent, XElement doc, XElement currentXmlNode, string currentNodeName, string currentAttributeName)
        {
            if (string.Equals(doc.Name.LocalName, Commands.AbstractDynamicCommandXsdSchemas.FetchRoot, StringComparison.InvariantCultureIgnoreCase))
            {
                var repository = ConnectionIntellisenseDataRepository.GetRepository(connectionData);

                HashSet <string> usedEntities = GetUsedEntities(doc);

                if (usedEntities.Any())
                {
                    repository.GetEntityDataForNamesAsync(usedEntities);
                }

                FillSessionForFetchXmlCompletionSet(completionSets, doc, connectionData, repository, currentXmlNode, currentNodeName, currentAttributeName, applicableTo);
            }
            else if (string.Equals(doc.Name.LocalName, Commands.AbstractDynamicCommandXsdSchemas.GridRoot, StringComparison.InvariantCultureIgnoreCase))
            {
                var repositoryEntities    = ConnectionIntellisenseDataRepository.GetRepository(connectionData);
                var repositoryWebResource = WebResourceIntellisenseDataRepository.GetRepository(connectionData);

                HashSet <int> usedEntityCodes = GetUsedEntityObjectTypeCodes(doc);

                if (usedEntityCodes.Any())
                {
                    repositoryEntities.GetEntityDataForObjectTypeCodesAsync(usedEntityCodes);
                }

                FillSessionForGridXmlCompletionSet(completionSets, connectionData, repositoryEntities, repositoryWebResource, currentXmlNode, currentNodeName, currentAttributeName, applicableTo);
            }
            else if (string.Equals(doc.Name.LocalName, Commands.AbstractDynamicCommandXsdSchemas.SavedQueryRoot, StringComparison.InvariantCultureIgnoreCase))
            {
                var repositoryEntities    = ConnectionIntellisenseDataRepository.GetRepository(connectionData);
                var repositoryWebResource = WebResourceIntellisenseDataRepository.GetRepository(connectionData);

                HashSet <string> usedEntities = GetUsedEntities(doc);

                if (usedEntities.Any())
                {
                    repositoryEntities.GetEntityDataForNamesAsync(usedEntities);
                }

                HashSet <int> usedEntityCodes = GetUsedEntityObjectTypeCodes(doc);

                if (usedEntityCodes.Any())
                {
                    repositoryEntities.GetEntityDataForObjectTypeCodesAsync(usedEntityCodes);
                }

                FillSessionForFetchXmlCompletionSet(completionSets, doc, connectionData, repositoryEntities, currentXmlNode, currentNodeName, currentAttributeName, applicableTo);

                FillSessionForGridXmlCompletionSet(completionSets, connectionData, repositoryEntities, repositoryWebResource, currentXmlNode, currentNodeName, currentAttributeName, applicableTo);
            }
            else if (string.Equals(doc.Name.LocalName, Commands.AbstractDynamicCommandXsdSchemas.SiteMapXmlRoot, StringComparison.InvariantCultureIgnoreCase))
            {
                var repositoryEntities    = ConnectionIntellisenseDataRepository.GetRepository(connectionData);
                var repositorySiteMap     = SiteMapIntellisenseDataRepository.GetRepository(connectionData);
                var repositoryWebResource = WebResourceIntellisenseDataRepository.GetRepository(connectionData);

                HashSet <string> usedEntities = GetUsedEntities(doc);

                if (usedEntities.Any())
                {
                    repositoryEntities.GetEntityDataForNamesAsync(usedEntities);
                }

                FillSessionForSiteMapCompletionSet(completionSets, snapshot, connectionData, repositoryEntities, repositorySiteMap, repositoryWebResource, extent, currentNodeName, currentAttributeName, applicableTo);
            }
            else if (string.Equals(doc.Name.LocalName, Commands.AbstractDynamicCommandXsdSchemas.RibbonDiffXmlRoot, StringComparison.InvariantCultureIgnoreCase) ||
                     string.Equals(doc.Name.LocalName, Commands.AbstractDynamicCommandXsdSchemas.RibbonXmlRoot, StringComparison.InvariantCultureIgnoreCase)
                     )
            {
                var repositoryEntities    = ConnectionIntellisenseDataRepository.GetRepository(connectionData);
                var repositoryWebResource = WebResourceIntellisenseDataRepository.GetRepository(connectionData);

                var repositoryRibbon = RibbonIntellisenseDataRepository.GetRepository(connectionData);

                FillSessionForRibbonDiffXmlCompletionSet(completionSets, doc, connectionData, repositoryEntities, repositoryWebResource, repositoryRibbon, currentXmlNode, currentNodeName, currentAttributeName, applicableTo);
            }
            else if (string.Equals(doc.Name.LocalName, Commands.AbstractDynamicCommandXsdSchemas.WebResourceDependencyXmlRoot, StringComparison.InvariantCultureIgnoreCase))
            {
                var repositoryEntities    = ConnectionIntellisenseDataRepository.GetRepository(connectionData);
                var repositoryWebResource = WebResourceIntellisenseDataRepository.GetRepository(connectionData);

                FillSessionForWebResourceDependencyXmlCompletionSet(completionSets, doc, connectionData, repositoryEntities, repositoryWebResource, currentXmlNode, currentNodeName, currentAttributeName, applicableTo);
            }
            else if (string.Equals(doc.Name.LocalName, Commands.AbstractDynamicCommandXsdSchemas.FormXmlRoot, StringComparison.InvariantCultureIgnoreCase))
            {
                var repositoryWebResource = WebResourceIntellisenseDataRepository.GetRepository(connectionData);

                FillSessionForFormXmlCompletionSet(completionSets, doc, connectionData, repositoryWebResource, currentXmlNode, currentNodeName, currentAttributeName, applicableTo);
            }
        }