private void OnShowWithCancelButton(object sender, RoutedEventArgs e)
        {
            var dialogFactory             = _serviceProvider.GetService(typeof(SVsThreadedWaitDialogFactory)) as IVsThreadedWaitDialogFactory;
            IVsThreadedWaitDialog2 dialog = null;

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

            /* Wait dialog with marquee progress */
            if (dialog != null && dialog.StartWaitDialog(
                    "Wait Dialog (with Cancel)",
                    "VS is Busy, but you can cancel this task by clicking Cancel button",
                    "Progress text", null,
                    "Waiting status bar text", 0, true,
                    true) == VSConstants.S_OK)
            {
                Thread.Sleep(5000);
            }

            bool isCancelled;

            dialog.HasCanceled(out isCancelled);
            if (isCancelled)
            {
                MessageBox.Show("Cancelled");
            }
        }
Пример #2
0
        public void Execute(SelectedItems selectedItems, CancellationTokenSource cts,
                            IVsThreadedWaitDialog2 dialog, int totalCount,
                            TextSelectionExecutor textSelectionExecutor,
                            Func <string, string> projectItemApplyAttributing,
                            string dialogAction = "Attributing")
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (selectedItems == null)
            {
                return;
            }

            var  currentCount     = 0;
            bool cancelProcessing = false;

            foreach (SelectedItem selectedItem in selectedItems)
            {
                dialog?.HasCanceled(out cancelProcessing);
                if (cancelProcessing)
                {
                    cts.Cancel();
                    break;
                }
                if (selectedItem.ProjectItem == null)
                {
                    continue;
                }
                Action <string> projectItemAttributingComplete = (fileName) => {
                    ThreadHelper.ThrowIfNotOnUIThread();
                    currentCount++;
                    dialog?.UpdateProgress($"{dialogAction}: {fileName}", $"{currentCount} of {totalCount} Processed", dialogAction, currentCount, totalCount, false, out cancelProcessing);
                    if (cancelProcessing)
                    {
                        cts.Cancel();
                    }
                };

                Action <string> projectItemAttributingStarted = (fileName) => {
                    ThreadHelper.ThrowIfNotOnUIThread();
                    dialog?.UpdateProgress($"{dialogAction}: {fileName}", $"{currentCount} of {totalCount} Processed", dialogAction, currentCount, totalCount, false, out cancelProcessing);
                    if (cancelProcessing)
                    {
                        cts.Cancel();
                    }
                };

                ProcessProjectItem(selectedItem.ProjectItem, cts.Token,
                                   textSelectionExecutor,
                                   projectItemAttributingComplete,
                                   projectItemAttributingStarted,
                                   projectItemApplyAttributing);
            }
        }
Пример #3
0
        internal bool HasCanceled()
        {
            var hasCanceled = false;

            if (_dialogStarted)
            {
                ThrowOnFailure(_waitDialog.HasCanceled(out hasCanceled));
            }

            return(hasCanceled);
        }
        private bool HasCanceled()
        {
            if (_waitDialog != null)
            {
                bool canceled;
                _waitDialog.HasCanceled(out canceled);

                return(canceled);
            }
            else
            {
                return(false);
            }
        }
Пример #5
0
        void CreateProgressDialog()
        {
            var dialogFactory = GetService(typeof(SVsThreadedWaitDialogFactory)) as IVsThreadedWaitDialogFactory;
            IVsThreadedWaitDialog2 progressDialog = null;

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

            if (progressDialog != null &&
                progressDialog.StartWaitDialog(
                    ResolveUR.Library.Constants.AppName + " Working...",
                    "Visual Studio is busy. Cancel ResolveUR by clicking Cancel button",
                    string.Empty,
                    null,
                    string.Empty,
                    0,
                    true,
                    true) == VSConstants.S_OK)
            {
                Thread.Sleep(1000);
            }

            _helper.ProgressDialog = progressDialog;

            var dialogCanceled = false;

            if (progressDialog != null)
            {
                progressDialog.HasCanceled(out dialogCanceled);
            }

            if (!dialogCanceled)
            {
                return;
            }

            _resolveur.Cancel();
            _helper.ShowMessageBox(ResolveUR.Library.Constants.AppName + " Status", "Canceled");
        }
Пример #6
0
        private async System.Threading.Tasks.Task RestorePackagesOrCheckForMissingPackages(vsBuildScope scope)
        {
            _msBuildOutputVerbosity = GetMSBuildOutputVerbositySetting(_dte);
            var waitDialogFactory = ServiceLocator.GetGlobalService <SVsThreadedWaitDialogFactory, IVsThreadedWaitDialogFactory>();

            waitDialogFactory.CreateInstance(out _waitDialog);
            var token = CancellationTokenSource.Token;

            try
            {
                if (IsConsentGranted())
                {
                    if (scope == vsBuildScope.vsBuildScopeSolution || scope == vsBuildScope.vsBuildScopeBatch || scope == vsBuildScope.vsBuildScopeProject)
                    {
                        TotalCount = (await PackageRestoreManager.GetMissingPackagesInSolution(token)).ToList().Count;
                        if (TotalCount > 0)
                        {
                            if (_outputOptOutMessage)
                            {
                                _waitDialog.StartWaitDialog(
                                    Resources.DialogTitle,
                                    Resources.RestoringPackages,
                                    String.Empty,
                                    varStatusBmpAnim: null,
                                    szStatusBarText: null,
                                    iDelayToShowDialog: 0,
                                    fIsCancelable: true,
                                    fShowMarqueeProgress: true);
                                WriteLine(VerbosityLevel.Quiet, Resources.PackageRestoreOptOutMessage);
                                _outputOptOutMessage = false;
                            }

                            System.Threading.Tasks.Task waitDialogCanceledCheckTask = System.Threading.Tasks.Task.Run(() =>
                            {
                                // Just create an extra task that can keep checking if the wait dialog was cancelled
                                // If so, cancel the CancellationTokenSource
                                bool canceled = false;
                                try
                                {
                                    while (!canceled && CancellationTokenSource != null && !CancellationTokenSource.IsCancellationRequested && _waitDialog != null)
                                    {
                                        _waitDialog.HasCanceled(out canceled);
                                        // Wait on the cancellation handle for 100ms to avoid checking on the wait dialog too frequently
                                        CancellationTokenSource.Token.WaitHandle.WaitOne(100);
                                    }

                                    CancellationTokenSource.Cancel();
                                }
                                catch (Exception)
                                {
                                    // Catch all and don't throw
                                    // There is a slight possibility that the _waitDialog was set to null by another thread right after the check for null
                                    // So, it could be null or disposed. Just ignore all errors
                                }
                            });

                            System.Threading.Tasks.Task whenAllTaskForRestorePackageTasks =
                                System.Threading.Tasks.Task.WhenAll(SolutionManager.GetNuGetProjects().Select(nuGetProject => RestorePackagesInProject(nuGetProject, token)));

                            await System.Threading.Tasks.Task.WhenAny(whenAllTaskForRestorePackageTasks, waitDialogCanceledCheckTask);

                            // Once all the tasks are completed, just cancel the CancellationTokenSource
                            // This will prevent the wait dialog from getting updated
                            CancellationTokenSource.Cancel();
                        }
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    _waitDialog.StartWaitDialog(
                        Resources.DialogTitle,
                        Resources.RestoringPackages,
                        String.Empty,
                        varStatusBmpAnim: null,
                        szStatusBarText: null,
                        iDelayToShowDialog: 0,
                        fIsCancelable: true,
                        fShowMarqueeProgress: true);
                    CheckForMissingPackages((await PackageRestoreManager.GetMissingPackagesInSolution(token)).ToList());
                }
            }
            finally
            {
                int canceled;
                _waitDialog.EndWaitDialog(out canceled);
                _waitDialog = null;
            }

            await PackageRestoreManager.RaisePackagesMissingEventForSolution(CancellationToken.None);
        }