1. Patrick Plenefisch
  2. ZomB Dashboard System

Commits

Patrick Plenefisch  committed a9f5ee2

Adding better error reporting dialogs

Comments (0)

Files changed (5)

File Apps/VisualZomB/App.xaml.cs Modified

View file
  • Ignore whitespace
  • Hide word diff
 using System.Reflection;
 using System.Windows;
 using System451.Communication.Dashboard.Utils;
+using System.Text;
 
 namespace System451.Communication.Dashboard.ViZ
 {
                 }
             }
             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()

File Apps/VisualZomB/Designer.xaml.cs Modified

View file
  • Ignore whitespace
  • Hide word diff
 
                 }
             }
-            catch { }//System.Diagnostics.Debug.Print("FAIL!"); }
+            catch (Exception ex)
+            {
+                App.PrcException(ex);
+            }
         }
 
         private void listBox1_PreviewMouseUp(object sender, MouseButtonEventArgs e)
 
         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;
+            try
+            {
+                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);
 
-            (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();
+                //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;
 
-            foreach (UIElement item in cvs.Children)
-            {
-                if (item.GetType().GetCustomAttributes(typeof(ZomBControlAttribute), true).Length > 0)
+                (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
             {
-                string zaml = Export();
-                File.WriteAllText(dlg.FileName, zaml);
+                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)
+            {
+                App.PrcException(ex);
             }
         }
 
 
             pw.Status = "Generating Zaml...";
             string zaml = Export();
-
+            try
             {
 
                 pw.Status = "Initializing process...";
                 }
                 catch { }
             }
+            catch (Exception ex)
+            {
+                App.PrcException(ex);
+            }
         }
 
         private void StaRun(string zaml, AppRunner r, WPF.ProgressDialog pw)

File Apps/VisualZomB/ErrorDialog.xaml Added

View file
  • Ignore whitespace
  • Hide word diff
+<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>

File Apps/VisualZomB/ErrorDialog.xaml.cs Added

View file
  • Ignore whitespace
  • Hide word diff
+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();
+        }
+    }
+}

File Apps/VisualZomB/VisualZomB.csproj Modified

View file
  • Ignore whitespace
  • Hide word diff
       <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>
   <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>