Esempio n. 1
0
 public StreamingFindReferencesProgress(SearchProgressMonitor monitor, MonoDevelopWorkspace workspace)
 {
     this.monitor   = monitor;
     this.workspace = workspace;
 }
Esempio n. 2
0
        internal static Task FindRefs(SymbolAndProjectId[] symbolAndProjectIds, Solution solution, SearchProgressMonitor monitor = null)
        {
            bool owningMonitor = false;

            if (monitor == null)
            {
                monitor       = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor(true, true);
                owningMonitor = true;
            }
            var workspace = IdeApp.TypeSystemService.Workspace as MonoDevelopWorkspace;

            if (workspace == null)
            {
                return(Task.CompletedTask);
            }
            return(Task.Run(async delegate {
                ITimeTracker timer = null;
                var metadata = MonoDevelop.Refactoring.Counters.CreateFindReferencesMetadata();

                try {
                    timer = MonoDevelop.Refactoring.Counters.FindReferences.BeginTiming(metadata);
                    monitor.BeginTask(GettextCatalog.GetString("Searching..."), 100);

                    var streamingProgresses = new StreamingFindReferencesProgress [symbolAndProjectIds.Length];
                    var tasks = new Task [symbolAndProjectIds.Length];
                    int reportedProgress = 0;
                    for (int i = 0; i < symbolAndProjectIds.Length; i++)
                    {
                        var reportingProgress = new StreamingFindReferencesProgress(monitor, workspace);
                        reportingProgress.ProgressUpdated = delegate {
                            double sumOfProgress = 0;
                            for (int j = 0; j < streamingProgresses.Length; j++)
                            {
                                sumOfProgress += streamingProgresses [j].Progress;
                            }
                            int newProgress = (int)((sumOfProgress / streamingProgresses.Length) * 100);
                            if (newProgress > reportedProgress)
                            {
                                lock (streamingProgresses) {
                                    if (newProgress > reportedProgress)
                                    {
                                        monitor.Step(newProgress - reportedProgress);
                                        reportedProgress = newProgress;
                                    }
                                }
                            }
                        };
                        streamingProgresses [i] = reportingProgress;
                    }
                    for (int i = 0; i < tasks.Length; i++)
                    {
                        tasks [i] = SymbolFinder.FindReferencesAsync(
                            symbolAndProjectIds [i],
                            solution,
                            streamingProgresses [i],
                            null,
                            FindReferencesSearchOptions.GetFeatureOptionsForStartingSymbol(symbolAndProjectIds [i].Symbol),
                            monitor.CancellationToken
                            );
                    }
                    await Task.WhenAll(tasks);
                } catch (OperationCanceledException) {
                } catch (Exception ex) {
                    metadata.SetFailure();
                    if (monitor != null)
                    {
                        monitor.ReportError("Error finding references", ex);
                    }
                    else
                    {
                        LoggingService.LogError("Error finding references", ex);
                    }
                } finally {
                    if (owningMonitor)
                    {
                        monitor.Dispose();
                    }
                    if (monitor.CancellationToken.IsCancellationRequested)
                    {
                        metadata.SetUserCancel();
                    }
                    if (timer != null)
                    {
                        timer.Dispose();
                    }
                }
            }));
        }