public async void OnElementChanged(SMDisplayedElementChangedEventArgs e) { var element = e.NewElement; if (element.IsNull()) { return; } if (element.Type != ElementType.Item) { Application.Current.Dispatcher.Invoke(() => { CurrentWdw?.Close(); }); return; } try { // Cancel search early on element changed event var cts = new RemoteCancellationTokenSource(); Svc.SM.UI.ElementWdw.OnElementChanged += new ActionProxy <SMDisplayedElementChangedEventArgs>((args) => cts?.Cancel()); List <string> searchTerms = GetSearchTerms(); await SearchForCards(searchTerms, cts.Token); } catch (RemotingException) { } }
public PendingEntryResult(RemoteCancellationTokenSource cancellationTokenSrc, Task <EntryResult> entryResultTask, IDictionaryService plugin) { CancellationTokenSrc = cancellationTokenSrc; EntryResultTask = entryResultTask; Plugin = plugin; }
public RemoteTestCollectionRunner(ITestCollection testCollection, IEnumerable <IXunitTestCase> testCases, IMessageSink diagnosticMessageSink, IMessageBus messageBus, Type testCaseOrdererType, RemoteCancellationTokenSource remoteCancellationTokenSource, Exception aggregatorException) : base(testCollection, testCases, diagnosticMessageSink, messageBus, null, null, null) { _remoteCancellationTokenSource = remoteCancellationTokenSource; TestCaseOrderer = ObjectFactory.CreateTestCaseOrderer(testCaseOrdererType, diagnosticMessageSink); Aggregator = ObjectFactory.CreateExceptionAggregator(aggregatorException); CancellationTokenSource = remoteCancellationTokenSource.CancellationTokenSource; }
private void LookupWord(IDictionaryService dict, string word) { RemoteCancellationTokenSource cts = new RemoteCancellationTokenSource(); var entryResultTask = LookupWordEntryAsync(cts.Token, word, dict); DataContext = new PendingEntryResult(cts, entryResultTask, dict); Title += ": " + word; }
public void ShowDictionaryPopup() { var dict = Svc <PDFPlugin> .Plugin.DictionaryPlugin; if (dict == null || dict.CredentialsAvailable == false || IsTextSelectionValid() == false) { return; } string text = SelectedText?.Trim(' ', '\t', '\r', '\n'); if (string.IsNullOrWhiteSpace(text)) { return; } /* * int spaceIdx = text.IndexOfAny(new[] { ' ', '\r' }); * * if (spaceIdx > 0) * text = text.Substring(0, * spaceIdx); * * if (spaceIdx == 0 || string.IsNullOrWhiteSpace(text)) * return; */ var pageIdx = SelectInfo.StartPage; var startIdx = SelectInfo.StartIndex; var textInfos = Document.Pages[pageIdx].Text.GetTextInfo(startIdx, text.Length); if (textInfos?.Rects == null || textInfos.Rects.Any() == false) { Show.Window() .For(new Alert($"ShowDictionaryPopup: Failed to get selected text info ({startIdx}:{text.Length}@{pageIdx}).", "Error")); return; } // ReSharper disable once AssignNullToNotNullAttribute var wdw = Window.GetWindow(this); if (wdw == null) { LogTo.Error("ShowDictionaryPopup: Window.GetWindow(this) returned null"); Show.Window() .For(new Alert("ShowDictionaryPopup: Window.GetWindow(this) returned null", "Error")); return; } var cts = new RemoteCancellationTokenSource(); var entryResultTask = LookupWordEntryAsync(cts.Token, text, dict); var pagePt = PageToClient(pageIdx, new Point(textInfos.Rects.Last().right, textInfos.Rects.Last().top)); DictionaryPopup.HorizontalOffset = pagePt.X; DictionaryPopup.VerticalOffset = pagePt.Y; DictionaryPopup.DataContext = new PendingEntryResult(cts, entryResultTask, dict); DictionaryPopup.IsOpen = true; }