public override void Fail(string message, string detailMessage)
        {
            base.Fail(message, detailMessage);  //write message to the output panel

            if (Debugger.IsAttached)
            {
                //if debugger is attached, just break => all threads stopped
                Debugger.Break();
            }
            else if (Dispatcher.CurrentDispatcher == _guiDisp)
            {
                //running standalone and called in the GUI thread => block it
                Thread anotherGuiThread = new Thread(() =>
                {
                    //TODO: nice dlg with buttons
                    var assertDlg = new Window()
                    {
                        Width = 100, Height = 100
                    };
                    assertDlg.Show();
                    assertDlg.Closed += (s, e) => assertDlg.Dispatcher.InvokeShutdown();
                    System.Windows.Threading.Dispatcher.Run(); //run on its own thread
                });

                anotherGuiThread.SetApartmentState(ApartmentState.STA);
                anotherGuiThread.Start();
                anotherGuiThread.Join();
            }
            else
            {
                //running standalone and NOT called in the GUI thread => call normal assert
                _defListener.Fail(message, detailMessage);
            }
        }
 public override void Fail(string message) => Lock(() => listener.Fail(message));
Beispiel #3
0
        public override void Fail(string message, string detailMessage)
        {
            if (ignoreAssertions)
            {
                return;
            }
            if (Debugger.IsAttached)
            {
                core.Fail(message, detailMessage);
                return;
            }

            int result = 0;

            Application.Current.Dispatcher.Invoke(() => {
                result = fileSystem.ShowOptions(
                    "Debug Assert!" + versionNumber,
                    message + Environment.NewLine + Environment.NewLine + detailMessage,
                    null,
                    new[] {
                    new VisualOption {
                        Index            = 0,
                        Option           = "Ignore",
                        ShortDescription = "Don't Show Assertions",
                        Description      = "Ignore assertions until the next time the application is opened."
                    },
                    new VisualOption {
                        Index            = 1,
                        Option           = "Debug",
                        ShortDescription = "Show Full Message",
                        Description      = "Bring up the full dialog with debugging options."
                    },
                    new VisualOption {
                        Index            = 2,
                        Option           = "Continue",
                        ShortDescription = "Ignore This One",
                        Description      = "Ignore this assertion, but show this dialog again if there's another."
                    },
                });
            });

            // user hit "Ignore Additional Assertions"
            ignoreAssertions = result == 0;
            while (result == 1)
            {
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                    break;
                }
                else
                {
                    Application.Current.Dispatcher.Invoke(() => {
                        result = fileSystem.ShowOptions(
                            "Attach a Debugger",
                            "Attach a debugger and click 'Debug' to get more information about the following assertion:" + Environment.NewLine +
                            message + Environment.NewLine +
                            detailMessage + Environment.NewLine +
                            "Stack Trace:" + Environment.NewLine +
                            Environment.StackTrace,
                            null,
                            new[] {
                            new VisualOption {
                                Index            = 1,
                                Option           = "Debug",
                                ShortDescription = "Show in Debugger",
                                Description      = "Break in a connected debugger"
                            },
                        }
                            );
                    });
                }
            }
        }
Beispiel #4
0
 void ILogger.Error(string message)
 {
     _output.Fail(message);
 }