Commit a76db7a

unknown <mo@.(none)>
2010-01-26 03:54:24
cleaning up
1 parent 62a4b92
product/Boot/boot/container/registration/wire_up_the_presentation_modules.cs
@@ -38,6 +38,7 @@ namespace MoMoney.boot.container.registration
             registry.transient<IFileMenu, FileMenu>();
             registry.transient<IWindowMenu, WindowMenu>();
             registry.transient<IHelpMenu, HelpMenu>();
+            registry.singleton<ISaveChangesCommand,SaveChangesPresenter>();
 
             item
                 .all_types()
product/Presentation/Core/CachedPresenterFactory.cs
@@ -1,4 +1,3 @@
-using Gorilla.Commons.Infrastructure.Logging;
 using gorilla.commons.utility;
 
 namespace MoMoney.Presentation.Core
@@ -21,8 +20,6 @@ namespace MoMoney.Presentation.Core
 
         public Presenter create<Presenter>() where Presenter : IPresenter
         {
-            presenters.each(x => this.log().debug("registered presenter: {0}", x));
-            this.log().debug("creating... {0}", typeof (Presenter));
             var presenter = presenters.find_an_implementation_of<IPresenter, Presenter>();
             view_factory.create_for<Presenter>().attach_to(presenter);
             return presenter;
product/Presentation/Core/CachingViewFactory.cs
@@ -1,3 +1,6 @@
+using System;
+using System.ComponentModel;
+using System.Linq;
 using Gorilla.Commons.Infrastructure.Logging;
 using gorilla.commons.utility;
 using momoney.presentation.views;
@@ -20,9 +23,47 @@ namespace MoMoney.Presentation.Core
 
         public IView<Presenter> create_for<Presenter>() where Presenter : IPresenter
         {
-            views.each(x => this.log().debug("registered view: {0}", x));
-            this.log().debug("creating a view for {0}", typeof (Presenter));
-            return views.find_an_implementation_of<IView, IView<Presenter>>();
+            if (views.all().Any(x => typeof (IView<Presenter>).IsAssignableFrom(x.GetType())))
+            {
+                return views.find_an_implementation_of<IView, IView<Presenter>>();
+            }
+            return new NullView<Presenter>();
+        }
+
+        class NullView<T> : IView<T> where T : IPresenter
+        {
+            public void attach_to(T presenter)
+            {
+            }
+
+            public ControlAction<EventArgs> activated { get; set; }
+
+            public ControlAction<EventArgs> deactivated { get; set; }
+
+            public ControlAction<EventArgs> closed { get; set; }
+
+            public ControlAction<CancelEventArgs> closing { get; set; }
+
+            public IAsyncResult BeginInvoke(Delegate method, object[] args)
+            {
+                return null;
+            }
+
+            public object EndInvoke(IAsyncResult result)
+            {
+                return new object();
+            }
+
+            public object Invoke(Delegate method, object[] args)
+            {
+                return new object();
+            }
+
+            public bool InvokeRequired { get; set; }
+
+            public void Dispose()
+            {
+            }
         }
     }
 }
\ No newline at end of file
product/Presentation/Model/Menu/File/ISaveChangesCommand.cs
@@ -0,0 +1,6 @@
+using gorilla.commons.utility;
+
+namespace MoMoney.Presentation.Model.Menu.File
+{
+    public interface ISaveChangesCommand : ParameterizedCommand<ISaveChangesCallback> {}
+}
\ No newline at end of file
product/Presentation/Model/Menu/File/SaveChangesCommand.cs → product/Presentation/Model/Menu/File/SaveChangesPresenter.cs
@@ -1,5 +1,4 @@
 using System;
-using gorilla.commons.utility;
 using MoMoney.Presentation.Core;
 using momoney.presentation.model.menu.file;
 using MoMoney.Presentation.Model.Projects;
@@ -8,23 +7,14 @@ using MoMoney.Presentation.Views;
 
 namespace MoMoney.Presentation.Model.Menu.File
 {
-    public interface ISaveChangesCommand : ParameterizedCommand<ISaveChangesCallback> {}
-
-    public interface ISaveChangesPresenter : IPresenter
-    {
-        void save();
-        void dont_save();
-        void cancel();
-    }
-
-    public class SaveChangesCommand : ISaveChangesCommand, ISaveChangesPresenter
+    public class SaveChangesPresenter : ISaveChangesCommand, IPresenter
     {
         readonly IProjectController current_project;
         readonly ISaveChangesView view;
         readonly ISaveAsCommand save_as_command;
         ISaveChangesCallback callback;
 
-        public SaveChangesCommand(IProjectController current_project, ISaveChangesView view, ISaveAsCommand save_as_command)
+        public SaveChangesPresenter(IProjectController current_project, ISaveChangesView view, ISaveAsCommand save_as_command)
         {
             this.current_project = current_project;
             this.save_as_command = save_as_command;
product/Presentation/Presenters/AddBillPaymentPresenter.cs
@@ -18,7 +18,6 @@ namespace momoney.presentation.presenters
 
         protected override void present()
         {
-            view.attach_to(this);
             pump
                 .run<IEnumerable<CompanyDTO>, IGetAllCompanysQuery>(view)
                 .run<IEnumerable<BillInformationDTO>, IGetAllBillsQuery>(view);
product/Presentation/Presenters/UnhandledErrorPresenter.cs
@@ -24,6 +24,7 @@ namespace momoney.presentation.presenters
 
         public void notify(UnhandledErrorOccurred message)
         {
+            view.attach_to(this);
             view.display(message.error);
         }
 
product/Presentation/Views/ISaveChangesView.cs
@@ -2,7 +2,7 @@ using MoMoney.Presentation.Model.Menu.File;
 
 namespace momoney.presentation.views
 {
-    public interface ISaveChangesView : IView<ISaveChangesPresenter>
+    public interface ISaveChangesView : IView<SaveChangesPresenter>
     {
         void prompt_user_to_save();
     }
product/Presentation/Winforms/Views/ApplicationShell.cs
@@ -15,7 +15,7 @@ namespace MoMoney.Presentation.Winforms.Views
     public partial class ApplicationShell : ApplicationWindow, IShell
     {
         readonly IDictionary<string, IComponent> regions;
-        ControlAction<EventArgs> closed_action;
+        ControlAction<EventArgs> closed_action = x => { };
 
         public ApplicationShell()
         {
product/Presentation/Winforms/Views/SaveChangesView.cs
@@ -34,7 +34,7 @@ namespace MoMoney.Presentation.Winforms.Views
             Closing += (sender, e) => closing_action(e);
         }
 
-        public void attach_to(ISaveChangesPresenter presenter)
+        public void attach_to(SaveChangesPresenter presenter)
         {
             can_be_closed = false;
             save_action = x => { execute(presenter.save); };
product/Presentation/Winforms/Views/SaveChangesViewSpecs.cs
@@ -10,7 +10,7 @@ namespace MoMoney.Presentation.Winforms.Views
     [Integration]
     public class when_prompted_to_save_changes_to_the_project : concerns_for<SaveChangesView>
     {
-        context c = () => { presenter = an<ISaveChangesPresenter>(); };
+        context c = () => { presenter = an<SaveChangesPresenter>(); };
 
         after_the_sut_has_been_created after = () =>
                                                    {
@@ -18,7 +18,7 @@ namespace MoMoney.Presentation.Winforms.Views
                                                        save_changes_window.attach_to(presenter);
                                                    };
 
-        protected static ISaveChangesPresenter presenter;
+        protected static SaveChangesPresenter presenter;
         protected static SaveChangesView save_changes_window;
     }
 
product/Presentation/Presentation.csproj
@@ -120,6 +120,7 @@
     <Compile Include="model\eventing\FinishedRunningCommand.cs" />
     <Compile Include="model\eventing\StartedRunningCommand.cs" />
     <Compile Include="model\menu\file\ISaveChangesCallback.cs" />
+    <Compile Include="model\menu\file\ISaveChangesCommand.cs" />
     <Compile Include="model\navigation\INavigationTreeVisitor.cs" />
     <Compile Include="model\navigation\ITreeBranch.cs" />
     <Compile Include="model\navigation\ITreeViewToRootNodeMapper.cs" />
@@ -147,7 +148,7 @@
     <Compile Include="model\menu\file\OpenCommandSpecs.cs" />
     <Compile Include="model\menu\file\SaveAsCommand.cs" />
     <Compile Include="model\menu\file\SaveAsCommandSpecs.cs" />
-    <Compile Include="model\menu\file\SaveChangesCommand.cs" />
+    <Compile Include="model\menu\file\SaveChangesPresenter.cs" />
     <Compile Include="model\menu\file\SaveCommand.cs" />
     <Compile Include="model\menu\file\SaveCommandSpecs.cs" />
     <Compile Include="model\menu\help\DisplayInformationAboutTheApplication.cs" />
product/service.infrastructure/eventing/EventAggregator.cs
@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Linq;
 using System.Threading;
 using gorilla.commons.utility;
 
@@ -28,12 +29,14 @@ namespace MoMoney.Service.Infrastructure.Eventing
 
         public void publish<Event>(Event the_event_to_broadcast) where Event : IEvent
         {
-            process(() => subscribers.call_on_each<IEventSubscriber<Event>>(x => x.notify(the_event_to_broadcast)));
+            var current_subscribers = subscribers.ToList();
+            process(() => current_subscribers.call_on_each<IEventSubscriber<Event>>(x => x.notify(the_event_to_broadcast)));
         }
 
         public void publish<T>(Action<T> call) where T : class
         {
-            process(() => subscribers.each(x => x.call_on(call)));
+            var current_subscribers = subscribers.ToList();
+            process(() => current_subscribers.each(x => x.call_on(call)));
         }
 
         public void publish<Event>() where Event : IEvent, new()