Commit e88059a

mokhan <mokhan@ce5e1baf-6525-42e4-a1b2-857ea38da20a>
2009-03-03 16:05:07
implemented the error presenter.
git-svn-id: https://svn.xp-dev.com/svn/mokhan-mo.money@36 ce5e1baf-6525-42e4-a1b2-857ea38da20a
1 parent 64e7f96
trunk/product/MyMoney/Presentation/Model/messages/unhandled_error_occurred.cs
@@ -0,0 +1,15 @@
+using System;
+using MyMoney.Infrastructure.eventing;
+
+namespace MyMoney.Presentation.Model.messages
+{
+    public class unhandled_error_occurred : IEvent
+    {
+        public unhandled_error_occurred(Exception error)
+        {
+            this.error = error;
+        }
+
+        public Exception error { get; private set; }
+    }
+}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Presenters/Shell/UnhandledErrorPresenter.cs
@@ -0,0 +1,33 @@
+using MyMoney.Infrastructure.eventing;
+using MyMoney.Presentation.Core;
+using MyMoney.Presentation.Model.messages;
+using MyMoney.Presentation.Views.Shell;
+
+namespace MyMoney.Presentation.Presenters.Shell
+{
+    public interface IUnhandledErrorPresenter : IPresenter, IEventSubscriber<unhandled_error_occurred>
+    {
+    }
+
+    public class UnhandledErrorPresenter : IUnhandledErrorPresenter
+    {
+        readonly IUnhandledErrorView view;
+        readonly IEventAggregator broker;
+
+        public UnhandledErrorPresenter(IUnhandledErrorView view, IEventAggregator broker)
+        {
+            this.view = view;
+            this.broker = broker;
+        }
+
+        public void run()
+        {
+            broker.subscribe_to(this);
+        }
+
+        public void notify(unhandled_error_occurred message)
+        {
+            view.display(message.error);
+        }
+    }
+}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Presenters/Shell/UnhandledErrorPresenterSpecs.cs
@@ -0,0 +1,44 @@
+using System;
+using jpboodhoo.bdd.contexts;
+using MyMoney.Infrastructure.eventing;
+using MyMoney.Presentation.Model.messages;
+using MyMoney.Presentation.Views.Shell;
+using MyMoney.Testing.spechelpers.contexts;
+using MyMoney.Testing.spechelpers.core;
+
+namespace MyMoney.Presentation.Presenters.Shell
+{
+    public class behaves_like_unhandled_error_presenter :
+        concerns_for<IUnhandledErrorPresenter, UnhandledErrorPresenter>
+    {
+        public override IUnhandledErrorPresenter create_sut()
+        {
+            return new UnhandledErrorPresenter(view, broker);
+        }
+
+        context c = () =>
+                        {
+                            view = the_dependency<IUnhandledErrorView>();
+                            broker = the_dependency<IEventAggregator>();
+                        };
+
+        protected static IUnhandledErrorView view;
+        protected static IEventAggregator broker;
+    }
+
+    public class when_the_presenter_is_run : behaves_like_unhandled_error_presenter
+    {
+        it should_listen_for_any_errors_in_the_application = () => broker.was_told_to(x => x.subscribe_to(sut));
+
+        because b = () => sut.run();
+    }
+
+    public class when_an_error_occurs_in_the_application : behaves_like_unhandled_error_presenter
+    {
+        it should_display_the_error = () => view.was_told_to(x => x.display(error));
+
+        because b = () => sut.notify(new unhandled_error_occurred(error));
+
+        static readonly Exception error = new Exception();
+    }
+}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Views/Shell/IUnhandledErrorView.cs
@@ -0,0 +1,11 @@
+using System;
+using MyMoney.Presentation.Presenters.Shell;
+using MyMoney.Presentation.Views.core;
+
+namespace MyMoney.Presentation.Views.Shell
+{
+    public interface IUnhandledErrorView : IView<IUnhandledErrorPresenter>
+    {
+        void display(Exception exception);
+    }
+}
\ No newline at end of file
trunk/product/MyMoney/Testing/spechelpers/contexts/behaves_like_a_repository.cs
@@ -1,3 +1,4 @@
+using MbUnit.Framework;
 using MyMoney.Domain.Core;
 using MyMoney.Infrastructure.Container;
 using MyMoney.Testing.MetaData;
@@ -6,6 +7,7 @@ namespace MyMoney.Testing.spechelpers.contexts
 {
     [run_in_real_container]
     [Concern(typeof (IRepository))]
+    [Ignore]
     public abstract class behaves_like_a_repository : concerns_for<IRepository>
     {
         public override IRepository create_sut()
trunk/product/MyMoney/windows.ui/bootstrap.cs
@@ -8,9 +8,9 @@ namespace MyMoney.windows.ui
         [STAThread]
         private static void Main()
         {
-            hookup.the<global_error_handling>()
+            hookup
+                .the<global_error_handling>()
                 .then<wire_up_the_container>()
-                //.then<check_for_updates>()
                 .then<start_the_application>()
                 .run();
         }
trunk/product/MyMoney/windows.ui/global_error_handling.cs
@@ -1,6 +1,9 @@
 using System;
 using System.Windows.Forms;
+using MyMoney.Infrastructure.Container;
+using MyMoney.Infrastructure.eventing;
 using MyMoney.Infrastructure.Extensions;
+using MyMoney.Presentation.Model.messages;
 using MyMoney.Utility.Core;
 using MyMoney.Utility.Extensions;
 
@@ -12,8 +15,14 @@ namespace MyMoney.windows.ui
         {
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
-            Application.ThreadException += (sender, e) => e.Exception.add_to_log();
-            AppDomain.CurrentDomain.UnhandledException += ((sender, e) => sender.log().error(e.ExceptionObject.downcast_to<Exception>()));
+            Application.ThreadException += (sender, e) => handle_error(e.Exception);
+            AppDomain.CurrentDomain.UnhandledException += ((sender, e) => handle_error(e.ExceptionObject.downcast_to<Exception>()));
+        }
+
+        static void handle_error(Exception e)
+        {
+            e.add_to_log();
+            resolve.dependency_for<IEventAggregator>().publish(new unhandled_error_occurred(e));
         }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/MyMoney.csproj
@@ -271,6 +271,7 @@
     <Compile Include="Presentation\Model\Menu\tool_bar_item_builder.cs" />
     <Compile Include="Presentation\Model\Menu\window\window_menu.cs" />
     <Compile Include="Presentation\Model\messages\closing_the_application.cs" />
+    <Compile Include="Presentation\Model\messages\unhandled_error_occurred.cs" />
     <Compile Include="Presentation\Model\Navigation\branches\add_bill_payment_branch.cs" />
     <Compile Include="Presentation\Model\Navigation\branches\add_new_income_branch.cs" />
     <Compile Include="Presentation\Model\Navigation\branches\view_all_bills_branch.cs" />
@@ -351,6 +352,8 @@
     <Compile Include="Presentation\Presenters\Shell\TaskTrayPresenter.cs" />
     <Compile Include="Presentation\Presenters\Shell\TitleBarPresenter.cs" />
     <Compile Include="Presentation\Presenters\Shell\TitleBarPresenterSpecs.cs" />
+    <Compile Include="Presentation\Presenters\Shell\UnhandledErrorPresenter.cs" />
+    <Compile Include="Presentation\Presenters\Shell\UnhandledErrorPresenterSpecs.cs" />
     <Compile Include="Presentation\Presenters\Startup\display_the_splash_screen.cs" />
     <Compile Include="Presentation\Presenters\Startup\hide_the_splash_screen.cs" />
     <Compile Include="Presentation\Presenters\Startup\ISplashScreenState.cs" />
@@ -446,6 +449,7 @@
     </Compile>
     <Compile Include="Presentation\Views\Shell\INotificationIconView.cs" />
     <Compile Include="Presentation\Views\Shell\IShell.cs" />
+    <Compile Include="Presentation\Views\Shell\IUnhandledErrorView.cs" />
     <Compile Include="Presentation\Views\Shell\NotificationIconView.cs" />
     <Compile Include="Presentation\Views\Shell\StatusBarView.cs" />
     <Compile Include="Presentation\Views\Shell\TaskTrayMessage.cs" />
@@ -677,7 +681,6 @@
   <ItemGroup>
     <Folder Include="Presentation\Presenters\mapping\" />
     <Folder Include="Presentation\Presenters\Menu\File\" />
-    <Folder Include="Presentation\Presenters\messages\" />
     <Folder Include="Tasks\domain\" />
     <Folder Include="Tasks\Stubs\" />
     <Folder Include="Testing\spechelpers\concerns\" />