From dc41cebc183c072c5187f6d4e2323079d2fbcc36 Mon Sep 17 00:00:00 2001 From: soukoku Date: Sat, 12 Apr 2014 11:22:05 -0400 Subject: [PATCH] Added error handling to wpf example. --- Tests/Tester.WPF/MainWindow.xaml.cs | 9 +++++++++ Tests/Tester.WPF/Tester.WPF.csproj | 12 ++++++++++++ Tests/Tester.WPF/TwainVM.cs | 24 ++++++++++++++++++++++++ Tests/Tester.WPF/app.config | 13 +++++++++++-- Tests/Tester.WPF/packages.config | 2 ++ 5 files changed, 58 insertions(+), 2 deletions(-) diff --git a/Tests/Tester.WPF/MainWindow.xaml.cs b/Tests/Tester.WPF/MainWindow.xaml.cs index 0b6dd5e..d607aa2 100644 --- a/Tests/Tester.WPF/MainWindow.xaml.cs +++ b/Tests/Tester.WPF/MainWindow.xaml.cs @@ -20,6 +20,8 @@ using CommonWin32; using System.Threading; using ModernWPF.Controls; using System.Reflection; +using System.ComponentModel; +using GalaSoft.MvvmLight.Messaging; namespace Tester.WPF { @@ -44,6 +46,13 @@ namespace Tester.WPF _twainVM = new TwainVM(); this.DataContext = _twainVM; + if (!DesignerProperties.GetIsInDesignMode(this)) + { + Messenger.Default.Register(this, msg => + { + ModernMessageBox.Show(this, msg.Content, msg.Caption, msg.Button, msg.Icon, msg.DefaultResult); + }); + } } protected override void OnClosed(EventArgs e) diff --git a/Tests/Tester.WPF/Tester.WPF.csproj b/Tests/Tester.WPF/Tester.WPF.csproj index d991a50..0278e66 100644 --- a/Tests/Tester.WPF/Tester.WPF.csproj +++ b/Tests/Tester.WPF/Tester.WPF.csproj @@ -44,6 +44,15 @@ False ..\..\packages\CommonWin32.2.0.4\lib\net35-Client\CommonWin32.dll + + ..\..\packages\MvvmLightLibs.4.3.31.1\lib\net40\GalaSoft.MvvmLight.Extras.WPF4.dll + + + ..\..\packages\MvvmLightLibs.4.3.31.1\lib\net40\GalaSoft.MvvmLight.WPF4.dll + + + ..\..\packages\CommonServiceLocator.1.2\lib\portable-windows8+net40+sl5+windowsphone8\Microsoft.Practices.ServiceLocation.dll + False ..\..\packages\ModernWPF.1.1.41.2\lib\net40-Client\ModernWPF.dll @@ -51,6 +60,9 @@ + + ..\..\packages\MvvmLightLibs.4.3.31.1\lib\net40\System.Windows.Interactivity.dll + diff --git a/Tests/Tester.WPF/TwainVM.cs b/Tests/Tester.WPF/TwainVM.cs index 7367f76..409e44e 100644 --- a/Tests/Tester.WPF/TwainVM.cs +++ b/Tests/Tester.WPF/TwainVM.cs @@ -10,6 +10,7 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using CommonWin32; using System.Threading; +using GalaSoft.MvvmLight.Messaging; namespace Tester.WPF { @@ -42,6 +43,29 @@ namespace Tester.WPF } } + protected override void OnTransferError(TransferErrorEventArgs e) + { + if (e.Exception != null) + { + Messenger.Default.Send(new DialogMessage(e.Exception.Message, null) + { + Caption = "Transfer Error Exception", + Icon = System.Windows.MessageBoxImage.Error, + Button = System.Windows.MessageBoxButton.OK + }); + } + else + { + Messenger.Default.Send(new DialogMessage(string.Format("Return Code: {0}\nCondition Code: {1}", e.ReturnCode, e.SourceStatus.ConditionCode), null) + { + Caption = "Transfer Error", + Icon = System.Windows.MessageBoxImage.Error, + Button = System.Windows.MessageBoxButton.OK + }); + } + base.OnTransferError(e); + } + protected override void OnTransferReady(TransferReadyEventArgs e) { // set it up to use file xfer diff --git a/Tests/Tester.WPF/app.config b/Tests/Tester.WPF/app.config index 2f7cce7..712761a 100644 --- a/Tests/Tester.WPF/app.config +++ b/Tests/Tester.WPF/app.config @@ -1,3 +1,12 @@ - + - + + + + + + + + + + diff --git a/Tests/Tester.WPF/packages.config b/Tests/Tester.WPF/packages.config index a6523ff..446489e 100644 --- a/Tests/Tester.WPF/packages.config +++ b/Tests/Tester.WPF/packages.config @@ -1,5 +1,7 @@  + + \ No newline at end of file