Ejemplo n.º 1
0
        public static bool ShowWaitingPopup(string message, IReadOnlyList <LongAction> actions, IActionLog log)
        {
            CommonMessagePump msgPump = new CommonMessagePump();

            msgPump.AllowCancel        = true;
            msgPump.EnableRealProgress = true;
            msgPump.WaitTitle          = "R Tools for Visual Studio";
            msgPump.WaitText           = message;
            msgPump.TotalSteps         = actions.Count;

            CancellationTokenSource cts = new CancellationTokenSource();
            Task task = Task.Run(() => {
                for (int i = 0; i < actions.Count; i++)
                {
                    cts.Token.ThrowIfCancellationRequested();
                    msgPump.CurrentStep = i + 1;
                    if (actions[i].Name == null)
                    {
                        msgPump.ProgressText = string.Format(CultureInfo.InvariantCulture, Resources.LongOperationProgressMessage1, i + 1, msgPump.TotalSteps);
                    }
                    else
                    {
                        msgPump.ProgressText = string.Format(CultureInfo.InvariantCulture, Resources.LongOperationProgressMessage2, i + 1, msgPump.TotalSteps, actions[i].Name);
                    }
                    actions[i].Action(actions[i].Data, cts.Token);
                }
            }, cts.Token);

            CommonMessagePumpExitCode exitCode;

            if (!VsAppShell.Current.IsUnitTestEnvironment)
            {
                exitCode = msgPump.ModalWaitForHandles(((IAsyncResult)task).AsyncWaitHandle);
            }
            else
            {
                exitCode = CommonMessagePumpExitCode.HandleSignaled;
            }

            if (exitCode == CommonMessagePumpExitCode.UserCanceled || exitCode == CommonMessagePumpExitCode.ApplicationExit)
            {
                cts.Cancel();
                msgPump                    = new CommonMessagePump();
                msgPump.AllowCancel        = false;
                msgPump.EnableRealProgress = false;
                // Wait for the async operation to actually cancel.
                msgPump.ModalWaitForHandles(((IAsyncResult)task).AsyncWaitHandle);
            }

            if (task.IsCanceled)
            {
                return(false);
            }
            try {
                task.Wait();
            } catch (Exception ex) {
                log?.WriteAsync(LogVerbosity.Minimal, MessageCategory.Error, "Long operation exception: " + ex.Message).DoNotWait();
            }
            return(true);
        }
Ejemplo n.º 2
0
        public static void WatcherChangesetSent(this IActionLog log, MsBuildFileSystemWatcher.Changeset changeset)
        {
            var sb = new StringBuilder();

            sb.AppendLine("MsBuildFileSystemWatcher changeset sent.")
            .AppendWatcherChangesetPart(changeset.AddedFiles, "Added Files:")
            .AppendWatcherChangesetPart(changeset.RenamedFiles, "Renamed Files:")
            .AppendWatcherChangesetPart(changeset.RemovedFiles, "Removed Files:")
            .AppendWatcherChangesetPart(changeset.AddedDirectories, "Added Directories:")
            .AppendWatcherChangesetPart(changeset.RenamedDirectories, "Renamed Directories:")
            .AppendWatcherChangesetPart(changeset.RemovedDirectories, "Removed Directories:");

            log.WriteAsync(LogVerbosity.Normal, MessageCategory.General, sb.ToString());
        }
Ejemplo n.º 3
0
 public static void ErrorInFileSystemWatcher(this IActionLog log, string watcherName, Exception e)
 {
     log.WriteAsync(LogVerbosity.Minimal, MessageCategory.Error, Invariant($"{watcherName} failed with exception:{e}"));
 }
Ejemplo n.º 4
0
 public static void ErrorInFileSystemWatcher(this IActionLog log, string watcherName, Exception e)
 {
     log.WriteAsync(MessageCategory.Error, $"{watcherName} failed with exception:{e}");
 }