Inheritance: FirstFloor.ModernUI.Presentation.Displayable
 public NonfatalErrorSolution([CanBeNull] string displayName, NonfatalErrorEntry entry, [CanBeNull] Func <CancellationToken, Task> execute)
     : base(() => Task.Delay(0), () => execute != null)
 {
     _entry      = entry;
     _execute    = execute;
     DisplayName = displayName ?? "Fix It";
 }
Beispiel #2
0
        private static void NotifyInner([NotNull] string message, [CanBeNull] string commentary, [CanBeNull] Exception exception,
                                        [CanBeNull] IEnumerable <NonfatalErrorSolution> solutions, bool show, string m, string p, int l)
        {
            if (exception is UserCancelledException)
            {
                return;
            }

            var i = exception as InformativeException;

            if (i != null)
            {
                message    = i.Message;
                commentary = i.SolutionCommentary;
                exception  = i.InnerException;
            }

            Logging.Write('•', $"{message}:\n{exception}", m, p, l);

            var entry = new NonfatalErrorEntry(message, commentary, exception, solutions ?? new NonfatalErrorSolution[0]);

            ActionExtension.InvokeInMainThreadAsync(() => {
                try {
                    var active = _active;
                    _active    = true;

                    if (show && !active && DateTime.Now - _previous > ErrorsTimeout)
                    {
                        ErrorMessage.Show(entry);
                    }

                    if (Instance.Errors.Count > ErrorsLimit)
                    {
                        Instance.Errors.RemoveAt(Instance.Errors.Count - 1);
                    }

                    Instance.Errors.Insert(0, entry);
                    if (entry.Unseen)
                    {
                        Instance.UpdateUnseen();
                    }
                } catch (Exception e) {
                    Logging.Error(e);
                } finally {
                    _active   = false;
                    _previous = DateTime.Now;
                }
            });
        }
Beispiel #3
0
        public static void Show(NonfatalErrorEntry entry) {
            var text = (entry.Exception == null ? $"{entry.DisplayName}." : $"{entry.DisplayName}:\n\n[b][mono]{entry.Exception.Message}[/mono][/b]") +
                    (entry.Commentary == null ? "" : $"\n\n[i]{entry.Commentary}[/i]");
            var dlg = new ModernDialog {
                Title = UiStrings.Common_Oops,
                Content = new ScrollViewer {
                    Content = new BbCodeBlock { BbCode = text, Margin = new Thickness(0, 0, 0, 8) },
                    VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                    HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled
                },
                MinHeight = 0,
                MinWidth = 0,
                MaxHeight = 480,
                MaxWidth = 640
            };

            dlg.Buttons = entry.Solutions.Select(x => dlg.CreateFixItButton(x, entry)).Where(x => x != null).Union(new[] { dlg.OkButton });
            dlg.Show();

            entry.Unseen = false;
        }
Beispiel #4
0
        private static void NotifyInner([NotNull] string message, [CanBeNull] string commentary, [CanBeNull] Exception exception,
                [CanBeNull] IEnumerable<INonfatalErrorSolution> solutions, bool show, string m, string p, int l) {
            if (exception is UserCancelledException) return;

            var i = exception as InformativeException;
            if (i != null) {
                message = i.Message;
                commentary = i.SolutionCommentary;
                exception = i.InnerException;
            }

            Logging.Write('•', $"{message}:\n{exception}", m, p, l);

            var entry = new NonfatalErrorEntry(message, commentary, exception, solutions ?? new INonfatalErrorSolution[0]);
            Application.Current.Dispatcher.InvokeAsync(() => {
                try {
                    var active = _active;
                    _active = true;

                    if (show && !active && DateTime.Now - _previous > ErrorsTimeout) {
                        ErrorMessage.Show(entry);
                    }

                    if (Instance.Errors.Count > ErrorsLimit) {
                        Instance.Errors.RemoveAt(Instance.Errors.Count - 1);
                    }

                    Instance.Errors.Insert(0, entry);
                    if (entry.Unseen) {
                        Instance.UpdateUnseen();
                    }
                } catch (Exception e) {
                    Logging.Error("NotifyInner(): " + e);
                } finally {
                    _active = false;
                    _previous = DateTime.Now;
                }
            });
        }
Beispiel #5
0
 public static Button CreateFixItButton([NotNull] this ModernDialog dlg, [CanBeNull] INonfatalErrorSolution solution, NonfatalErrorEntry entry = null) {
     if (dlg == null) throw new ArgumentNullException(nameof(dlg));
     return solution == null ? null : dlg.CreateCloseDialogButton(solution.DisplayName, false, false, MessageBoxResult.OK, solution);
 }
 public INonfatalErrorSolution([CanBeNull] string displayName, NonfatalErrorEntry entry, [NotNull] Func<CancellationToken, Task> execute, Func<bool> canExecute = null)
         : base(() => Task.Delay(0), canExecute, 0, false) {
     _entry = entry;
     _execute = execute;
     DisplayName = displayName ?? "Fix It";
 }