Example #1
0
		public void TestGetInnerException_Marked_DoesNotHaveInner_NestedInner()
		{
			var inner = new Exception( "Inner", null );
			inner.Data[ ExceptionModifiers.IsMatrioshkaInner ] = null;
			var source = new Exception( "Outer", inner );

			var result = source.GetInnerException();

			Assert.That( result, Is.Null );
		}
Example #2
0
		public void TestGetInnerException_NotMarked_AsIs()
		{
			var nestedInner = new Exception( "Nested inner" );
			var inner = new Exception( "Inner", nestedInner );
			var source = new Exception( "Outer", inner );
	
			var result = source.GetInnerException();
			
			Assert.That( result, Is.SameAs( inner ) );
		}
Example #3
0
		public void TestGetInnerException_Marked_HasInner_NestedInner()
		{
			var nestedInner = new Exception( "Nested inner" );
			var inner = new Exception( "Inner", nestedInner );
			inner.Data[ ExceptionModifiers.IsMatrioshkaInner ] = null;
			var source = new Exception( "Outer", inner );

			var result = source.GetInnerException();

			Assert.That( result, Is.SameAs( nestedInner ) );
		}
Example #4
0
		public void TestGetInnerException_InnerIsNull_Null()
		{
			var source = new Exception();
			var result = source.GetInnerException();
			Assert.That( result, Is.Null );
		}
Example #5
0
 private static void ShowExceptionReporter(Exception ex)
 {
     var inner = ex.GetInnerException();
     Logging.Client.Error("Unhandled Exception", inner);
     if (inner is InvalidZetboxGeneratedVersionException)
     {
         MessageBox.Show(
             WpfToolkitResources.InvalidZetboxGeneratedVersionException_Message,
             WpfToolkitResources.InvalidZetboxGeneratedVersionException_Title,
             MessageBoxButton.OK,
             MessageBoxImage.Stop);
     }
     else if (wpfResourcesInitialized && container != null)
     {
         var vmf = container.Resolve<IViewModelFactory>();
         var mdl = vmf.CreateViewModel<ExceptionReporterViewModel.Factory>().Invoke(container.Resolve<IZetboxContext>(), null, ex, container.Resolve<IScreenshotTool>().GetScreenshot());
         vmf.ShowDialog(mdl);
     }
     else
     {
         MessageBox.Show(ex.ToString());
     }
 }
        public bool Show(IZetboxContext ctx, Exception ex)
        {
            if (ctx == null) throw new ArgumentNullException("ctx");
            if (ex == null) return false;

            var inner = ex.GetInnerException();
            if (inner is ConcurrencyException)
            {
                var error = (ConcurrencyException)inner;
                vmf.CreateDialog(ctx, ZetboxContextExceptionHandlerResources.ConcurrencyException_Caption)
                    .AddTextBlock("empty", string.Empty, ZetboxContextExceptionHandlerResources.ConcurrencyException_Message)
                    .AddMultiLineString("details", ZetboxContextExceptionHandlerResources.DetailsLabel, string.Join("\n", error.Details.Select(e => string.Format(ZetboxContextExceptionHandlerResources.ConcurrencyException_DetailFormatString, e.ObjectAsString, e.ChangedBy, e.ChangedOn))), true, true)
                    .Show();
                return true;
            }
            else if (inner is ZetboxValidationException)
            {
                var error = (ZetboxValidationException)inner;
                vmf.CreateDialog(ctx, ZetboxContextExceptionHandlerResources.ZetboxValidationException_Caption)
                    .AddTextBlock("empty", string.Empty, ZetboxContextExceptionHandlerResources.ZetboxValidationException_Message)
                    .AddMultiLineString("details", ZetboxContextExceptionHandlerResources.ZetboxValidationException_ValueLabel, string.Format(ZetboxContextExceptionHandlerResources.ZetboxValidationException_ValueFormat, error.Message))
                    .Show();
                return true;
            }
            else if (inner is FKViolationException)
            {
                var error = (FKViolationException)inner;
                var details = string.Join("\n", error.Details.Select(e =>
                {
                    if (e.RelGuid == default(Guid) || e.RelGuid == Guid.Empty) return e.DatabaseError;
                    var rel = frozenCtx.FindPersistenceObject<Relation>(e.RelGuid);
                    return string.Format(
                        ZetboxContextExceptionHandlerResources.FKViolationException_DetailFormatString,
                        rel.A.Type.Name,
                        rel.B.Type.Name,
                        rel.A.RoleName,
                        rel.Verb,
                        rel.B.RoleName,
                        e.DatabaseError);
                }));
                vmf.CreateDialog(ctx, ZetboxContextExceptionHandlerResources.FKViolationException_Caption)
                    .AddTextBlock("error", string.Empty, ZetboxContextExceptionHandlerResources.FKViolationException_Message)
                    .AddMultiLineString("details", ZetboxContextExceptionHandlerResources.DetailsLabel, details, true, true)
                    .Show();
                return true;
            }
            else if (inner is UniqueConstraintViolationException)
            {
                var error = (UniqueConstraintViolationException)inner;
                var details = string.Join("\n", error.Details.Select(e =>
                {
                    if (e.IdxGuid == default(Guid) || e.IdxGuid == Guid.Empty) return e.DatabaseError;
                    var idx = frozenCtx.FindPersistenceObject<IndexConstraint>(e.IdxGuid);
                    return string.Format(
                        ZetboxContextExceptionHandlerResources.UniqueConstraintViolationException_DetailFormatString,
                        idx.Constrained.Name,
                        string.Join(", ", idx.Properties.Select(p => p.GetLabel())),
                        idx.Reason,
                        e.DatabaseError);
                }));
                vmf.CreateDialog(ctx, ZetboxContextExceptionHandlerResources.UniqueConstraintViolationException_Caption)
                    .AddTextBlock("error", string.Empty, ZetboxContextExceptionHandlerResources.UniqueConstraintViolationException_Message)
                    .AddMultiLineString("details", ZetboxContextExceptionHandlerResources.DetailsLabel, details, true, true)
                    .Show();
                return true;
            }

            return false;
        }