Exemplo n.º 1
0
        private DialogAction ShowAssertDialog(AssertionViewModel vm)
        {
            using var resetEvent = new AutoResetEvent(false);
            DialogAction action = DialogAction.Ignore;
            var          t      = new Thread(() => {
                var dialog = new DebugAssertWindow(vm);
                dialog.ShowDialog();
                action = dialog.Action;
                resetEvent.Set();
            });

            t.SetApartmentState(ApartmentState.STA);
            t.Start();
            resetEvent.WaitOne();

            return(action);
        }
Exemplo n.º 2
0
        public override void Fail(string?message, string?detailMessage)
        {
            // top 4 frames are TraceListener implementation details, so we need to skip them to get to the Debug.Assert call
            var stackTrace = new StackTrace(4, true);
            var vm         = new AssertionViewModel(message ?? string.Empty, detailMessage ?? string.Empty, stackTrace.ToString());

            DialogAction action = ShowAssertDialog(vm);

            switch (action)
            {
            case DialogAction.Quit:
                string exitMessage = message + (detailMessage?.Length > 0 ? Environment.NewLine + detailMessage : null);
                Environment.FailFast(exitMessage);
                break;

            case DialogAction.Debug:
                if (!Debugger.IsAttached)
                {
                    Debugger.Launch();
                }
                Debugger.Break();
                break;
            }
        }
 internal DebugAssertWindow(AssertionViewModel viewModel)
 {
     InitializeComponent();
     DataContext = viewModel;
 }