public Task GetItemsAsync(string searchString, IOmniBoxSearchSession searchSession) { return(this.joinableTaskContext.Factory.RunAsync(async delegate { try { searchSession.CancellationToken.ThrowIfCancellationRequested(); // Has STA requirement, explicit marshal to avoid potential deadlocks. await this.joinableTaskContext.Factory.SwitchToMainThreadAsync(searchSession.CancellationToken); searchSession.CancellationToken.ThrowIfCancellationRequested(); IVsTemplateProviderFactory templateProviderFactory = await asyncServiceProvider .GetServiceAsync(typeof(Microsoft.Internal.VisualStudio.Shell.Interop.SVsDialogService)) as IVsTemplateProviderFactory; var installedTemplateProvider = templateProviderFactory.GetInstalledTemplateProvider(); var searchResultsNode = installedTemplateProvider.Search(searchString); foreach (IVsSearchResultTemplate template in searchResultsNode.Extensions) { OmniBoxItem obItem = new NPDTemplateSearchResultShim(template, installedTemplateProvider); searchSession.AddItem(obItem); searchSession.CancellationToken.ThrowIfCancellationRequested(); } } catch (Exception ex) when(!(ex is OperationCanceledException)) { Debug.Fail("Exception during NPD search " + ex.Message); } }).Task); }
public async System.Threading.Tasks.Task GetItemsAsync(string searchString, IOmniBoxSearchSession searchSession) { if (searchString == null || searchString.Length < 3) { return; } try { string result; using (var client = new HttpClient()) using (var response = await client.GetAsync($"https://docs.microsoft.com/api/search/rss?search={searchString}&locale=en-us", searchSession.CancellationToken)) { result = await response.Content.ReadAsStringAsync(); } if (searchSession.CancellationToken.IsCancellationRequested) { return; } XmlReader r = XmlReader.Create(new StringReader(result)); while (r.Read()) { if (r.NodeType == XmlNodeType.Element && r.Name == "item") { r.ReadToDescendant("title"); var title = r.ReadElementContentAsString("title", ""); r.ReadToNextSibling("description"); var desc = r.ReadElementContentAsString("description", ""); r.ReadToNextSibling("link"); var link = r.ReadElementContentAsString("link", ""); if (searchSession.CancellationToken.IsCancellationRequested) { return; } searchSession.AddItem(new DocOmniBoxItem(title, desc, link)); } } } catch (Exception ex) when(!(ex is OperationCanceledException)) { Debug.Fail("Failed to search for doc item: " + ex.Message); } }
public async System.Threading.Tasks.Task GetItemsAsync(string searchString, IOmniBoxSearchSession searchSession) { await this.joinableTaskContext.Factory.SwitchToMainThreadAsync(); if (this.textManager == null) { this.textManager = (IVsTextManager2)this.serviceProvider.GetService(typeof(SVsTextManager)); } if (!ErrorHandler.Succeeded(this.textManager.GetActiveView2(fMustHaveFocus: 1, pBuffer: null, grfIncludeViewFrameType: 0, out var ppView))) { return; } var textView = this.adaptersFactory.GetWpfTextView(ppView); if (textView != null) { if (await this.lightBulbBroker.HasSuggestedActionsAsync(this.categoryRegistryService.Any, textView, searchSession.CancellationToken)) { // TODO: too lazy... #pragma warning disable CS0618 // Type or member is obsolete var session = this.lightBulbBroker.CreateSession(this.categoryRegistryService.Any, textView); #pragma warning restore CS0618 // Type or member is obsolete if (session != null && session.TryGetSuggestedActionSets(out var actionSets) != QuerySuggestedActionCompletionStatus.Canceled) { foreach (var actionSet in actionSets) { foreach (var action in actionSet.Actions) { searchSession.AddItem(new LightBulbItem(action)); } } } } } }