Ejemplo n.º 1
0
        static WaitDialog Create()
        {
            if (factory == null)
            {
                factory = VsServiceProvider
                          .GetService <SVsThreadedWaitDialogFactory, IVsThreadedWaitDialogFactory>();
                if (factory == null)
                {
                    return(null);
                }
            }

            IVsThreadedWaitDialog2 vsWaitDialog = null;

            factory.CreateInstance(out vsWaitDialog);
            if (vsWaitDialog == null)
            {
                return(null);
            }

            return(new WaitDialog
            {
                VsWaitDialog = vsWaitDialog,
                Running = true,
            });
        }
Ejemplo n.º 2
0
        private IVsThreadedWaitDialog3 CreateDialog(IVsThreadedWaitDialogFactory dialogFactory)
        {
            IVsThreadedWaitDialog2 dialog2;

            Marshal.ThrowExceptionForHR(dialogFactory.CreateInstance(out dialog2));
            Contract.ThrowIfNull(dialog2);

            var dialog3 = (IVsThreadedWaitDialog3)dialog2;

            var callback = new Callback(this);

            dialog3.StartWaitDialogWithCallback(
                szWaitCaption: _title,
                szWaitMessage: _message,
                szProgressText: null,
                varStatusBmpAnim: null,
                szStatusBarText: null,
                fIsCancelable: _allowCancel,
                iDelayToShowDialog: DelayToShowDialogSecs,
                fShowProgress: false,
                iTotalSteps: 0,
                iCurrentStep: 0,
                pCallback: callback);

            return(dialog3);
        }
Ejemplo n.º 3
0
        static WaitDialog Create()
        {
            if (factory == null)
            {
                factory = (IVsThreadedWaitDialogFactory)Package
                          .GetGlobalService(typeof(SVsThreadedWaitDialogFactory));
                if (factory == null)
                {
                    return(null);
                }
            }

            IVsThreadedWaitDialog2 vsWaitDialog = null;

            factory.CreateInstance(out vsWaitDialog);
            if (vsWaitDialog == null)
            {
                return(null);
            }

            return(new WaitDialog
            {
                VsWaitDialog = vsWaitDialog,
                Running = true,
            });
        }
Ejemplo n.º 4
0
        private IVsThreadedWaitDialog3 CreateDialog(
            IVsThreadedWaitDialogFactory dialogFactory, bool showProgress)
        {
            IVsThreadedWaitDialog2 dialog2;
            Marshal.ThrowExceptionForHR(dialogFactory.CreateInstance(out dialog2));
            Contract.ThrowIfNull(dialog2);

            var dialog3 = (IVsThreadedWaitDialog3)dialog2;

            var callback = new Callback(this);

            dialog3.StartWaitDialogWithCallback(
                szWaitCaption: _title,
                szWaitMessage: _message,
                szProgressText: null,
                varStatusBmpAnim: null,
                szStatusBarText: null,
                fIsCancelable: _allowCancel,
                iDelayToShowDialog: DelayToShowDialogSecs,
                fShowProgress: showProgress,
                iTotalSteps: this.ProgressTracker.TotalItems,
                iCurrentStep: this.ProgressTracker.CompletedItems,
                pCallback: callback);

            return dialog3;
        }
Ejemplo n.º 5
0
        /// <inheritdoc/>
        public override async TPL.Task Execute(Project project)
        {
            if (await this.HasUserAcceptedWarningMessage(Resources.Resources.NugetUpdate_Title, Resources.Resources.NugetUpdate_Text))
            {
                // Creates dialog informing the user to wait for the installation to finish
                IVsThreadedWaitDialogFactory twdFactory = await this.Package.GetServiceAsync(typeof(SVsThreadedWaitDialogFactory)) as IVsThreadedWaitDialogFactory;

                IVsThreadedWaitDialog2 dialog = null;
                twdFactory?.CreateInstance(out dialog);

                string title = Resources.Resources.NugetUpdate_WaitTitle;
                string text  = Resources.Resources.NugetUpdate_WaitText;
                dialog?.StartWaitDialog(title, text, null, null, null, 0, false, true);

                try
                {
                    await this.Successor.Execute(project);
                }
                finally
                {
                    // Closes the wait dialog. If the dialog failed, does nothing
                    dialog?.EndWaitDialog(out int canceled);
                }
            }
        }
        public void Restore(IEnumerable <RestoringProject> projects)
        {
            var projectsList = projects.ToList();
            IVsThreadedWaitDialog2 waitDialog;

            waitDialogFactory.CreateInstance(out waitDialog);
            waitDialog.StartWaitDialog("Paket", "Restoring packages", null, null, null, 0, false, true);

            int i = 0;

            try
            {
                foreach (var project in projectsList)
                {
                    bool canceled;
                    waitDialog.UpdateProgress(string.Format("Restoring packages for {0}", project.ProjectName), null, null, i++, projectsList.Count, false, out canceled);

                    restorer.Restore(new[] { project });
                }
            }
            finally
            {
                waitDialog.EndWaitDialog(out i);
            }
        }
Ejemplo n.º 7
0
        private async Task <bool> DownloadIWYUWithProgressBar(string executablePath, IVsThreadedWaitDialogFactory dialogFactory)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IVsThreadedWaitDialog2 progressDialog;

            dialogFactory.CreateInstance(out progressDialog);
            if (progressDialog == null)
            {
                Output.Instance.WriteLine("Failed to get create wait dialog.");
                return(false);
            }

            progressDialog.StartWaitDialogWithPercentageProgress(
                szWaitCaption: "Include Toolbox - Downloading include-what-you-use",
                szWaitMessage: "", // comes in later.
                szProgressText: null,
                varStatusBmpAnim: null,
                szStatusBarText: "Downloading include-what-you-use",
                fIsCancelable: true,
                iDelayToShowDialog: 0,
                iTotalSteps: 100,
                iCurrentStep: 0);

            var cancellationToken = new System.Threading.CancellationTokenSource();

            try
            {
                await IWYUDownload.DownloadIWYU(executablePath, delegate(string section, string status, float percentage)
                {
                    ThreadHelper.ThrowIfNotOnUIThread();

                    bool canceled;
                    progressDialog.UpdateProgress(
                        szUpdatedWaitMessage: section,
                        szProgressText: status,
                        szStatusBarText: $"Downloading include-what-you-use - {section} - {status}",
                        iCurrentStep: (int)(percentage * 100),
                        iTotalSteps: 100,
                        fDisableCancel: true,
                        pfCanceled: out canceled);
                    if (canceled)
                    {
                        cancellationToken.Cancel();
                    }
                }, cancellationToken.Token);
            }
            catch (Exception e)
            {
                await Output.Instance.ErrorMsg("Failed to download include-what-you-use: {0}", e);

                return(false);
            }
            finally
            {
                progressDialog.EndWaitDialog();
            }

            return(true);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates the threaded wait dialog, see <b>Microsoft.VisualStudio.Shell.Interop.IVsThreadedWaitDialog2</b>
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="progress">The progress.</param>
        /// <param name="statustext">The statustext.</param>
        /// <param name="total">The total.</param>
        /// <returns>"Microsoft.VisualStudio.Shell.Interop.IVsThreadedWaitDialog2" instance</returns>
        static internal IVsThreadedWaitDialog2 CreateThreadedWaitDialog(string message, string progress, string statustext, int total)
        {
            IVsThreadedWaitDialog2 dlg = null;

            ErrorHandler.ThrowOnFailure(dialogFactory.CreateInstance(out dlg));

            ErrorHandler.ThrowOnFailure(
                dlg.StartWaitDialogWithPercentageProgress(AppTitle, message, progress, null, statustext, true, 0, total, 0));

            return(dlg);
        }
Ejemplo n.º 9
0
 public void CreateDialogInstance(out IVsThreadedWaitDialog2 dialog,
                                  string caption, string message, string progressText, string statusBarText)
 {
     dialog = null;
     _dialogFactory?.CreateInstance(out dialog);
     dialog?.StartWaitDialog(
         caption,
         message,
         progressText,
         null,
         statusBarText,
         0, false, true);
 }
Ejemplo n.º 10
0
        private void UpdateSlowCheetah(Project project)
        {
            // This is done on the UI thread because changes are made to the project file,
            // causing it to be reloaded. To avoid conflicts with NuGet installation,
            // the update is done sequentially
            if (this.HasUserAcceptedWarningMessage(Resources.Resources.NugetUpdate_Title, Resources.Resources.NugetUpdate_Text))
            {
                // Creates dialog informing the user to wait for the installation to finish
                IVsThreadedWaitDialogFactory twdFactory = this.package.GetService(typeof(SVsThreadedWaitDialogFactory)) as IVsThreadedWaitDialogFactory;
                IVsThreadedWaitDialog2       dialog     = null;
                twdFactory?.CreateInstance(out dialog);

                string title = Resources.Resources.NugetUpdate_WaitTitle;
                string text  = Resources.Resources.NugetUpdate_WaitText;
                dialog?.StartWaitDialog(title, text, null, null, null, 0, false, true);
                try
                {
                    // Installs the latest version of the SlowCheetah NuGet package
                    var componentModel = (IComponentModel)this.package.GetService(typeof(SComponentModel));
                    if (this.IsSlowCheetahInstalled(project))
                    {
                        IVsPackageUninstaller packageUninstaller = componentModel.GetService <IVsPackageUninstaller>();
                        packageUninstaller.UninstallPackage(project, PackageName, true);
                    }

                    IVsPackageInstaller2 packageInstaller = componentModel.GetService <IVsPackageInstaller2>();
                    packageInstaller.InstallLatestPackage(null, project, PackageName, false, false);

                    project.Save();
                    ProjectRootElement projectRoot = ProjectRootElement.Open(project.FullName);
                    foreach (ProjectPropertyGroupElement propertyGroup in projectRoot.PropertyGroups.Where(pg => pg.Label.Equals("SlowCheetah")))
                    {
                        projectRoot.RemoveChild(propertyGroup);
                    }

                    foreach (ProjectImportElement import in projectRoot.Imports.Where(i => i.Label == "SlowCheetah" || i.Project == "$(SlowCheetahTargets)"))
                    {
                        projectRoot.RemoveChild(import);
                    }

                    projectRoot.Save();
                }
                finally
                {
                    // Closes the wait dialog. If the dialog failed, does nothing
                    int canceled;
                    dialog?.EndWaitDialog(out canceled);
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates the threaded wait dialog, see <b>Microsoft.VisualStudio.Shell.Interop.IVsThreadedWaitDialog2</b>
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="progress">The progress.</param>
        /// <param name="statustext">The statustext.</param>
        /// <param name="total">The total.</param>
        /// <returns>"Microsoft.VisualStudio.Shell.Interop.IVsThreadedWaitDialog2" instance</returns>
        static internal IVsThreadedWaitDialog2 CreateThreadedWaitDialog(string message, string progress, string statustext, int total)
        {
            //dlg = Utilities.CreateThreadedWaitDialog("Collecting information about changesets", "Starting to process changests...", "status", 100);
            //dlg.UpdateProgress("Collecting information about changesets", "Starting to process changesets...", "status", 0, 100, true, out bcanceled);
            //dlg.EndWaitDialog(out icanceled);

            IVsThreadedWaitDialog2 dlg = null;

            ErrorHandler.ThrowOnFailure(dialogFactory.CreateInstance(out dlg));

            ErrorHandler.ThrowOnFailure(
                dlg.StartWaitDialogWithPercentageProgress(AppTitle, message, progress, null, statustext, true, 0, total, 0));

            return(dlg);
        }
Ejemplo n.º 12
0
        public CLIExecutor(Process executable, WaitDialogDescription dialogDesc, ProcessDataReceiverDelegate OnProcessUpdated, ProcessTerminatorDelegate OnProcessCanceled, ProcessTerminatorDelegate OnProcessExited)
        {
            this.executable        = executable;
            this.dialogDesc        = dialogDesc;
            this.OnProcessExited   = OnProcessExited;
            this.OnProcessUpdated  = OnProcessUpdated;
            this.OnProcessCanceled = OnProcessCanceled;

            IVsThreadedWaitDialogFactory dlgFactory = Package.GetGlobalService(typeof(SVsThreadedWaitDialogFactory)) as IVsThreadedWaitDialogFactory;

            if (dlgFactory != null)
            {
                dlgFactory.CreateInstance(out waitDialog);
            }
        }
Ejemplo n.º 13
0
            public ThreadedWaitWrapper(IVsThreadedWaitDialogFactory factory, string caption, string message)
            {
                if (factory == null)
                {
                    return;
                }

                if (!VSErr.Succeeded(factory.CreateInstance(out _dlg2)))
                {
                    _dlg2 = null;
                    return;
                }

                _dlg2.StartWaitDialog(caption, message, null, null, null, 2, false, true);
            }
        public IDisposable ShowProgressDialog(string caption, string message, int startDelay)
        {
            IVsThreadedWaitDialog2       vsThreadedWaitDialog2;
            IVsThreadedWaitDialogFactory service = this._serviceProvider.GetService(typeof(SVsThreadedWaitDialogFactory)) as IVsThreadedWaitDialogFactory;

            Marshal.ThrowExceptionForHR(service.CreateInstance(out vsThreadedWaitDialog2));
            string str = null;
            int    num = vsThreadedWaitDialog2.StartWaitDialog(caption, message, null, null, str, startDelay, false, true);

            Marshal.ThrowExceptionForHR(num);
            Cursor overrideCursor = Mouse.OverrideCursor;

            Mouse.OverrideCursor = Cursors.Wait;
            return(new VsShellDialogService.ProgressDialog(vsThreadedWaitDialog2, overrideCursor));
        }
Ejemplo n.º 15
0
        public static IVsThreadedWaitDialog2 ShowWaitDialog(IVsThreadedWaitDialogFactory dialogFactory)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            IVsThreadedWaitDialog2 dialog = null;

            if (dialogFactory != null)
            {
                dialogFactory.CreateInstance(out dialog);
            }


            if (dialog != null)
            {
                dialog.StartWaitDialog(Messages.PleaseWait, Messages.ExecutingRequestedAction, "", null, "", 0, false, true);
            }
            return(dialog);
        }
Ejemplo n.º 16
0
        public Downloader(string src, string destFolder, WaitDialogDescription dialogDesc, DownloadHandlingDelegate OnDownloadCompleted, DownloadHandlingDelegate OnDownloadCanceled)
        {
            srcUri                   = new Uri(src);
            dest                     = GetLocalPathByUri(destFolder, srcUri);//Path.Combine(destFolder, Path.GetFileName(srcUri.AbsolutePath));
            this.dialogDesc          = dialogDesc;
            this.OnDownloadCompleted = OnDownloadCompleted;
            this.OnDownloadCanceled  = OnDownloadCanceled;

            webClient = new WebClient();

            IVsThreadedWaitDialogFactory dlgFactory = Package.GetGlobalService(typeof(SVsThreadedWaitDialogFactory)) as IVsThreadedWaitDialogFactory;

            if (dlgFactory != null)
            {
                dlgFactory.CreateInstance(out waitDialog);
            }
        }
Ejemplo n.º 17
0
        private async Task OptionalDownloadOrUpdate(IncludeWhatYouUseOptionsPage settings, IVsThreadedWaitDialogFactory dialogFactory)
        {
            // Check existence, offer to download if it's not there.
            bool downloadedNewIwyu = false;

            if (!File.Exists(settings.ExecutablePath))
            {
                if (await Output.Instance.YesNoMsg($"Can't find include-what-you-use in '{settings.ExecutablePath}'. Do you want to download it from '{IWYUDownload.DisplayRepositorURL}'?") != Output.MessageResult.Yes)
                {
                    return;
                }

                downloadedNewIwyu = await DownloadIWYUWithProgressBar(settings.ExecutablePath, dialogFactory);

                if (!downloadedNewIwyu)
                {
                    return;
                }
            }
            else if (settings.AutomaticCheckForUpdates && !checkedForUpdatesThisSession)
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                IVsThreadedWaitDialog2 dialog = null;
                dialogFactory.CreateInstance(out dialog);
                dialog?.StartWaitDialog("Include Toolbox", "Running Include-What-You-Use", null, null, "Checking for Updates for include-what-you-use", 0, false, true);
                bool newVersionAvailable = await IWYUDownload.IsNewerVersionAvailableOnline(settings.ExecutablePath);

                dialog?.EndWaitDialog();

                if (newVersionAvailable)
                {
                    checkedForUpdatesThisSession = true;
                    if (await Output.Instance.YesNoMsg($"There is a new version of include-what-you-use available. Do you want to download it from '{IWYUDownload.DisplayRepositorURL}'?") == Output.MessageResult.Yes)
                    {
                        downloadedNewIwyu = await DownloadIWYUWithProgressBar(settings.ExecutablePath, dialogFactory);
                    }
                }
            }
            if (downloadedNewIwyu)
            {
                settings.AddMappingFiles(IWYUDownload.GetMappingFilesNextToIwyuPath(settings.ExecutablePath));
            }
        }
        /// <summary>
        ///     This function is the callback used to execute the command when the menu item is clicked. See the
        ///     constructor to see how the menu item is associated with this function using OleMenuCommandService
        ///     service and MenuCommand class.
        /// </summary>
        /// <param name="sender"> Event sender. </param>
        /// <param name="e"> Event args. </param>
        private void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var dte = _sdteService as DTE;

            if (dte.SelectedItems.Count <= 0)
            {
                return;
            }

            var totalCount = _selectedItemCountExecutor.Execute(dte.SelectedItems);

            IVsThreadedWaitDialog2 dialog = null;

            if (totalCount > 1 && _dialogFactory != null)
            {
                //https://www.visualstudiogeeks.com/extensions/visualstudio/using-progress-dialog-in-visual-studio-extensions
                _dialogFactory.CreateInstance(out dialog);
            }

            var cts = new CancellationTokenSource();

            if (dialog == null ||
                dialog.StartWaitDialogWithPercentageProgress("Proto Attributor: Attributing Progress", "", $"0 of {totalCount} Processed",
                                                             null, DIALOG_ACTION, true, 0, totalCount, 0) != VSConstants.S_OK)
            {
                dialog = null;
            }

            try
            {
                _attributeExecutor.Execute(dte.SelectedItems, cts, dialog, totalCount, _textSelectionExecutor,
                                           (content) => _attributeService.ReorderAttributes(content));
            }
            finally
            {
                dialog?.EndWaitDialog(out var usercancel);
            }
        }
Ejemplo n.º 19
0
        public InstallResult InstallTizenPackage(SDBDeviceInfo device, string tpkPath,
                                                 IVsOutputWindowPane outputPane,
                                                 IVsThreadedWaitDialogFactory dlgFactory,
                                                 bool forceInstall,
                                                 out string lastErrorMessage)
        {
            this.outputPane = outputPane;
            this.outputPane?.Activate();

            if (!TargetHasTizenDotNET(device, out lastErrorMessage))
            {
                return(InstallResult.INSTALL_NOT_TRIED);
            }

            if (!NeedToInstall(device, tpkPath, forceInstall))
            {
                lastErrorMessage = string.Format("  Skip install ({0})", tpkPath);
                return(InstallResult.OK);
            }

            dlgFactory?.CreateInstance(out this.waitDialog);//waitDialog can be null and dialog can not be displayed by VS without some reasons.
            this.waitDialog?.StartWaitDialog(
                "Install Tizen Application",
                "Please wait while the new application is being installed...",
                "Preparing...",
                null,
                "Tizen application install in progress...",
                0, false, true);

            int userCancel;

            var           appUninstallCmd = new SDBAppCmd(device, SDBProtocol.uninstall, VsProjectHelper.GetInstance.GetPackageId(tpkPath));
            InstallResult result          = DoInstallTizenPackage(device, tpkPath, out lastErrorMessage);

            this.waitDialog?.EndWaitDialog(out userCancel);

            return(result);
        }
        IVsThreadedWaitDialog3 CreateDialog(IVsThreadedWaitDialogFactory dialogFactory) {
            IVsThreadedWaitDialog2 dialog2;
            Marshal.ThrowExceptionForHR(dialogFactory.CreateInstance(out dialog2));

            var dialog3 = (IVsThreadedWaitDialog3) dialog2;

            var callback = new Callback(this);

            dialog3.StartWaitDialogWithCallback(
                szWaitCaption     : _title,
                szWaitMessage     : _message,
                szProgressText    : null,
                varStatusBmpAnim  : null,
                szStatusBarText   : null,
                fIsCancelable     : _allowCancel,
                iDelayToShowDialog: DelayToShowDialogSecs,
                fShowProgress     : false,
                iTotalSteps       : 0,
                iCurrentStep      : 0,
                pCallback         : callback);

            return dialog3;
        }
        private void DoExport(string fileName)
        {
            IVsThreadedWaitDialog2 dialog;

            dialogFactory.CreateInstance(out dialog);

            dialog.StartWaitDialog(
                Resources.ProgressTitle, Resources.ProgressHeader,
                Resources.LoadingList, null,
                Resources.ProgressTitle,
                0, false,
                true);

            try
            {
                var extensions = this.GetInstalledExtensions()
                                 .Select(ext =>
                {
                    if (dialog != null)
                    {
                        bool canceled;
                        dialog.UpdateProgress(
                            Resources.ProgressHeader,
                            string.Format(Resources.Loading, ext.Name),
                            string.Format(Resources.Loading, ext.Name), 0, 0, false, out canceled);
                    }
                    return(GetExtensionDownloadUrl(ext));
                }).Where(ext => !string.IsNullOrWhiteSpace(ext.DownloadAs));


                using (var writer = File.CreateText(fileName))
                {
                    writer.WriteLine(GetScriptPart("header.template").ReadToEnd());

                    var index = 0;
                    foreach (var extension in extensions)
                    {
                        bool isCancelled;
                        dialog.HasCanceled(out isCancelled);
                        if (isCancelled)
                        {
                            return;
                        }

                        var cmd = string.Format("echo $ext{0} = @{{Name = '{1}';Description ='{2}';Author ='{3}';Identifier ='{4}';DownloadUrl='{5}';DownloadAs='{6}'}}; >> ext.ps1",
                                                index++,
                                                CmdEncode(extension.Name),
                                                CmdEncode(extension.Description),
                                                CmdEncode(extension.Author),
                                                CmdEncode(extension.Identifier),
                                                CmdEncode(extension.DownloadUrl),
                                                CmdEncode(extension.DownloadAs));
                        writer.WriteLine(cmd);
                    }

                    if (index > 0)
                    {
                        var sep = "echo $ext = (";
                        for (int i = 0; i < index; i++)
                        {
                            writer.Write(sep);
                            writer.Write("$ext{0}", i);
                            sep = ",";
                        }
                        writer.WriteLine(");  >> ext.ps1");
                    }

                    var ps   = GetScriptPart("ps.template");
                    var line = ps.ReadLine();
                    while (line != null)
                    {
                        writer.WriteLine("echo " + CmdEncode(line) + " >> ext.ps1");
                        line = ps.ReadLine();
                    }

                    writer.WriteLine(GetScriptPart("footer.template").ReadToEnd());
                }
            }
            finally
            {
                int usercancel;
                dialog.EndWaitDialog(out usercancel);
            }
        }
Ejemplo n.º 22
0
        public void EnableCurrentSolutionForRestore(bool fromActivation)
        {
            if (!_solutionManager.IsSolutionOpen)
            {
                throw new InvalidOperationException(VsResources.SolutionNotAvailable);
            }

            if (fromActivation)
            {
                // if not in quiet mode, ask user for confirmation before proceeding
                bool?result = MessageHelper.ShowQueryMessage(
                    VsResources.PackageRestoreConfirmation,
                    VsResources.DialogTitle,
                    showCancelButton: false);
                if (result != true)
                {
                    return;
                }
            }

            Exception exception = null;

            IVsThreadedWaitDialog2 waitDialog;

            _waitDialogFactory.CreateInstance(out waitDialog);
            try
            {
                waitDialog.StartWaitDialog(
                    VsResources.DialogTitle,
                    VsResources.PackageRestoreWaitMessage,
                    String.Empty,
                    varStatusBmpAnim: null,
                    szStatusBarText: null,
                    iDelayToShowDialog: 0,
                    fIsCancelable: false,
                    fShowMarqueeProgress: true);

                if (fromActivation)
                {
                    // only enable package restore consent if this is called as a result of user enabling package restore
                    SetPackageRestoreConsent();
                }

                EnablePackageRestore(fromActivation);
            }
            catch (Exception ex)
            {
                exception = ex;
                ExceptionHelper.WriteToActivityLog(exception);
            }
            finally
            {
                int canceled;
                waitDialog.EndWaitDialog(out canceled);
            }

            if (fromActivation)
            {
                if (exception != null)
                {
                    // show error message
                    MessageHelper.ShowErrorMessage(
                        VsResources.PackageRestoreErrorMessage +
                        Environment.NewLine +
                        Environment.NewLine +
                        ExceptionUtility.Unwrap(exception).Message,
                        VsResources.DialogTitle);
                }
                else
                {
                    // show success message
                    MessageHelper.ShowInfoMessage(
                        VsResources.PackageRestoreCompleted,
                        VsResources.DialogTitle);
                }
            }
        }
        public static async Task <Report> ProcessAsync(IAsyncServiceProvider serviceProvider, bool addComment)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var report = new Report();

            var dte = (DTE)await serviceProvider.GetServiceAsync(typeof(DTE));

            if (dte == null || string.IsNullOrEmpty(dte.Solution.FullName))
            {
                report.SolutionName = "N/A";
                return(report);
            }

            report.SolutionName = System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetFileName(dte.Solution.FullName));

            IVsStatusbar statusBar = (IVsStatusbar)await serviceProvider.GetServiceAsync(typeof(SVsStatusbar));

            IVsThreadedWaitDialogFactory factory =
                (IVsThreadedWaitDialogFactory)await serviceProvider.GetServiceAsync(
                    typeof(SVsThreadedWaitDialogFactory));

            IVsThreadedWaitDialog2 dialog = null;

            factory?.CreateInstance(out dialog);
            dialog?.StartWaitDialog("PVSStudio Helper", (addComment) ? "Add comment" : "Remove comment", null, null,
                                    null, 0, false, true);

            IVsOutputWindow outWindow =
                (IVsOutputWindow)await serviceProvider.GetServiceAsync(typeof(SVsOutputWindow));

            var generalPaneGuid             = VSConstants.GUID_OutWindowGeneralPane; // P.S. There's also the GUID_OutWindowDebugPane available.
            IVsOutputWindowPane generalPane = null;

            outWindow?.GetPane(ref generalPaneGuid, out generalPane);
            if (generalPane == null)
            {
                outWindow?.CreatePane(ref generalPaneGuid, "General", 1, 0);
                outWindow?.GetPane(ref generalPaneGuid, out generalPane);
            }

            await ProjectProcess.ProcessAsync(dte, report, addComment, async (message) =>
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                dialog?.UpdateProgress(null, message, null, 0, 0, true, out var canceled);
                //messagePump.WaitText = message;
                if (statusBar != null)
                {
                    statusBar.IsFrozen(out var isFrozen);
                    if (isFrozen == 0)
                    {
                        statusBar.SetText(message);
                    }
                }

                generalPane?.OutputString($"{message}{Environment.NewLine}");
            });

            var finalMessage =
                $"The solution {report.SolutionName} processed. Processed items: {report.ProcessedItems}, include opened items {report.ProcessedOpenedItems}";

            if (statusBar != null)
            {
                statusBar.IsFrozen(out var isFrozen);
                if (isFrozen == 0)
                {
                    statusBar.SetText(finalMessage);
                }
            }
            generalPane?.OutputStringThreadSafe($"{finalMessage}{Environment.NewLine}");

            dialog.EndWaitDialog();

            return(report);
        }
        /// <summary>
        /// Tries to create stash staged (if operatiopn wasn't successful - shows Team Explorer notification).
        /// </summary>
        /// <param name="message">message that should be assigned to the Stash.</param>
        /// <returns>True if operation was successful, otherwise - false.</returns>
        public bool TryCreateStashStaged(string message)
        {
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();

            IVsThreadedWaitDialog2 dialog = null;

            if (_dialogFactory != null)
            {
                _dialogFactory.CreateInstance(out dialog);
            }

            // Step 1. git stash keep staged.
            if (dialog != null)
            {
                dialog.StartWaitDialogWithPercentageProgress("Stash staged", "Step 1: git stash --keep-index", "Waiting...", null, "Waiting", false, 0, 4, 1);
            }

            if (!_gitCommandExecuter.TryCreateStashKeepIndex(out var errorMessage))
            {
                dialog?.EndWaitDialog(out _);
                _teamExplorer.ShowNotification(errorMessage, NotificationType.Error, NotificationFlags.None, null, Guid.NewGuid());
                return(false);
            }

            // Step 2. git stash
            if (dialog != null)
            {
                dialog.UpdateProgress($"Step 2: git stash save '{message}'", "Waiting...", "Waiting", 2, 4, true, out _);
            }

            if (!_gitCommandExecuter.TryCreateStash(message, true, out errorMessage))
            {
                dialog?.EndWaitDialog(out _);
                _teamExplorer.ShowNotification(errorMessage, NotificationType.Error, NotificationFlags.None, null, Guid.NewGuid());
                return(false);
            }

            // Step 3. git stash apply
            if (dialog != null)
            {
                dialog.UpdateProgress("Step 3: git stash apply stash@{1}", "Waiting...", "Waiting", 3, 4, true, out _);
            }

            if (!_gitCommandExecuter.TryApplyStash(1, out errorMessage))
            {
                dialog?.EndWaitDialog(out _);
                _teamExplorer.ShowNotification(errorMessage, NotificationType.Error, NotificationFlags.None, null, Guid.NewGuid());
                return(false);
            }

            // Step 4. git stash drop
            if (dialog != null)
            {
                dialog.UpdateProgress("Step 4: git stash drop stash@{1}", "Waiting...", "Waiting", 4, 4, true, out _);
            }

            if (!_gitCommandExecuter.TryDeleteStash(1, out errorMessage))
            {
                dialog?.EndWaitDialog(out _);
                _teamExplorer.ShowNotification(errorMessage, NotificationType.Error, NotificationFlags.None, null, Guid.NewGuid());
                return(false);
            }

            dialog?.EndWaitDialog(out _);
            return(true);
        }