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 System.Threading.Tasks.Task GetItemsAsync( string searchString, IOmniBoxSearchSession session) { if (session.CancellationToken.IsCancellationRequested) { return(Task.FromCanceled(session.CancellationToken)); } var callbackShim = new SearchCallbackShim(session); session.CancellationToken.Register(() => this.StopSearch(callbackShim)); return(this.StartSearch(searchString, callbackShim)); }
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 searchCallback) { searchCallback.CancellationToken.ThrowIfCancellationRequested(); var callbackShim = new NavigateToCallbackShim(searchCallback); // ItemsSources for NavigateTo are transient and have to be refreshed each search. if (this.factory.TryCreateNavigateToItemProvider(this.shellServiceProvider, out var itemProvider)) { searchCallback.CancellationToken.Register(() => itemProvider.StopSearch()); itemProvider.StartSearch(callbackShim, searchString); await callbackShim.Task; } }
public async System.Threading.Tasks.Task GetItemsAsync(string searchString, IOmniBoxSearchSession searchSession) { await this.joinableTaskContext.Factory.SwitchToMainThreadAsync(); if (this.dte == null) { this.dte = (DTE)this.serviceProvider.GetService(typeof(DTE)); } if (this.textManager == null) { this.textManager = (IVsTextManager2)this.serviceProvider.GetService(typeof(SVsTextManager)); } ITextView textView; if (!ErrorHandler.Succeeded(this.textManager.GetActiveView2(fMustHaveFocus: 1, pBuffer: null, grfIncludeViewFrameType: 0, out var ppView)) || (textView = this.adaptersFactory.GetWpfTextView(ppView)) == null) { this.ConsiderShellCommands(searchSession); }
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)); } } } } } }
public NavigateToCallbackShim(IOmniBoxSearchSession searchCallback) { this.searchCallback = searchCallback ?? throw new ArgumentNullException(nameof(searchCallback)); }