Example #1
0
        private ThreadedWaitDialogHelper.Session StartWaitDialog(string waitMessage, int delayToShowDialogMs)
        {
            var dialogFactory   = _shell.GlobalServices.GetService <IVsThreadedWaitDialogFactory>(typeof(SVsThreadedWaitDialogFactory));
            var initialProgress = new ThreadedWaitDialogProgressData(waitMessage, isCancelable: true);

            return(dialogFactory.StartWaitDialog(null, initialProgress, TimeSpan.FromMilliseconds(delayToShowDialogMs)));
        }
        /// <summary>
        /// This event could be raised from multiple threads. Only perform thread-safe operations
        /// </summary>
        private void PackageRestoreManager_PackageRestored(object sender, PackageRestoredEventArgs args)
        {
            if (Token.IsCancellationRequested)
            {
                _canceled = true;
                return;
            }

            if (args.Restored)
            {
                var packageIdentity = args.Package;
                Interlocked.Increment(ref CurrentCount);

                ThreadHelper.JoinableTaskFactory.RunAsync(async delegate
                {
                    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                    var progressData = new ThreadedWaitDialogProgressData(string.Format(CultureInfo.CurrentCulture,
                                                                                        Resources.RestoredPackage,
                                                                                        packageIdentity),
                                                                          string.Empty,
                                                                          string.Empty,
                                                                          isCancelable: true,
                                                                          currentStep: CurrentCount,
                                                                          totalSteps: TotalCount);
                    ThreadedWaitDialogProgress.Report(progressData);
                });
            }
        }
        private void LogToVS(VerbosityLevel verbosityLevel, string message)
        {
            if (Token.IsCancellationRequested)
            {
                // If an operation is canceled, don't log anything, simply return
                // And, show a single message gets shown in the summary that package restore has been canceled
                // Do not report it as separate errors
                _canceled = true;
                return;
            }

            // If the verbosity level of message is worse than VerbosityLevel.Normal, that is,
            // VerbosityLevel.Detailed or VerbosityLevel.Diagnostic, AND,
            // _msBuildOutputVerbosity is lesser than verbosityLevel; do nothing
            if (verbosityLevel > VerbosityLevel.Normal && _msBuildOutputVerbosity < (int)verbosityLevel)
            {
                return;
            }

            ThreadHelper.JoinableTaskFactory.Run(async delegate
            {
                // Switch to main thread to update the progress dialog, output window or error list window
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                // Only show messages with VerbosityLevel.Normal. That is, info messages only.
                // Do not show errors, warnings, verbose or debug messages on the progress dialog
                // Avoid showing indented messages, these are typically not useful for the progress dialog since
                // they are missing the context of the parent text above it
                if (verbosityLevel == VerbosityLevel.Normal && message.Length == message.TrimStart().Length)
                {
                    // When both currentStep and totalSteps are 0, we get a marquee on the dialog
                    var progressData = new ThreadedWaitDialogProgressData(message,
                                                                          string.Empty,
                                                                          string.Empty,
                                                                          isCancelable: true,
                                                                          currentStep: 0,
                                                                          totalSteps: 0);

                    // Update the progress dialog
                    ThreadedWaitDialogProgress.Report(progressData);
                }

                // Write to the output window. Based on _msBuildOutputVerbosity, the message may or may not
                // get shown on the output window. Default is VerbosityLevel.Minimal
                WriteLine(verbosityLevel, message);

                // VerbosityLevel.Quiet corresponds to ILogger.LogError, and,
                // VerbosityLevel.Minimal corresponds to ILogger.LogWarning
                // In these 2 cases, we add an error or warning to the error list window
                if (verbosityLevel == VerbosityLevel.Quiet || verbosityLevel == VerbosityLevel.Minimal)
                {
                    MessageHelper.ShowError(_errorListProvider,
                                            verbosityLevel == VerbosityLevel.Quiet ? TaskErrorCategory.Error : TaskErrorCategory.Warning,
                                            TaskPriority.High,
                                            message,
                                            hierarchyItem: null);
                }
            });
        }
Example #4
0
    public async Task <IWaitDialog> CreateAsync(string title, ThreadedWaitDialogProgressData progress)
    {
        IVsThreadedWaitDialogFactory waitDialogFactory;


        await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

        waitDialogFactory = (IVsThreadedWaitDialogFactory)await VS.Services.GetThreadedWaitDialogAsync();

        return(new Dialog(waitDialogFactory.StartWaitDialog(title, progress)));
    }
Example #5
0
        public IModalProgressDialogSession StartModalProgressDialog(string caption, ProgressDialogData initialData, INuGetUI uiService)
        {
            var waitForDialogFactory = (IVsThreadedWaitDialogFactory)Package.GetGlobalService(typeof(SVsThreadedWaitDialogFactory));
            var progressData         = new ThreadedWaitDialogProgressData(
                initialData.WaitMessage,
                initialData.ProgressText,
                null,
                initialData.IsCancelable,
                initialData.CurrentStep,
                initialData.TotalSteps);
            var session = waitForDialogFactory.StartWaitDialog(caption, progressData);

            return(new VisualStudioProgressDialogSession(session));
        }
        public State(IWaitDialog waitDialog, ThreadedWaitDialogProgressData initialProgress, IVsSolution4 solution)
        {
            _waitDialog      = waitDialog;
            _currentProgress = initialProgress;
            Solution         = solution;

            _projectsToLoad = new HashSet <Guid>();
            _loadedProjects = new HashSet <Guid>();

            _projectsToUnload = new HashSet <Guid>();
            _unloadedProjects = new HashSet <Guid>();

            ProjectsVisitedWhileLoading          = new HashSet <Guid>();
            RequiresProjectDependencyCalculation = true;
        }
        public async Task <IModalProgressDialogSession> StartModalProgressDialogAsync(string caption, ProgressDialogData initialData, INuGetUI uiService)
        {
            await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var waitForDialogFactory = (IVsThreadedWaitDialogFactory)Package.GetGlobalService(typeof(SVsThreadedWaitDialogFactory));
            var progressData         = new ThreadedWaitDialogProgressData(
                initialData.WaitMessage,
                initialData.ProgressText,
                null,
                initialData.IsCancelable,
                initialData.CurrentStep,
                initialData.TotalSteps);
            var session = waitForDialogFactory.StartWaitDialog(caption, progressData);

            return(new VisualStudioProgressDialogSession(session));
        }
Example #8
0
            public override void ReportProgress(
                string progressMessage,
                uint currentStep,
                uint totalSteps)
            {
                ThreadHelper.ThrowIfNotOnUIThread();

                // When both currentStep and totalSteps are 0, we get a marquee on the dialog
                var progressData = new ThreadedWaitDialogProgressData(
                    progressMessage,
                    progressText: string.Empty,
                    statusBarText: string.Empty,
                    isCancelable: true,
                    currentStep: (int)currentStep,
                    totalSteps: (int)totalSteps);

                _session.Progress.Report(progressData);
            }
            public override async Task ReportProgressAsync(
                string progressMessage,
                uint currentStep,
                uint totalSteps)
            {
                await _taskFactory.SwitchToMainThreadAsync();

                // When both currentStep and totalSteps are 0, we get a marquee on the dialog
                var progressData = new ThreadedWaitDialogProgressData(
                    progressMessage,
                    progressText: string.Empty,
                    statusBarText: string.Empty,
                    isCancelable: true,
                    currentStep: (int)currentStep,
                    totalSteps: (int)totalSteps);

                _session.Progress.Report(progressData);
            }
Example #10
0
 public void Update(ThreadedWaitDialogProgressData data)
 {
     Session.Progress.Report(data);
 }
Example #11
0
 public void ReportProgress(ThreadedWaitDialogProgressData progress)
 {
     _session.Progress.Report(progress);
 }
Example #12
0
        private static ThreadedWaitDialogHelper.Session StartWaitDialog(double delayToShowDialog)
        {
            var initialProgress = new ThreadedWaitDialogProgressData(Resources.DebuggerInProgress, isCancelable: true);

            return(_twdf.Value.StartWaitDialog(null, initialProgress, TimeSpan.FromSeconds(delayToShowDialog)));
        }
 private void Report(ThreadedWaitDialogProgressData progress)
 {
     _waitDialog.ReportProgress(progress);
     _currentProgress = progress;
 }
Example #14
0
 static protected void Report(Session s, string progressText, string statusText = null)
 {
     var value = new ThreadedWaitDialogProgressData(null, progressText, statusText);
     s.Progress.Report(value);
 }
Example #15
0
 static protected Session StartWaitDialog(string waitMessage, string progressText = null, string statusText = null)
 {
     var waitDialogSvc = (IVsThreadedWaitDialogFactory)Package.GetGlobalService(typeof(SVsThreadedWaitDialogFactory));
     var initialProgress = new ThreadedWaitDialogProgressData(waitMessage, progressText, statusText);
     return waitDialogSvc.StartWaitDialog("CodeWeaver", initialProgress);
 }
Example #16
0
    public async Task ApplyAsync(FilterOptions options)
    {
        ThreadedWaitDialogProgressData progress;
        IWaitDialogFactory             waitDialogFactory;


        if (options is null)
        {
            throw new ArgumentNullException(nameof(options));
        }

        await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

        if ((options.ProjectsToLoad.Count == 0) && (options.ProjectsToUnload.Count == 0))
        {
            return;
        }

        waitDialogFactory = await VS.GetRequiredServiceAsync <IWaitDialogFactory, IWaitDialogFactory>();

        progress = new ThreadedWaitDialogProgressData("Filtering projects...", "Getting ready...", "", true);

        using (var dialog = await waitDialogFactory.CreateAsync(Vsix.Name, progress)) {
            IEnumerable <Guid> projectsToUnload;
            IEnumerable <Guid> projectsToLoad;
            State             state;
            ISolutionExplorer solutionExplorer;


            state = new State(
                dialog,
                progress,
                (IVsSolution4)await VS.Services.GetSolutionAsync()
                );

            projectsToUnload = options.ProjectsToUnload.ToList();
            projectsToLoad   = options.ProjectsToLoad.ToList();

            // Work out which projects actually need to be unloaded
            // so that we can calculate an accurate progress. If a
            // project is already unloaded, then we can skip it.
            state.AddProjectsToUnload(projectsToUnload.Where((x) => IsLoaded(state.Solution, x)));

            // Do the same for the projects that we need to load. We may add
            // to this list as we load projects and find their dependencies,
            // but we need to start with a known list so that we can give a
            // reasonable initial estimation for the progress. Start with the
            // projects that we were asked to load that are not already loaded.
            state.AddProjectsToLoad(projectsToLoad.Where((x) => !IsLoaded(state.Solution, x)));

            // If we're loading dependencies, then we can add the unloaded
            // dependencies of the loaded projects that were requested to be loaded.
            if (options.LoadProjectDependencies)
            {
                foreach (var identifier in projectsToLoad.Where((x) => IsLoaded(state.Solution, x)))
                {
                    foreach (var dependency in await GetProjectDependenciesAsync(identifier, state))
                    {
                        if (!IsLoaded(state.Solution, dependency))
                        {
                            state.AddProjectToLoad(dependency);
                        }
                    }
                }
            }

            // Now we can start loading and unloading projects. We're
            // filtering projects because the user wants to keep the number
            // of projects loaded to a minimum, so start by unloading the
            // requested projects before we start loading any new projects.
            foreach (var identifier in projectsToUnload)
            {
                if (state.IsCancellationRequested)
                {
                    break;
                }

                await UnloadProjectAsync(identifier, state);
            }

            foreach (var identifier in projectsToLoad)
            {
                if (state.IsCancellationRequested)
                {
                    break;
                }

                await LoadProjectAsync(identifier, options.LoadProjectDependencies, state);
            }

            // Even if we've been cancelled, we'll still hide the unloaded
            // projects and show the loaded projects. This prevents us from
            // getting into a state where we've loaded some projects but they
            // remain hidden because the user cancelled half way through.
            solutionExplorer = await VS.GetRequiredServiceAsync <ISolutionExplorer, ISolutionExplorer>();

            await solutionExplorer.HideUnloadedProjectsAsync();

            // If a project has been loaded, then the user probably
            // wants to see it, so expand any parent folders.
            await solutionExplorer.ExpandAsync(state.GetLoadedProjects());
        }
    }