Permalink
Browse files

Adding better error reporting dialogs

git-svn-id: http://firstforge.wpi.edu/svn/repos/zomb/trunk@397 0141d0df-edca-4edd-a601-3402401f7f08
  • Loading branch information...
1 parent ba3fe37 commit 56f6037843fa231ef0fce6d360df8aa6a6b50980 @byteit101 committed Mar 13, 2011
@@ -20,6 +20,7 @@
using System.Reflection;
using System.Windows;
using System451.Communication.Dashboard.Utils;
+using System.Text;
namespace System451.Communication.Dashboard.ViZ
{
@@ -88,7 +89,41 @@ private void Application_Startup(object sender, StartupEventArgs e)
}
}
else
- new Designer().Show();
+#if !DEBUG
+ try
+ {
+#endif
+ new Designer().Show();
+#if !DEBUG
+ }
+ catch (Exception ex)
+ {
+ string full = getFullException(ex);
+ System.Windows.Forms.MessageBox.Show(full);
+ }
+#endif
+ }
+
+ internal static void PrcException(Exception ex)
+ {
+ string full = getFullException(ex);
+ new ErrorDialog { Message = full }.ShowDialog();
+ try
+ {
+ using (StreamWriter sw = new StreamWriter(File.Open("C:\\ZomB.log", FileMode.Append)))
+ {
+ sw.Write(full+"\r\n\r\n");
+ }
+ }
+ catch { }
+ }
+
+ internal static string getFullException(Exception ex)
+ {
+ StringBuilder sb = new StringBuilder(ex.ToString());
+ if (ex.InnerException != null)
+ sb.Append("\r\nWith Inner:\r\n"+getFullException(ex.InnerException));
+ return sb.ToString();
}
internal static void LoadPlugins()
@@ -254,7 +254,10 @@ private void listBox1_PreviewMouseMove(object sender, MouseEventArgs e)
}
}
- catch { }//System.Diagnostics.Debug.Print("FAIL!"); }
+ catch (Exception ex)
+ {
+ App.PrcException(ex);
+ }
}
private void listBox1_PreviewMouseUp(object sender, MouseButtonEventArgs e)
@@ -1128,55 +1131,69 @@ internal void CommandBinding_Open_Executed(object sender, ExecutedRoutedEventArg
public void LoadFile(string fileName)
{
- StoppedDDHCVS cvs = XamlReader.Load(new MemoryStream(UTF8Encoding.UTF8.GetBytes(new StreamReader(new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
- .ReadToEnd().Replace("ZomB:DashboardDataCanvas ",
- "ViZ:StoppedDDHCVS xmlns:ViZ=\"clr-namespace:System451.Communication.Dashboard.ViZ;assembly=ViZ\" ")
- .Replace("/ZomB:DashboardDataCanvas",
- "/ViZ:StoppedDDHCVS")))) as StoppedDDHCVS;
- if (cvs == null)
- return;
- List<UIElement> lc = new List<UIElement>(cvs.Children.Count);
-
- //canvas size
- var ofv = new Point(cvs.Width, cvs.Height) - new Point(ZDash.ActualWidth, ZDash.ActualHeight);
- var newInnerSize = (Size)(new Point(ZDash.ActualWidth, ZDash.ActualHeight) + ofv);
- var newOuterSize = (Size)(new Point(this.ActualWidth, this.ActualHeight) + ofv);
- this.Width = newOuterSize.Width;
- this.Height = newOuterSize.Height;
- LayoutCvs.Width = (ZDChrome.Width = ZDash.Width = newInnerSize.Width) + 4;
- LayoutCvs.Height = (ZDChrome.Height = ZDash.Height = newInnerSize.Height) + 4;
-
- (designerProps[3] as ComboBox).SelectedIndex = ((int)cvs.InvalidPacketAction) - 1;//this hinges on the values
- ((designerProps[5] as FrameworkElement).Tag as ZomBUrlCollectionDesigner).Set((cvs.DefaultSources));
- (designerProps[7] as TextBox).Text = cvs.Team.ToString();
-
- foreach (UIElement item in cvs.Children)
+ try
{
- if (item.GetType().GetCustomAttributes(typeof(ZomBControlAttribute), true).Length > 0)
+ StoppedDDHCVS cvs = XamlReader.Load(new MemoryStream(UTF8Encoding.UTF8.GetBytes(new StreamReader(new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
+ .ReadToEnd().Replace("ZomB:DashboardDataCanvas ",
+ "ViZ:StoppedDDHCVS xmlns:ViZ=\"clr-namespace:System451.Communication.Dashboard.ViZ;assembly=ViZ\" ")
+ .Replace("/ZomB:DashboardDataCanvas",
+ "/ViZ:StoppedDDHCVS")))) as StoppedDDHCVS;
+ if (cvs == null)
+ return;
+ List<UIElement> lc = new List<UIElement>(cvs.Children.Count);
+
+ //canvas size
+ var ofv = new Point(cvs.Width, cvs.Height) - new Point(ZDash.ActualWidth, ZDash.ActualHeight);
+ var newInnerSize = (Size)(new Point(ZDash.ActualWidth, ZDash.ActualHeight) + ofv);
+ var newOuterSize = (Size)(new Point(this.ActualWidth, this.ActualHeight) + ofv);
+ this.Width = newOuterSize.Width;
+ this.Height = newOuterSize.Height;
+ LayoutCvs.Width = (ZDChrome.Width = ZDash.Width = newInnerSize.Width) + 4;
+ LayoutCvs.Height = (ZDChrome.Height = ZDash.Height = newInnerSize.Height) + 4;
+
+ (designerProps[3] as ComboBox).SelectedIndex = ((int)cvs.InvalidPacketAction) - 1;//this hinges on the values
+ ((designerProps[5] as FrameworkElement).Tag as ZomBUrlCollectionDesigner).Set((cvs.DefaultSources));
+ (designerProps[7] as TextBox).Text = cvs.Team.ToString();
+
+ foreach (UIElement item in cvs.Children)
{
- lc.Add(item);
+ if (item.GetType().GetCustomAttributes(typeof(ZomBControlAttribute), true).Length > 0)
+ {
+ lc.Add(item);
+ }
}
+ ZDash.Children.Clear();
+ foreach (var item in lc)
+ {
+ cvs.Children.Remove(item);
+ AddControl((FrameworkElement)item);
+ }
+ Deselect();
}
- ZDash.Children.Clear();
- foreach (var item in lc)
+ catch (Exception ex)
{
- cvs.Children.Remove(item);
- AddControl((FrameworkElement)item);
+ App.PrcException(ex);
}
- Deselect();
}
private void SaveApp()
{
- var dlg = new System.Windows.Forms.SaveFileDialog();
- dlg.DefaultExt = ".zaml";
- dlg.AddExtension = true;
- dlg.SupportMultiDottedExtensions = true;
- dlg.Filter = "ZomB App Markup Files (*.zaml)|*.zaml|All Files|*.*";
- if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+ try
+ {
+ var dlg = new System.Windows.Forms.SaveFileDialog();
+ dlg.DefaultExt = ".zaml";
+ dlg.AddExtension = true;
+ dlg.SupportMultiDottedExtensions = true;
+ dlg.Filter = "ZomB App Markup Files (*.zaml)|*.zaml|All Files|*.*";
+ if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+ {
+ string zaml = Export();
+ File.WriteAllText(dlg.FileName, zaml);
+ }
+ }
+ catch (Exception ex)
{
- string zaml = Export();
- File.WriteAllText(dlg.FileName, zaml);
+ App.PrcException(ex);
}
}
@@ -1190,7 +1207,7 @@ private void RunApp()
pw.Status = "Generating Zaml...";
string zaml = Export();
-
+ try
{
pw.Status = "Initializing process...";
@@ -1217,6 +1234,10 @@ private void RunApp()
}
catch { }
}
+ catch (Exception ex)
+ {
+ App.PrcException(ex);
+ }
}
private void StaRun(string zaml, AppRunner r, WPF.ProgressDialog pw)
@@ -0,0 +1,18 @@
+<Window x:Class="System451.Communication.Dashboard.ViZ.ErrorDialog"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ Title="Kaboom!" Height="488" Width="691" xmlns:my="clr-namespace:System451.Communication.Dashboard.ViZ" Topmost="True" WindowStartupLocation="CenterScreen" SnapsToDevicePixels="True">
+ <Grid Margin="10">
+ <Grid.RowDefinitions>
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="260*" />
+ <RowDefinition Height="Auto" />
+ </Grid.RowDefinitions>
+ <StackPanel Grid.Row="2" Name="stackPanel1" HorizontalAlignment="Right" Orientation="Horizontal" Margin="0,5,0,0">
+ <Label Content="A copy of this report has been saved to C:\ZomB.log" Name="label1" VerticalAlignment="Center" HorizontalAlignment="Center" Padding="5,5,10,5" />
+ <Button Content="Close" Height="23" Name="button1" Width="75" Click="button1_Click" />
+ </StackPanel>
+ <Label Content="Ack! ZomB encountered an error. Please let the developers know about this." Name="label2" VerticalAlignment="Top" />
+ <TextBox Grid.Row="1" Name="textBox1" IsReadOnly="True" Text="{Binding Path=Message, RelativeSource={RelativeSource FindAncestor, AncestorType=my:ErrorDialog, AncestorLevel=1}}" Background="LightGray" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" />
+ </Grid>
+</Window>
@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+
+namespace System451.Communication.Dashboard.ViZ
+{
+ /// <summary>
+ /// Interaction logic for ErrorDialog.xaml
+ /// </summary>
+ public partial class ErrorDialog : Window
+ {
+ public ErrorDialog()
+ {
+ InitializeComponent();
+ }
+
+ public string Message
+ {
+ get { return (string)GetValue(MessageProperty); }
+ set { SetValue(MessageProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for Message. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty MessageProperty =
+ DependencyProperty.Register("Message", typeof(string), typeof(ErrorDialog), new UIPropertyMetadata(""));
+
+ private void button1_Click(object sender, RoutedEventArgs e)
+ {
+ this.Close();
+ }
+ }
+}
@@ -92,6 +92,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
+ <Page Include="ErrorDialog.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
<Page Include="FirstRun.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -133,6 +137,9 @@
<ItemGroup>
<Compile Include="CategoryComparer.cs" />
<Compile Include="DropShadowChrome.cs" />
+ <Compile Include="ErrorDialog.xaml.cs">
+ <DependentUpon>ErrorDialog.xaml</DependentUpon>
+ </Compile>
<Compile Include="FirstRun.xaml.cs">
<DependentUpon>FirstRun.xaml</DependentUpon>
</Compile>

0 comments on commit 56f6037

Please sign in to comment.