Exemple #1
0
        public SolutionEventMonitor(VisualStudioWorkspace workspace)
        {
            var notificationService = workspace.Services.GetService <IGlobalOperationNotificationService>() as GlobalOperationNotificationService;

            if (notificationService != null)
            {
                // subscribe to events only if it is normal service. if it is one from unit test or other, don't bother to subscribe
                _notificationService = notificationService;

                // make sure we set initial state correctly. otherwise, we can get into a race where we might miss the very first events
                if (KnownUIContexts.SolutionBuildingContext.IsActive)
                {
                    ContextChanged(active: true, operation: SolutionBuilding);
                }

                KnownUIContexts.SolutionBuildingContext.UIContextChanged += SolutionBuildingContextChanged;

                // make sure we set initial state correctly. otherwise, we can get into a race where we might miss the very first events
                if (KnownUIContexts.SolutionOpeningContext.IsActive)
                {
                    ContextChanged(active: true, operation: SolutionOpening);
                }

                KnownUIContexts.SolutionOpeningContext.UIContextChanged += SolutionOpeningContextChanged;
            }
        }
 public GlobalOperationNotificationServiceFactory(
     IAsynchronousOperationListenerProvider listenerProvider
     )
 {
     _listener  = listenerProvider.GetListener(FeatureAttribute.GlobalOperation);
     _singleton = new GlobalOperationNotificationService(_listener);
 }
        private void TrackBulkFileOperations()
        {
            RoslynDebug.AssertNotNull(_workspace);

            // we will pause whatever ambient work loads we have that are tied to IGlobalOperationNotificationService
            // such as solution crawler, pre-emptive remote host synchronization and etc. any background work users didn't
            // explicitly asked for.
            //
            // this should give all resources to BulkFileOperation. we do same for things like build,
            // debugging, wait dialog and etc. BulkFileOperation is used for things like git branch switching and etc.
            IGlobalOperationNotificationService globalNotificationService = _workspace.Services.GetRequiredService <IGlobalOperationNotificationService>();

            // BulkFileOperation can't have nested events. there will be ever only 1 events (Begin/End)
            // so we only need simple tracking.
            object gate = new object();
            GlobalOperationRegistration?localRegistration = null;

            BulkFileOperation.End += (s, a) =>
            {
                StopBulkFileOperationNotification();
            };

            BulkFileOperation.Begin += (s, a) =>
            {
                StartBulkFileOperationNotification();
            };

            void StartBulkFileOperationNotification()
            {
                lock (gate)
                {
                    // this shouldn't happen, but we are using external component
                    // so guarding us from them
                    if (localRegistration != null)
                    {
                        FatalError.ReportWithoutCrash(new InvalidOperationException("BulkFileOperation already exist"));
                        return;
                    }

                    localRegistration = globalNotificationService.Start("BulkFileOperation");
                }
            }

            void StopBulkFileOperationNotification()
            {
                lock (gate)
                {
                    // this can happen if BulkFileOperation was already in the middle
                    // of running. to make things simpler, decide to not use IsInProgress
                    // which we need to worry about race case.
                    if (localRegistration == null)
                    {
                        return;
                    }

                    localRegistration.Dispose();
                    localRegistration = null;
                }
            }
        }
                    public AbstractPriorityProcessor(
                        IAsynchronousOperationListener listener,
                        IncrementalAnalyzerProcessor processor,
                        Lazy <ImmutableArray <IIncrementalAnalyzer> > lazyAnalyzers,
                        IGlobalOperationNotificationService globalOperationNotificationService,
                        int backOffTimeSpanInMs,
                        CancellationToken shutdownToken
                        )
                        : base(
                            listener,
                            globalOperationNotificationService,
                            backOffTimeSpanInMs,
                            shutdownToken
                            )
                    {
                        _gate          = new object();
                        _lazyAnalyzers = lazyAnalyzers;

                        Processor = processor;

                        if (Processor._documentTracker != null)
                        {
                            Processor._documentTracker.NonRoslynBufferTextChanged +=
                                OnNonRoslynBufferTextChanged;
                        }
                    }
Exemple #5
0
                    public NormalPriorityProcessor(
                        IAsynchronousOperationListener listener,
                        IncrementalAnalyzerProcessor processor,
                        Lazy <ImmutableArray <IIncrementalAnalyzer> > lazyAnalyzers,
                        IGlobalOperationNotificationService globalOperationNotificationService,
                        int backOffTimeSpanInMs,
                        CancellationToken shutdownToken
                        )
                        : base(
                            listener,
                            processor,
                            lazyAnalyzers,
                            globalOperationNotificationService,
                            backOffTimeSpanInMs,
                            shutdownToken
                            )
                    {
                        _running       = Task.CompletedTask;
                        _workItemQueue = new AsyncDocumentWorkItemQueue(
                            processor._registration.ProgressReporter,
                            processor._registration.Workspace
                            );
                        _higherPriorityDocumentsNotProcessed = new ConcurrentDictionary <
                            DocumentId,
                            IDisposable?
                            >(concurrencyLevel: 2, capacity: 20);

                        _currentProjectProcessing = null;

                        Start();
                    }
Exemple #6
0
 public GlobalOperationAwareIdleProcessor(
     IAsynchronousOperationListener listener,
     IGlobalOperationNotificationService globalOperationNotificationService,
     TimeSpan backOffTimeSpan,
     CancellationToken shutdownToken)
     : base(listener, backOffTimeSpan, shutdownToken)
 {
     _globalOperationNotificationService          = globalOperationNotificationService;
     _globalOperationNotificationService.Started += OnGlobalOperationStarted;
     _globalOperationNotificationService.Stopped += OnGlobalOperationStopped;
 }
                    public LowPriorityProcessor(
                        IAsynchronousOperationListener listener,
                        IncrementalAnalyzerProcessor processor,
                        Lazy<ImmutableArray<IIncrementalAnalyzer>> lazyAnalyzers,
                        IGlobalOperationNotificationService globalOperationNotificationService,
                        int backOffTimeSpanInMs,
                        CancellationToken shutdownToken) :
                        base(listener, processor, lazyAnalyzers, globalOperationNotificationService, backOffTimeSpanInMs, shutdownToken)
                    {
                        _workItemQueue = new AsyncProjectWorkItemQueue(processor._registration.ProgressReporter, processor._registration.Workspace);

                        Start();
                    }
                    public LowPriorityProcessor(
                        IAsynchronousOperationListener listener,
                        IncrementalAnalyzerProcessor processor,
                        Lazy <ImmutableArray <IIncrementalAnalyzer> > lazyAnalyzers,
                        IGlobalOperationNotificationService globalOperationNotificationService,
                        TimeSpan backOffTimeSpan,
                        CancellationToken shutdownToken)
                        : base(listener, processor, lazyAnalyzers, globalOperationNotificationService, backOffTimeSpan, shutdownToken)
                    {
                        _workItemQueue = new AsyncProjectWorkItemQueue(processor._registration.ProgressReporter, processor._registration.Workspace);

                        Start();
                    }
        public GlobalOperationAwareIdleProcessor(
            IAsynchronousOperationListener listener,
            IGlobalOperationNotificationService globalOperationNotificationService,
            int backOffTimeSpanInMs,
            CancellationToken shutdownToken) :
            base(listener, backOffTimeSpanInMs, shutdownToken)
        {
            _globalOperation = null;
            _globalOperationTask = SpecializedTasks.EmptyTask;

            _globalOperationNotificationService = globalOperationNotificationService;
            _globalOperationNotificationService.Started += OnGlobalOperationStarted;
            _globalOperationNotificationService.Stopped += OnGlobalOperationStopped;
        }
        public GlobalOperationAwareIdleProcessor(
            IAsynchronousOperationListener listener,
            IGlobalOperationNotificationService globalOperationNotificationService,
            int backOffTimeSpanInMs,
            CancellationToken shutdownToken) :
            base(listener, backOffTimeSpanInMs, shutdownToken)
        {
            _globalOperation     = null;
            _globalOperationTask = SpecializedTasks.EmptyTask;

            _globalOperationNotificationService          = globalOperationNotificationService;
            _globalOperationNotificationService.Started += OnGlobalOperationStarted;
            _globalOperationNotificationService.Stopped += OnGlobalOperationStopped;
        }
Exemple #11
0
                    public LowPriorityProcessor(
                        IAsynchronousOperationListener listener,
                        IncrementalAnalyzerProcessor processor,
                        Lazy <ImmutableArray <IIncrementalAnalyzer> > lazyAnalyzers,
                        IGlobalOperationNotificationService globalOperationNotificationService,
                        int backOffTimeSpanInMs,
                        CancellationToken shutdownToken) :
                        base(listener, processor, globalOperationNotificationService, backOffTimeSpanInMs, shutdownToken)
                    {
                        _lazyAnalyzers = lazyAnalyzers;
                        _workItemQueue = new AsyncProjectWorkItemQueue();

                        Start();
                    }
Exemple #12
0
        public VisualStudioWaitContext(
            IGlobalOperationNotificationService notificationService,
            IVsThreadedWaitDialogFactory dialogFactory,
            string title,
            string message,
            bool allowCancel)
        {
            _title                   = title;
            _message                 = message;
            _allowCancel             = allowCancel;
            _cancellationTokenSource = new CancellationTokenSource();

            _dialog       = CreateDialog(dialogFactory);
            _registration = notificationService.Start(title);
        }
                    public AbstractPriorityProcessor(
                        IAsynchronousOperationListener listener,
                        IncrementalAnalyzerProcessor processor,
                        IGlobalOperationNotificationService globalOperationNotificationService,
                        int backOffTimeSpanInMs,
                        CancellationToken shutdownToken) :
                        base(listener, globalOperationNotificationService, backOffTimeSpanInMs, shutdownToken)
                    {
                        this.Processor = processor;

                        if (this.Processor._documentTracker != null)
                        {
                            this.Processor._documentTracker.NonRoslynBufferTextChanged += OnNonRoslynBufferTextChanged;
                        }
                    }
                    public AbstractPriorityProcessor(
                        IAsynchronousOperationListener listener,
                        IncrementalAnalyzerProcessor processor,
                        IGlobalOperationNotificationService globalOperationNotificationService,
                        int backOffTimeSpanInMs,
                        CancellationToken shutdownToken) :
                        base(listener, globalOperationNotificationService, backOffTimeSpanInMs, shutdownToken)
                    {
                        this.Processor = processor;

                        if (this.Processor._documentTracker != null)
                        {
                            this.Processor._documentTracker.NonRoslynBufferTextChanged += OnNonRoslynBufferTextChanged;
                        }
                    }
Exemple #15
0
        /// <summary>
        /// internal for testing
        /// </summary>
        internal ExternalErrorDiagnosticUpdateSource(
            Workspace workspace,
            IDiagnosticAnalyzerService diagnosticService,
            IAsynchronousOperationListener listener)
        {
            // use queue to serialize work. no lock needed
            _taskQueue = new TaskQueue(listener, TaskScheduler.Default);

            _workspace = workspace;
            _workspace.WorkspaceChanged += OnWorkspaceChanged;

            _diagnosticService = diagnosticService;

            _notificationService = _workspace.Services.GetService <IGlobalOperationNotificationService>();
        }
        public VisualStudioWaitContext(
            IGlobalOperationNotificationService notificationService,
            IVsThreadedWaitDialogFactory dialogFactory,
            string title,
            string message,
            bool allowCancel)
        {
            _title = title;
            _message = message;
            _allowCancel = allowCancel;
            _cancellationTokenSource = new CancellationTokenSource();

            _dialog = CreateDialog(dialogFactory);
            _registration = notificationService.Start(title);
        }
Exemple #17
0
        public void Dispose()
        {
            foreach (var globalOperation in _operations.Values)
            {
                globalOperation.Dispose();
            }

            _operations.Clear();

            if (_notificationService != null)
            {
                _notificationService = null;
                KnownUIContexts.SolutionBuildingContext.UIContextChanged -= SolutionBuildingContextChanged;
                KnownUIContexts.SolutionOpeningContext.UIContextChanged  -= SolutionOpeningContextChanged;
            }
        }
        public VisualStudioWaitContext(
            IGlobalOperationNotificationService notificationService,
            IVsThreadedWaitDialogFactory dialogFactory,
            string title,
            string message,
            bool allowCancel, 
            bool showProgress)
        {
            _title = title;
            _message = message;
            _allowCancel = allowCancel;
            _cancellationTokenSource = new CancellationTokenSource();

            this.ProgressTracker = showProgress
                ? new ProgressTracker((_1, _2) => UpdateDialog())
                : new ProgressTracker();

            _dialog = CreateDialog(dialogFactory, showProgress);
            _registration = notificationService.Start(title);
        }
        public VisualStudioWaitContext(
            IGlobalOperationNotificationService notificationService,
            IVsThreadedWaitDialogFactory dialogFactory,
            string title,
            string message,
            bool allowCancel,
            bool showProgress)
        {
            _title                   = title;
            _message                 = message;
            _allowCancel             = allowCancel;
            _cancellationTokenSource = new CancellationTokenSource();

            this.ProgressTracker = showProgress
                ? new ProgressTracker((_1, _2, _3) => UpdateDialog())
                : new ProgressTracker();

            _dialog       = CreateDialog(dialogFactory, showProgress);
            _registration = notificationService.Start(title);
        }
                    public NormalPriorityProcessor(
                        IAsynchronousOperationListener listener,
                        IncrementalAnalyzerProcessor processor,
                        Lazy <ImmutableArray <IIncrementalAnalyzer> > lazyAnalyzers,
                        IGlobalOperationNotificationService globalOperationNotificationService,
                        int backOffTimeSpanInMs,
                        CancellationToken shutdownToken) :
                        base(listener, processor, lazyAnalyzers, globalOperationNotificationService, backOffTimeSpanInMs, shutdownToken)
                    {
                        _running       = SpecializedTasks.EmptyTask;
                        _workItemQueue = new AsyncDocumentWorkItemQueue(processor._registration.ProgressReporter, processor._registration.Workspace);
                        _higherPriorityDocumentsNotProcessed = new ConcurrentDictionary <DocumentId, IDisposable>(concurrencyLevel: 2, capacity: 20);

                        _currentProjectProcessing = default(ProjectId);
                        _processingSolution       = null;

                        _currentSnapshotVersionTrackingSet = new HashSet <ProjectId>();

                        Start();
                    }
                    public NormalPriorityProcessor(
                        IAsynchronousOperationListener listener,
                        IncrementalAnalyzerProcessor processor,
                        Lazy<ImmutableArray<IIncrementalAnalyzer>> lazyAnalyzers,
                        IGlobalOperationNotificationService globalOperationNotificationService,
                        int backOffTimeSpanInMs,
                        CancellationToken shutdownToken) :
                        base(listener, processor, lazyAnalyzers, globalOperationNotificationService, backOffTimeSpanInMs, shutdownToken)
                    {
                        _running = SpecializedTasks.EmptyTask;
                        _workItemQueue = new AsyncDocumentWorkItemQueue(processor._registration.ProgressReporter, processor._registration.Workspace);
                        _higherPriorityDocumentsNotProcessed = new ConcurrentDictionary<DocumentId, IDisposable>(concurrencyLevel: 2, capacity: 20);

                        _currentProjectProcessing = default(ProjectId);
                        _processingSolution = null;

                        _currentSnapshotVersionTrackingSet = new HashSet<ProjectId>();

                        Start();
                    }
Exemple #22
0
            public PerformanceReporter(
                TraceSource logger,
                TelemetrySession telemetrySession,
                IPerformanceTrackerService diagnosticAnalyzerPerformanceTracker,
                IGlobalOperationNotificationService globalOperationNotificationService,
                CancellationToken shutdownToken)
                : base(
                    AsynchronousOperationListenerProvider.NullListener,
                    globalOperationNotificationService,
                    backOffTimeSpan: TimeSpan.FromMinutes(2),
                    shutdownToken)
            {
                _event    = new SemaphoreSlim(initialCount: 0);
                _reported = new HashSet <string>();

                _logger           = logger;
                _telemetrySession = telemetrySession;
                _diagnosticAnalyzerPerformanceTracker = diagnosticAnalyzerPerformanceTracker;
                _diagnosticAnalyzerPerformanceTracker.SnapshotAdded += OnSnapshotAdded;
                Start();
            }
                    public GlobalOperationAwareIdleProcessor(
                        IAsynchronousOperationListener listener,
                        IncrementalAnalyzerProcessor processor,
                        IGlobalOperationNotificationService globalOperationNotificationService,
                        int backOffTimeSpanInMs,
                        CancellationToken shutdownToken) :
                        base(listener, backOffTimeSpanInMs, shutdownToken)
                    {
                        this.Processor = processor;

                        _globalOperation     = null;
                        _globalOperationTask = SpecializedTasks.EmptyTask;

                        _globalOperationNotificationService          = globalOperationNotificationService;
                        _globalOperationNotificationService.Started += OnGlobalOperationStarted;
                        _globalOperationNotificationService.Stopped += OnGlobalOperationStopped;

                        if (this.Processor._documentTracker != null)
                        {
                            this.Processor._documentTracker.NonRoslynBufferTextChanged += OnNonRoslynBufferTextChanged;
                        }
                    }
                    public GlobalOperationAwareIdleProcessor(
                        IAsynchronousOperationListener listener,
                        IncrementalAnalyzerProcessor processor,
                        IGlobalOperationNotificationService globalOperationNotificationService,
                        int backOffTimeSpanInMs,
                        CancellationToken shutdownToken) :
                        base(listener, backOffTimeSpanInMs, shutdownToken)
                    {
                        this.Processor = processor;

                        _globalOperation = null;
                        _globalOperationTask = SpecializedTasks.EmptyTask;

                        _globalOperationNotificationService = globalOperationNotificationService;
                        _globalOperationNotificationService.Started += OnGlobalOperationStarted;
                        _globalOperationNotificationService.Stopped += OnGlobalOperationStopped;

                        if (this.Processor._documentTracker != null)
                        {
                            this.Processor._documentTracker.NonRoslynBufferTextChanged += OnNonRoslynBufferTextChanged;
                        }
                    }
            public PerformanceReporter(TraceSource logger, IPerformanceTrackerService diagnosticAnalyzerPerformanceTracker, IGlobalOperationNotificationService globalOperationNotificationService, TimeSpan reportingInterval, CancellationToken shutdownToken)
                : base(
                    AsynchronousOperationListenerProvider.NullListener,
                    globalOperationNotificationService,
                    (int)reportingInterval.TotalMilliseconds,
                    shutdownToken)
            {
                _event    = new SemaphoreSlim(initialCount: 0);
                _reported = new HashSet <string>();

                _logger = logger;
                _diagnosticAnalyzerPerformanceTracker = diagnosticAnalyzerPerformanceTracker;
                _diagnosticAnalyzerPerformanceTracker.SnapshotAdded += OnSnapshotAdded;
                Start();
            }
Exemple #26
0
            //private readonly GlobalOperationRegistration registration;

            public WaitContext(IGlobalOperationNotificationService service, string title, string message, bool allowCancel)
            {
                //this.registration = service.Start (title);
            }