public AdornmentManagerTester() { _subjectBuffer = EditorFactory.CreateBuffer(TestExportProvider.ExportProviderWithCSharpAndVisualBasic, "Hi There"); _textView = new Mock<IWpfTextView>(); var aggregatorService = new Mock<IViewTagAggregatorFactoryService>(); _adornmentLayer = new Mock<IAdornmentLayer>(); _aggregator = new Mock<ITagAggregator<Tag>>(); var layerName = "LayerName"; _textView.Setup(tv => tv.GetAdornmentLayer(layerName)).Returns(_adornmentLayer.Object); _textView.SetupGet(tv => tv.VisualElement).Returns(new FrameworkElement()); aggregatorService.Setup(a => a.CreateTagAggregator<Tag>(_textView.Object)).Returns(_aggregator.Object); var textViewModel = new Mock<ITextViewModel>(); textViewModel.Setup(tvm => tvm.VisualBuffer).Returns(_subjectBuffer); _textView.Setup(tv => tv.TextViewModel).Returns(textViewModel.Object); var workspace = new TestWorkspace(); var listener = new AggregateAsynchronousOperationListener( Enumerable.Empty<Lazy<IAsynchronousOperationListener, FeatureMetadata>>(), FeatureAttribute.LineSeparators); Manager = AdornmentManager<Tag>.Create(_textView.Object, aggregatorService.Object, listener, adornmentLayerName: layerName); }
public NavigationBarControllerFactoryService( IWaitIndicator waitIndicator, [ImportMany] IEnumerable<Lazy<IAsynchronousOperationListener, FeatureMetadata>> asyncListeners) { _waitIndicator = waitIndicator; _asyncListener = new AggregateAsynchronousOperationListener(asyncListeners, FeatureAttribute.NavigationBar); }
public void TestMultipleBackgroundAction() { // Test that background actions don't run at the same time. var listener = new AggregateAsynchronousOperationListener(Enumerable.Empty<Lazy<IAsynchronousOperationListener, FeatureMetadata>>(), "Test"); var worker = new AsynchronousSerialWorkQueue(listener); var doneEvent = new AutoResetEvent(false); var action1Ran = false; var action2Ran = false; worker.EnqueueBackgroundWork(() => { Assert.NotSame(_foregroundSyncContext, SynchronizationContext.Current); action1Ran = true; // Simulate work to ensure that if tasks overlap that we will // see it. Thread.Sleep(1000); Assert.False(action2Ran); }, "Test", CancellationToken.None); worker.EnqueueBackgroundWork(() => { Assert.NotSame(_foregroundSyncContext, SynchronizationContext.Current); action2Ran = true; doneEvent.Set(); }, "Test", CancellationToken.None); doneEvent.WaitOne(); Assert.True(action1Ran); Assert.True(action2Ran); }
internal void BeginSession( EventHookupCommandHandler eventHookupCommandHandler, ITextView textView, ITextBuffer subjectBuffer, AggregateAsynchronousOperationListener asyncListener, Mutex testSessionHookupMutex) { CurrentSession = new EventHookupSession(this, eventHookupCommandHandler, textView, subjectBuffer, asyncListener, testSessionHookupMutex); }
public InlineRenameService( IWaitIndicator waitIndicator, ITextBufferAssociatedViewService textBufferAssociatedViewService, ITextBufferFactoryService textBufferFactoryService, [ImportMany] IEnumerable<IRefactorNotifyService> refactorNotifyServices, [ImportMany] IEnumerable<Lazy<IAsynchronousOperationListener, FeatureMetadata>> listeners) { _waitIndicator = waitIndicator; _textBufferAssociatedViewService = textBufferAssociatedViewService; _textBufferFactoryService = textBufferFactoryService; _refactorNotifyServices = refactorNotifyServices; _aggregateListener = new AggregateAsynchronousOperationListener(listeners, FeatureAttribute.Rename); }
public EventHookupCommandHandler( IInlineRenameService inlineRenameService, Microsoft.CodeAnalysis.Editor.Host.IWaitIndicator waitIndicator, IQuickInfoBroker quickInfoBroker, [Import(AllowDefault = true)] IHACK_EventHookupDismissalOnBufferChangePreventerService prematureDismissalPreventer, [ImportMany] IEnumerable<Lazy<IAsynchronousOperationListener, FeatureMetadata>> asyncListeners) { _inlineRenameService = inlineRenameService; _waitIndicator = waitIndicator; _prematureDismissalPreventer = prematureDismissalPreventer; _asyncListener = new AggregateAsynchronousOperationListener(asyncListeners, FeatureAttribute.EventHookup); this.EventHookupSessionManager = new EventHookupSessionManager(prematureDismissalPreventer, quickInfoBroker); }
public void TestBackgroundAction() { var listener = new AggregateAsynchronousOperationListener(Enumerable.Empty<Lazy<IAsynchronousOperationListener, FeatureMetadata>>(), "Test"); var worker = new AsynchronousSerialWorkQueue(listener); var doneEvent = new AutoResetEvent(initialState: false); var actionRan = false; worker.EnqueueBackgroundWork(() => { // Assert.NotNull(SynchronizationContext.Current); Assert.NotSame(_foregroundSyncContext, SynchronizationContext.Current); actionRan = true; doneEvent.Set(); }, GetType().Name + ".TestBackgroundAction", CancellationToken.None); doneEvent.WaitOne(); Assert.True(actionRan); }
public AbstractSnippetInfoService( Shell.SVsServiceProvider serviceProvider, Guid languageGuidForSnippets, IEnumerable<Lazy<IAsynchronousOperationListener, FeatureMetadata>> asyncListeners) { AssertIsForeground(); if (serviceProvider != null) { var textManager = (IVsTextManager2)serviceProvider.GetService(typeof(SVsTextManager)); if (textManager.GetExpansionManager(out _expansionManager) == VSConstants.S_OK) { ComEventSink.Advise<IVsExpansionEvents>(_expansionManager, this); _waiter = new AggregateAsynchronousOperationListener(asyncListeners, FeatureAttribute.Snippets); _languageGuidForSnippets = languageGuidForSnippets; PopulateSnippetCaches(); } } }
public void TestBackgroundCancel1() { // Ensure that we can cancel a background action. var listener = new AggregateAsynchronousOperationListener(Enumerable.Empty<Lazy<IAsynchronousOperationListener, FeatureMetadata>>(), "Test"); var worker = new AsynchronousSerialWorkQueue(listener); var taskRunningEvent = new AutoResetEvent(false); var cancelEvent = new AutoResetEvent(false); var doneEvent = new AutoResetEvent(false); var source = new CancellationTokenSource(); var cancellationToken = source.Token; var actionRan = false; worker.EnqueueBackgroundWork(() => { actionRan = true; Assert.NotSame(_foregroundSyncContext, SynchronizationContext.Current); Assert.False(cancellationToken.IsCancellationRequested); taskRunningEvent.Set(); cancelEvent.WaitOne(); Assert.True(cancellationToken.IsCancellationRequested); doneEvent.Set(); }, "Test", source.Token); taskRunningEvent.WaitOne(); source.Cancel(); cancelEvent.Set(); doneEvent.WaitOne(); Assert.True(actionRan); }
public AbstractSnippetInfoService( Shell.SVsServiceProvider serviceProvider, Guid languageGuidForSnippets, IEnumerable<Lazy<IAsynchronousOperationListener, FeatureMetadata>> asyncListeners) { _languageGuidForSnippets = languageGuidForSnippets; if (serviceProvider != null) { var textManager = (IVsTextManager2)serviceProvider.GetService(typeof(SVsTextManager)); if (textManager.GetExpansionManager(out _expansionManager) == VSConstants.S_OK) { ComEventSink.Advise<IVsExpansionEvents>(_expansionManager, this); } } IAsynchronousOperationListener waiter = new AggregateAsynchronousOperationListener(asyncListeners, FeatureAttribute.Snippets); var token = waiter.BeginAsyncOperation(GetType().Name + ".Start"); InitialCachePopulationTask = Task.Factory.StartNew(() => PopulateSnippetCaches(), CancellationToken.None, TaskCreationOptions.None, ForegroundTaskScheduler).CompletesAsyncOperation(token); }
public void TestBackgroundCancelMultipleActions() { // Ensure that multiple background actions are cancelled if they // use the same cancellation token. var listener = new AggregateAsynchronousOperationListener(Enumerable.Empty<Lazy<IAsynchronousOperationListener, FeatureMetadata>>(), "Test"); var worker = new AsynchronousSerialWorkQueue(listener); var taskRunningEvent = new AutoResetEvent(false); var cancelEvent = new AutoResetEvent(false); var doneEvent = new AutoResetEvent(false); var source = new CancellationTokenSource(); var cancellationToken = source.Token; var action1Ran = false; var action2Ran = false; worker.EnqueueBackgroundWork(() => { action1Ran = true; Assert.NotSame(_foregroundSyncContext, SynchronizationContext.Current); Assert.False(cancellationToken.IsCancellationRequested); taskRunningEvent.Set(); cancelEvent.WaitOne(); cancellationToken.ThrowIfCancellationRequested(); Assert.True(false); }, "Test", source.Token); // We should not run this action. worker.EnqueueBackgroundWork(() => { action2Ran = true; Assert.False(true); }, "Test", source.Token); taskRunningEvent.WaitOne(); source.Cancel(); cancelEvent.Set(); try { worker.WaitUntilCompletion_ForTestingPurposesOnly(); Assert.True(false); } catch (AggregateException ae) { Assert.IsAssignableFrom<OperationCanceledException>(ae.InnerException); } Assert.True(action1Ran); Assert.False(action2Ran); }
public void TestBackgroundCancelOneAction() { // Ensure that when a background action is cancelled the next // one starts (if it has a different cancellation token). var listener = new AggregateAsynchronousOperationListener(Enumerable.Empty<Lazy<IAsynchronousOperationListener, FeatureMetadata>>(), "Test"); var worker = new AsynchronousSerialWorkQueue(listener); var taskRunningEvent = new AutoResetEvent(false); var cancelEvent = new AutoResetEvent(false); var doneEvent = new AutoResetEvent(false); var source1 = new CancellationTokenSource(); var source2 = new CancellationTokenSource(); var token1 = source1.Token; var token2 = source2.Token; var action1Ran = false; var action2Ran = false; worker.EnqueueBackgroundWork(() => { action1Ran = true; Assert.NotSame(_foregroundSyncContext, SynchronizationContext.Current); Assert.False(token1.IsCancellationRequested); taskRunningEvent.Set(); cancelEvent.WaitOne(); token1.ThrowIfCancellationRequested(); Assert.True(false); }, "Test", source1.Token); worker.EnqueueBackgroundWork(() => { action2Ran = true; Assert.NotSame(_foregroundSyncContext, SynchronizationContext.Current); Assert.False(token2.IsCancellationRequested); taskRunningEvent.Set(); cancelEvent.WaitOne(); doneEvent.Set(); }, "Test", source2.Token); // Wait for the first task to start. taskRunningEvent.WaitOne(); // Cancel it source1.Cancel(); cancelEvent.Set(); // Wait for the second task to start. taskRunningEvent.WaitOne(); cancelEvent.Set(); // Wait for the second task to complete. doneEvent.WaitOne(); Assert.True(action1Ran); Assert.True(action2Ran); }
internal GraphQueryManager(Workspace workspace, AggregateAsynchronousOperationListener asyncListener) { _workspace = workspace; _asyncListener = asyncListener; }