예제 #1
0
 private bool IsValidLocalConnection(string name, string path)
 {
     try {
         var info = _installationService.CreateInfo(name, path);
         return(info.VerifyInstallation());
     } catch (Exception ex) when(!ex.IsCriticalException())
     {
         _log.Write(LogVerbosity.Normal, MessageCategory.Error, ex.Message);
     }
     return(false);
 }
예제 #2
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?.Write(LogVerbosity.Minimal, MessageCategory.Error, "Long operation exception: " + ex.Message);
            }
            return(true);
        }
예제 #3
0
        public static IDisposable Measure(this IActionLog log, LogVerbosity verbosity, string message)
        {
            if (log.LogVerbosity < verbosity)
            {
                return(Disposable.Empty);
            }

            log.Write(verbosity, MessageCategory.General, Invariant($"{message} started"));
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            return(Disposable.Create(() => {
                stopwatch.Stop();
                log.Write(verbosity, MessageCategory.General, Invariant($"{message} completed in {stopwatch.ElapsedMilliseconds} ms."));
            }));
        }
        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.Write(LogVerbosity.Normal, MessageCategory.General, sb.ToString());
        }
예제 #5
0
 public void Write(LogVerbosity verbosity, MessageCategory category, string message)
 => _log.Write(verbosity, category, message);
 public static void ErrorInFileSystemWatcher(this IActionLog log, string watcherName, Exception e)
 {
     log.Write(LogVerbosity.Minimal, MessageCategory.Error, Invariant($"{watcherName} failed with exception:{e}"));
 }
예제 #7
0
 public void Write(string text)
 {
     _log.Write(LogVerbosity.Minimal, MessageCategory.General, $"[{_prefix} output]: {text}");
 }