public WorkItem(
     DocumentId documentId, string language, InvocationReasons invocationReasons, bool isLowPriority,
     SyntaxPath activeMember, IAsyncToken asyncToken)
     : this(documentId, documentId.ProjectId, language, invocationReasons, isLowPriority,
            activeMember, ImmutableHashSet.Create<IIncrementalAnalyzer>(),
            false, asyncToken)
 {
 }
        public void RegisterNotification(Func<bool> action, int delay, IAsyncToken asyncToken, CancellationToken cancellationToken = default(CancellationToken))
        {
            Contract.Requires(delay >= 0);

            var current = Environment.TickCount;

            _workQueue.Enqueue(new PendingWork(current + delay, action, asyncToken, cancellationToken));
        }
Exemplo n.º 3
0
        public static Task CompletesAsyncOperation(this Task task, IAsyncToken asyncToken)
        {
            var diagnosticToken = asyncToken as AsynchronousOperationListener.DiagnosticAsyncToken;
            if (diagnosticToken != null)
            {
                diagnosticToken.AssociateWithTask(task);
            }

            return task.CompletesTrackingOperation(asyncToken);
        }
        public void RegisterNotification(Func<bool> action, int delayInMS, IAsyncToken asyncToken, CancellationToken cancellationToken = default(CancellationToken))
        {
            Task task;
            lock (_gate)
            {
                task = _queue.ScheduleTask(() => Execute_NoLock(action, asyncToken, cancellationToken), cancellationToken);
                _tasks.Add(task);
            }

            task.Wait(cancellationToken);
        }
 private void Execute_NoLock(Func<bool> action, IAsyncToken asyncToken, CancellationToken cancellationToken)
 {
     if (action())
     {
         asyncToken.Dispose();
     }
     else
     {
         _tasks.Add(_queue.ScheduleTask(() => Execute_NoLock(action, asyncToken, cancellationToken), cancellationToken));
     }
 }
            protected override async Task ExecuteAsync()
            {
                lock (_gate)
                {
                    _lastToken?.Dispose();
                    _lastToken = null;
                }

                // wait for global operation to finish
                await GlobalOperationTask.ConfigureAwait(false);

                // update primary solution in remote host
                await SynchronizePrimaryWorkspaceAsync(_globalOperationCancellationSource.Token).ConfigureAwait(false);
            }
        public void RegisterNotification(Action action, int delayInMS, IAsyncToken asyncToken, CancellationToken cancellationToken = default(CancellationToken))
        {
            Task task;
            lock (_gate)
            {
                task = _queue.ScheduleTask(() =>
                {
                    action();
                    asyncToken.Dispose();
                }, cancellationToken);

                _tasks.Add(task);
            }

            task.Wait(cancellationToken);
        }
            private void Search(IDisposable navigateToSearch, IAsyncToken asyncToken)
            {
                var searchTasks = _solution.Projects.Select(SearchAsync).ToArray();
                var whenAllTask = Task.WhenAll(searchTasks);

                // NOTE(cyrusn) This SafeContinueWith is *not* cancellable.  We must dispose of the notifier
                // in order for tests to work property.  Also, if we don't notify the callback that we're
                // done then the UI will never stop displaying the progress bar.
                whenAllTask.SafeContinueWith(_ =>
                {
                    _callback.Done();
                    navigateToSearch.Dispose();
                    asyncToken.Dispose();
                },
                CancellationToken.None,
                TaskContinuationOptions.ExecuteSynchronously,
                TaskScheduler.Default);
            }
            protected override async Task ExecuteAsync()
            {
                lock (_gate)
                {
                    _lastToken?.Dispose();
                    _lastToken = null;
                }

                // wait for global operation to finish
                await GlobalOperationTask.ConfigureAwait(false);

                // cancel updating solution checksum if a global operation (such as loading solution, building solution and etc) has started
                await UpdateSolutionChecksumAsync(_globalOperationCancellationSource.Token).ConfigureAwait(false);

                // check whether we had bulk change that require asset synchronization
                if (_synchronize)
                {
                    await SynchronizeAssets().ConfigureAwait(false);
                }
            }
                private WorkItem(
                    DocumentId documentId,
                    ProjectId projectId,
                    string language,
                    InvocationReasons invocationReasons,
                    bool isLowPriority,
                    SyntaxPath activeMember,
                    ImmutableHashSet<IIncrementalAnalyzer> analyzers,
                    bool retry,
                    IAsyncToken asyncToken)
                {
                    this.DocumentId = documentId;
                    this.ProjectId = projectId;
                    this.Language = language;
                    this.InvocationReasons = invocationReasons;
                    this.IsLowPriority = isLowPriority;

                    this.ActiveMember = activeMember;
                    this.Analyzers = analyzers;

                    this.IsRetry = retry;

                    this.AsyncToken = asyncToken;
                }
 private PendingWork(int minimumRunPointInMS, Action action, Func<bool> func, IAsyncToken asyncToken, CancellationToken cancellationToken)
 {
     this.MinimumRunPointInMS = minimumRunPointInMS;
     this.DoWorkAction = action;
     this.DoWorkFunc = func;
     this.AsyncToken = asyncToken;
     this.CancellationToken = cancellationToken;
 }
Exemplo n.º 12
0
 private void EnqueueEvent(Solution solution, DocumentId documentId, InvocationReasons invocationReasons, IAsyncToken asyncToken)
 {
     _eventProcessingQueue.ScheduleTask(
         () => EnqueueWorkItemForDocumentAsync(solution, documentId, invocationReasons), _shutdownToken).CompletesAsyncOperation(asyncToken);
 }
Exemplo n.º 13
0
 private void ProcessSolutionEvent(WorkspaceChangeEventArgs e, IAsyncToken asyncToken)
 {
     switch (e.Kind)
     {
         case WorkspaceChangeKind.SolutionAdded:
             OnSolutionAdded(e.NewSolution);
             EnqueueEvent(e.NewSolution, InvocationReasons.DocumentAdded, asyncToken);
             break;
         case WorkspaceChangeKind.SolutionRemoved:
             EnqueueEvent(e.OldSolution, InvocationReasons.SolutionRemoved, asyncToken);
             break;
         case WorkspaceChangeKind.SolutionCleared:
             EnqueueEvent(e.OldSolution, InvocationReasons.DocumentRemoved, asyncToken);
             break;
         case WorkspaceChangeKind.SolutionChanged:
         case WorkspaceChangeKind.SolutionReloaded:
             EnqueueEvent(e.OldSolution, e.NewSolution, asyncToken);
             break;
         default:
             throw ExceptionUtilities.Unreachable;
     }
 }
Exemplo n.º 14
0
            private void ProcessEvents(WorkspaceChangeEventArgs args, IAsyncToken asyncToken)
            {
                SolutionCrawlerLogger.LogWorkspaceEvent(_logAggregator, (int)args.Kind);

                // TODO: add telemetry that record how much it takes to process an event (max, min, average and etc)
                switch (args.Kind)
                {
                    case WorkspaceChangeKind.SolutionAdded:
                    case WorkspaceChangeKind.SolutionChanged:
                    case WorkspaceChangeKind.SolutionReloaded:
                    case WorkspaceChangeKind.SolutionRemoved:
                    case WorkspaceChangeKind.SolutionCleared:
                        ProcessSolutionEvent(args, asyncToken);
                        break;
                    case WorkspaceChangeKind.ProjectAdded:
                    case WorkspaceChangeKind.ProjectChanged:
                    case WorkspaceChangeKind.ProjectReloaded:
                    case WorkspaceChangeKind.ProjectRemoved:
                        ProcessProjectEvent(args, asyncToken);
                        break;
                    case WorkspaceChangeKind.DocumentAdded:
                    case WorkspaceChangeKind.DocumentReloaded:
                    case WorkspaceChangeKind.DocumentChanged:
                    case WorkspaceChangeKind.DocumentRemoved:
                    case WorkspaceChangeKind.AdditionalDocumentAdded:
                    case WorkspaceChangeKind.AdditionalDocumentRemoved:
                    case WorkspaceChangeKind.AdditionalDocumentChanged:
                    case WorkspaceChangeKind.AdditionalDocumentReloaded:
                        ProcessDocumentEvent(args, asyncToken);
                        break;
                    default:
                        throw ExceptionUtilities.Unreachable;
                }
            }
 public WorkItem(
     DocumentId documentId, string language, InvocationReasons invocationReasons, bool isLowPriority,
     IIncrementalAnalyzer analyzer, IAsyncToken asyncToken)
     : this(documentId, documentId.ProjectId, language, invocationReasons, isLowPriority,
            null, analyzer == null ? ImmutableHashSet.Create<IIncrementalAnalyzer>() : ImmutableHashSet.Create<IIncrementalAnalyzer>(analyzer),
            false, asyncToken)
 {
 }
 public Data(ProjectId projectId, bool needDependencyTracking, IAsyncToken asyncToken)
 {
     this.AsyncToken             = asyncToken;
     this.ProjectId              = projectId;
     this.NeedDependencyTracking = needDependencyTracking;
 }
Exemplo n.º 17
0
 public void RegisterNotification(Func <bool> action, IAsyncToken asyncToken, CancellationToken cancellationToken = default)
 {
     RegisterNotification(action, DefaultTimeSliceInMS, asyncToken, cancellationToken);
 }
Exemplo n.º 18
0
 public PendingWork(int minimumRunPointInMS, Func <bool> work, IAsyncToken asyncToken, CancellationToken cancellationToken)
     : this(minimumRunPointInMS, null, work, asyncToken, cancellationToken)
 {
 }
Exemplo n.º 19
0
 public PendingWork(int minimumRunPointInMS, Action work, IAsyncToken asyncToken, CancellationToken cancellationToken)
     : this(minimumRunPointInMS, work, null, asyncToken, cancellationToken)
 {
 }
Exemplo n.º 20
0
 private PendingWork(int minimumRunPointInMS, Action action, Func <bool> func, IAsyncToken asyncToken, CancellationToken cancellationToken)
 {
     this.MinimumRunPointInMS = minimumRunPointInMS;
     this.DoWorkAction        = action;
     this.DoWorkFunc          = func;
     this.AsyncToken          = asyncToken;
     this.CancellationToken   = cancellationToken;
 }
Exemplo n.º 21
0
 private void EnqueueEvent(Solution oldSolution, Solution newSolution, DocumentId documentId, IAsyncToken asyncToken)
 {
     // document changed event is the special one.
     _eventProcessingQueue.ScheduleTask(
         () => EnqueueWorkItemAfterDiffAsync(oldSolution, newSolution, documentId), _shutdownToken).CompletesAsyncOperation(asyncToken);
 }
Exemplo n.º 22
0
 private void EnqueueEvent(Solution solution, DocumentId documentId, InvocationReasons invocationReasons, IAsyncToken asyncToken)
 {
     _eventProcessingQueue.ScheduleTask(
         () => EnqueueWorkItemForDocumentAsync(solution, documentId, invocationReasons), _shutdownToken).CompletesAsyncOperation(asyncToken);
 }
Exemplo n.º 23
0
 private void EnqueueEvent(Solution oldSolution, Solution newSolution, ProjectId projectId, IAsyncToken asyncToken)
 {
     _eventProcessingQueue.ScheduleTask(
         () => EnqueueWorkItemAfterDiffAsync(oldSolution, newSolution, projectId), _shutdownToken).CompletesAsyncOperation(asyncToken);
 }
 public PendingWork(int minimumRunPointInMS, Func<bool> work, IAsyncToken asyncToken, CancellationToken cancellationToken)
     : this(minimumRunPointInMS, null, work, asyncToken, cancellationToken)
 {
 }
Exemplo n.º 25
0
 public WorkItem(DocumentId documentId, string language, InvocationReasons invocationReasons, bool isLowPriority, IAsyncToken asyncToken)
     : this(documentId, documentId.ProjectId, language, invocationReasons, isLowPriority, null, ImmutableHashSet.Create <IIncrementalAnalyzer>(), false, asyncToken)
 {
 }
 public Data(ProjectId projectId, bool needDependencyTracking, IAsyncToken asyncToken)
 {
     AsyncToken             = asyncToken;
     ProjectId              = projectId;
     NeedDependencyTracking = needDependencyTracking;
 }
 public WorkItem With(DocumentId documentId, ProjectId projectId, IAsyncToken asyncToken)
 {
     // create new work item
     return new WorkItem(
         documentId,
         projectId,
         this.Language,
         this.InvocationReasons,
         this.IsLowPriority,
         this.ActiveMember,
         this.Analyzers,
         this.IsRetry,
         asyncToken);
 }
 public Data(Document document, SyntaxPath changedMember, IAsyncToken asyncToken)
 {
     AsyncToken    = asyncToken;
     Document      = document;
     ChangedMember = changedMember;
 }
Exemplo n.º 29
0
 public void RegisterNotification(Action action, IAsyncToken asyncToken, CancellationToken cancellationToken = default)
 => RegisterNotification(action, DefaultTimeSliceInMS, asyncToken, cancellationToken);
Exemplo n.º 30
0
 public void RegisterNotification(Action action, IAsyncToken asyncToken, CancellationToken cancellationToken = default(CancellationToken))
 {
     RegisterNotification(action, 0, asyncToken, cancellationToken);
 }
Exemplo n.º 31
0
 private void EnqueueEvent(Solution solution, InvocationReasons invocationReasons, IAsyncToken asyncToken)
 {
     var task = _eventProcessingQueue.ScheduleTask(
         () => EnqueueWorkItemForSolution(solution, invocationReasons), _shutdownToken).CompletesAsyncOperation(asyncToken);
 }
 public void RegisterNotification(Action action, IAsyncToken asyncToken, CancellationToken cancellationToken = default(CancellationToken))
 {
     RegisterNotification(action, 0, asyncToken, cancellationToken);
 }
Exemplo n.º 33
0
            private void ProcessDocumentEvent(WorkspaceChangeEventArgs e, IAsyncToken asyncToken)
            {
                switch (e.Kind)
                {
                    case WorkspaceChangeKind.DocumentAdded:
                        EnqueueEvent(e.NewSolution, e.DocumentId, InvocationReasons.DocumentAdded, asyncToken);
                        break;
                    case WorkspaceChangeKind.DocumentRemoved:
                        EnqueueEvent(e.OldSolution, e.DocumentId, InvocationReasons.DocumentRemoved, asyncToken);
                        break;
                    case WorkspaceChangeKind.DocumentReloaded:
                    case WorkspaceChangeKind.DocumentChanged:
                        EnqueueEvent(e.OldSolution, e.NewSolution, e.DocumentId, asyncToken);
                        break;

                    case WorkspaceChangeKind.AdditionalDocumentAdded:
                    case WorkspaceChangeKind.AdditionalDocumentRemoved:
                    case WorkspaceChangeKind.AdditionalDocumentChanged:
                    case WorkspaceChangeKind.AdditionalDocumentReloaded:
                        // If an additional file has changed we need to reanalyze the entire project.
                        EnqueueEvent(e.NewSolution, e.ProjectId, InvocationReasons.AdditionalDocumentChanged, asyncToken);
                        break;

                    default:
                        throw ExceptionUtilities.Unreachable;
                }
            }
Exemplo n.º 34
0
 public Data(Project project, DocumentId documentId, Document?document, SyntaxPath?changedMember, IAsyncToken asyncToken)
 {
     _documentId   = documentId;
     _document     = document;
     Project       = project;
     ChangedMember = changedMember;
     AsyncToken    = asyncToken;
 }
Exemplo n.º 35
0
 private void EnqueueEvent(Solution oldSolution, Solution newSolution, ProjectId projectId, IAsyncToken asyncToken)
 {
     _eventProcessingQueue.ScheduleTask(
         () => EnqueueWorkItemAfterDiffAsync(oldSolution, newSolution, projectId), _shutdownToken).CompletesAsyncOperation(asyncToken);
 }
Exemplo n.º 36
0
 public WorkItem With(IAsyncToken asyncToken)
 {
     return(new WorkItem(
                this.DocumentId, this.ProjectId, this.Language, this.InvocationReasons, this.IsLowPriority, this.ActiveMember, this.Analyzers,
                retry: false, asyncToken: asyncToken));
 }
Exemplo n.º 37
0
 private void EnqueueEvent(Solution oldSolution, Solution newSolution, DocumentId documentId, IAsyncToken asyncToken)
 {
     // document changed event is the special one.
     _eventProcessingQueue.ScheduleTask(
         () => EnqueueWorkItemAfterDiffAsync(oldSolution, newSolution, documentId), _shutdownToken).CompletesAsyncOperation(asyncToken);
 }
            private void EnqueueChecksumUpdate()
            {
                // event will raised sequencially. no concurrency on this handler
                if (_event.CurrentCount > 0)
                {
                    return;
                }

                lock (_gate)
                {
                    _lastToken = _lastToken ?? Listener.BeginAsyncOperation(nameof(SolutionChecksumUpdater));
                }

                _event.Release();
            }
 public PendingWork(int minimumRunPointInMS, Action work, IAsyncToken asyncToken, CancellationToken cancellationToken)
     : this(minimumRunPointInMS, work, null, asyncToken, cancellationToken)
 {
 }
                public WorkItem With(
                    InvocationReasons invocationReasons, SyntaxPath currentMember,
                    ImmutableHashSet<IIncrementalAnalyzer> analyzers, bool retry, IAsyncToken asyncToken)
                {
                    // dispose old one
                    this.AsyncToken.Dispose();

                    // create new work item
                    return new WorkItem(
                        this.DocumentId, this.ProjectId, this.Language,
                        InvocationReasons.With(invocationReasons),
                        IsLowPriority,
                        this.ActiveMember == currentMember ? currentMember : null,
                        Union(analyzers), this.IsRetry || retry,
                        asyncToken);
                }
 public void RegisterNotification(Func<bool> action, IAsyncToken asyncToken, CancellationToken cancellationToken = default(CancellationToken))
 {
     RegisterNotification(action, DefaultTimeSliceInMS, asyncToken, cancellationToken);
 }
 public WorkItem With(IAsyncToken asyncToken)
 {
     return new WorkItem(
         this.DocumentId, this.ProjectId, this.Language, this.InvocationReasons, this.IsLowPriority, this.ActiveMember, this.Analyzers,
         retry: false, asyncToken: asyncToken);
 }
Exemplo n.º 43
0
 private void EnqueueEvent(Solution solution, InvocationReasons invocationReasons, IAsyncToken asyncToken)
 {
     var task = _eventProcessingQueue.ScheduleTask(
         () => EnqueueWorkItemForSolution(solution, invocationReasons), _shutdownToken).CompletesAsyncOperation(asyncToken);
 }
 public Data(Document document, SyntaxPath changedMember, IAsyncToken asyncToken)
 {
     this.AsyncToken    = asyncToken;
     this.Document      = document;
     this.ChangedMember = changedMember;
 }