Ejemplo n.º 1
0
                    private bool GetNextWorkItem(
                        out WorkItem workItem,
                        out CancellationToken cancellationToken
                        )
                    {
                        // GetNextWorkItem since it can't fail. we still return bool to confirm that this never fail.
                        var documentId = _processor._documentTracker?.TryGetActiveDocument();

                        if (documentId != null)
                        {
                            if (
                                _workItemQueue.TryTake(
                                    documentId,
                                    out workItem,
                                    out cancellationToken
                                    )
                                )
                            {
                                return(true);
                            }
                        }

                        return(_workItemQueue.TryTakeAnyWork(
                                   preferableProjectId: null,
                                   dependencyGraph: _processor.DependencyGraph,
                                   analyzerService: _processor.DiagnosticAnalyzerService,
                                   workItem: out workItem,
                                   cancellationToken: out cancellationToken
                                   ));
                    }
                    private bool GetNextWorkItem(out WorkItem workItem, out CancellationTokenSource documentCancellation)
                    {
                        var documentId = _processor._documentTracker.GetActiveDocument();

                        if (documentId != null)
                        {
                            if (_workItemQueue.TryTake(documentId, out workItem, out documentCancellation))
                            {
                                return(true);
                            }
                        }

                        return(_workItemQueue.TryTakeAnyWork(preferableProjectId: null, workItem: out workItem, source: out documentCancellation));
                    }
Ejemplo n.º 3
0
                    private async Task <bool> TryProcessOneHigherPriorityDocumentAsync()
                    {
                        try
                        {
                            foreach (var documentId in GetPrioritizedPendingDocuments())
                            {
                                if (CancellationToken.IsCancellationRequested)
                                {
                                    return(true);
                                }

                                // this is a best effort algorithm with some shortcomings.
                                //
                                // the most obvious issue is if there is a new work item (without a solution change - but very unlikely)
                                // for a opened document we already processed, the work item will be treated as a regular one rather than higher priority one
                                // (opened document)
                                // see whether we have work item for the document
                                if (
                                    !_workItemQueue.TryTake(
                                        documentId,
                                        out var workItem,
                                        out var documentCancellation
                                        )
                                    )
                                {
                                    RemoveHigherPriorityDocument(documentId);
                                    continue;
                                }

                                // okay now we have work to do
                                await ProcessDocumentAsync(
                                    Analyzers,
                                    workItem,
                                    documentCancellation
                                    )
                                .ConfigureAwait(false);

                                RemoveHigherPriorityDocument(documentId);
                                return(true);
                            }

                            return(false);
                        }
                        catch (Exception e) when(FatalError.ReportAndPropagateUnlessCanceled(e))
                        {
                            throw ExceptionUtilities.Unreachable;
                        }
                    }
Ejemplo n.º 4
0
                    private async Task <bool> TryProcessOneHigherPriorityDocumentAsync()
                    {
                        try
                        {
                            // this is an best effort algorithm with some shortcommings.
                            //
                            // the most obvious issue is if there is a new work item (without a solution change - but very unlikely)
                            // for a opened document we already processed, the work item will be treated as a regular one rather than higher priority one
                            // (opened document)
                            CancellationTokenSource documentCancellation;
                            foreach (var documentId in this.GetPrioritizedPendingDocuments())
                            {
                                if (this.CancellationToken.IsCancellationRequested)
                                {
                                    return(true);
                                }

                                // see whether we have work item for the document
                                WorkItem workItem;
                                if (!_workItemQueue.TryTake(documentId, out workItem, out documentCancellation))
                                {
                                    continue;
                                }

                                // okay now we have work to do
                                await ProcessDocumentAsync(this.Analyzers, workItem, documentCancellation).ConfigureAwait(false);

                                // remove opened document processed
                                IDisposable projectCache;
                                if (_higherPriorityDocumentsNotProcessed.TryRemove(documentId, out projectCache))
                                {
                                    DisposeProjectCache(projectCache);
                                }

                                return(true);
                            }

                            return(false);
                        }
                        catch (Exception e) when(FatalError.ReportUnlessCanceled(e))
                        {
                            throw ExceptionUtilities.Unreachable;
                        }
                    }
Ejemplo n.º 5
0
                    private bool GetNextWorkItem(out WorkItem workItem, out CancellationTokenSource documentCancellation)
                    {
                        // GetNextWorkItem since it can't fail. we still return bool to confirm that this never fail.
                        var documentId = _processor._documentTracker.GetActiveDocument();

                        if (documentId != null)
                        {
                            if (_workItemQueue.TryTake(documentId, out workItem, out documentCancellation))
                            {
                                return(true);
                            }
                        }

                        return(_workItemQueue.TryTakeAnyWork(
                                   preferableProjectId: null,
                                   dependencyGraph: this._processor.DependencyGraph,
                                   workItem: out workItem,
                                   source: out documentCancellation));
                    }