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);
            }
        }
        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);
            }
        }
        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 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);
            }
        }