Commit b1a32ff

mokhan <mokhan@ce5e1baf-6525-42e4-a1b2-857ea38da20a>
2009-03-20 04:21:47
trying to update the UI with progress of the application startup.
git-svn-id: https://svn.xp-dev.com/svn/mokhan-mo.money@87 ce5e1baf-6525-42e4-a1b2-857ea38da20a
1 parent ddfb1da
trunk/product/MyMoney/boot/container/wire_up_the_container.cs
@@ -3,6 +3,7 @@ using Castle.Windsor;
 using MoMoney.Infrastructure.Container.Windsor;
 using MoMoney.Infrastructure.Container.Windsor.configuration;
 using MoMoney.Infrastructure.Extensions;
+using MoMoney.Presentation.Model.interaction;
 using MoMoney.Utility.Core;
 using MoMoney.Utility.Extensions;
 using MoMoney.windows.ui;
@@ -11,6 +12,17 @@ namespace MoMoney.boot.container
 {
     internal class wire_up_the_container : ICommand
     {
+        readonly Func<ICallback<notification_message>> callback;
+
+        public wire_up_the_container() : this(() => new EmptyCallback<notification_message>())
+        {
+        }
+
+        public wire_up_the_container(Func<ICallback<notification_message>> callback)
+        {
+            this.callback = callback;
+        }
+
         public void run()
         {
             this.log().debug("initializing container");
@@ -20,7 +32,7 @@ namespace MoMoney.boot.container
 
             var registry = new WindsorDependencyRegistry(container);
             var specification = new ComponentExclusionSpecification();
-            var configuration = new ComponentRegistrationConfiguration();
+            var configuration = new ComponentRegistrationConfiguration(callback());
 
             new wire_up_the_essential_services_into_the(registry)
                 .then(new wire_up_the_mappers_in_to_the(registry))
trunk/product/MyMoney/boot/bootstrap.cs
@@ -1,9 +1,13 @@
 using System;
 using MoMoney.boot.container;
 using MoMoney.Infrastructure.Extensions;
-using MoMoney.Presentation.Presenters.Commands;
+using MoMoney.Infrastructure.Logging;
+using MoMoney.Infrastructure.Threading;
+using MoMoney.Presentation.Presenters.Startup;
+using MoMoney.Presentation.Views.Startup;
 using MoMoney.Utility.Extensions;
 using MoMoney.windows.ui;
+using display_the_splash_screen=MoMoney.Presentation.Presenters.Commands.display_the_splash_screen;
 
 namespace MoMoney.boot
 {
@@ -12,14 +16,23 @@ namespace MoMoney.boot
         [STAThread]
         static void Main()
         {
-            var startup_screen = new display_the_splash_screen().on_a_background_thread();
+            Func<ISplashScreenPresenter> presenter = () => bootstrap.presenter();
+            presenter = presenter.memorize();
+
+            var startup_screen = new display_the_splash_screen(presenter).on_a_background_thread();
             hookup
                 .the<global_error_handling>()
                 .then(startup_screen)
-                .then<wire_up_the_container>()
+                .then(new wire_up_the_container(() => presenter()))
                 .then(startup_screen.Dispose)
                 .then<start_the_application>()
                 .run();
         }
+
+        static SplashScreenPresenter presenter()
+        {
+            Log.For(typeof (bootstrap)).debug("creating presenter");
+            return new SplashScreenPresenter(new IntervalTimer(new TimerFactory()), new SplashScreenView());
+        }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/boot/global_error_handling.cs
@@ -9,7 +9,7 @@ using MoMoney.Presentation.Model.messages;
 using MoMoney.Utility.Core;
 using MoMoney.Utility.Extensions;
 
-namespace MoMoney.windows.ui
+namespace MoMoney.boot
 {
     internal class global_error_handling : ICommand
     {
trunk/product/MyMoney/Infrastructure/Container/Windsor/configuration/ComponentRegistrationConfiguration.cs
@@ -1,4 +1,5 @@
 using Castle.MicroKernel.Registration;
+using MoMoney.Presentation.Model.interaction;
 using MoMoney.Utility.Core;
 using MoMoney.Utility.Extensions;
 
@@ -10,6 +11,13 @@ namespace MoMoney.Infrastructure.Container.Windsor.configuration
 
     public class ComponentRegistrationConfiguration : IRegistrationConfiguration
     {
+        readonly ICallback<notification_message> callback;
+
+        public ComponentRegistrationConfiguration(ICallback<notification_message> callback)
+        {
+            this.callback = callback;
+        }
+
         public void configure(ComponentRegistration registration)
         {
             new RegisterComponentContract()
@@ -17,6 +25,7 @@ namespace MoMoney.Infrastructure.Container.Windsor.configuration
                 .then(new ApplyLoggingInterceptor())
                 //.then(new LogComponent())
                 .configure(registration);
+            callback.complete("registered:{0}".formatted_using(registration.Implementation));
         }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Presentation/Presenters/Commands/display_the_splash_screen.cs
@@ -1,9 +1,6 @@
 using System;
-using MoMoney.Infrastructure.Threading;
 using MoMoney.Presentation.Presenters.Startup;
-using MoMoney.Presentation.Views.Startup;
 using MoMoney.Utility.Core;
-using MoMoney.Utility.Extensions;
 
 namespace MoMoney.Presentation.Presenters.Commands
 {
@@ -11,14 +8,14 @@ namespace MoMoney.Presentation.Presenters.Commands
     {
         readonly Func<ISplashScreenPresenter> presenter;
 
-        public display_the_splash_screen()
-            : this(() => new SplashScreenPresenter(new IntervalTimer(new TimerFactory()), new SplashScreenView()))
-        {
-        }
+        //public display_the_splash_screen()
+        //    : this(() => new SplashScreenPresenter(new IntervalTimer(new TimerFactory()), new SplashScreenView()))
+        //{
+        //}
 
         public display_the_splash_screen(Func<ISplashScreenPresenter> presenter)
         {
-            this.presenter = presenter.memorize();
+            this.presenter = presenter;
         }
 
         public void run()
trunk/product/MyMoney/Presentation/Presenters/Startup/SplashScreenPresenter.cs
@@ -1,14 +1,15 @@
 using MoMoney.Infrastructure.Threading;
+using MoMoney.Presentation.Model.interaction;
 using MoMoney.Presentation.Views.Startup;
 using MoMoney.Utility.Core;
 
 namespace MoMoney.Presentation.Presenters.Startup
 {
-    public interface ISplashScreenPresenter : IDisposableCommand, ITimerClient
+    public interface ISplashScreenPresenter : IDisposableCommand, ITimerClient, ICallback<notification_message>
     {
     }
 
-    public class SplashScreenPresenter : ISplashScreenPresenter
+    internal class SplashScreenPresenter : ISplashScreenPresenter
     {
         readonly ITimer timer;
         readonly ISplashScreenView view;
@@ -35,5 +36,10 @@ namespace MoMoney.Presentation.Presenters.Startup
         {
             current_state.update();
         }
+
+        public void complete(notification_message item)
+        {
+            view.notify(item);
+        }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Presentation/Presenters/Startup/SplashScreenPresenterSpecs.cs
@@ -9,12 +9,12 @@ using MoMoney.Testing.spechelpers.core;
 namespace MoMoney.Presentation.Presenters.Startup
 {
     [Concern(typeof (SplashScreenPresenter))]
-    public abstract class behaves_like_splash_screen_presenter : concerns_for<ISplashScreenPresenter, SplashScreenPresenter>
+    public abstract class behaves_like_splash_screen_presenter : concerns_for<ISplashScreenPresenter>
     {
-        //public override ISplashScreenPresenter create_sut()
-        //{
-        //    return new splash_screen_presenter(timer, view);
-        //}
+        public override ISplashScreenPresenter create_sut()
+        {
+            return new SplashScreenPresenter(timer, view);
+        }
 
         context c = () =>
                         {
trunk/product/MyMoney/Presentation/Views/Startup/ISplashScreenView.cs
@@ -1,3 +1,5 @@
+using MoMoney.Presentation.Model.interaction;
+
 namespace MoMoney.Presentation.Views.Startup
 {
     public interface ISplashScreenView
@@ -7,5 +9,6 @@ namespace MoMoney.Presentation.Views.Startup
         void decrement_the_opacity();
         void close_the_screen();
         void display();
+        void notify(notification_message message);
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Presentation/Views/Startup/SplashScreenView.cs
@@ -1,6 +1,7 @@
 using System;
 using System.Windows.Forms;
 using MoMoney.Infrastructure.Extensions;
+using MoMoney.Presentation.Model.interaction;
 using MoMoney.Presentation.Resources;
 using MoMoney.Presentation.Views.core;
 
@@ -52,5 +53,17 @@ namespace MoMoney.Presentation.Views.Startup
         {
             on_ui_thread(Show);
         }
+
+        public void notify(notification_message message)
+        {
+            this.log().debug("notifying the view");
+            on_ui_thread(() =>
+                             {
+                                 this.log().debug(message);
+                                 progress_textbox.Text = message;
+                                 progress_bar.PerformStep();
+                                 progress_bar.Text = message;
+                             });
+        }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Presentation/Views/Startup/SplashScreenView.Designer.cs
@@ -27,21 +27,43 @@ namespace MoMoney.Presentation.Views.Startup {
         /// </summary>
         private void InitializeComponent()
         {
+            this.progress_bar = new System.Windows.Forms.ProgressBar();
+            this.progress_textbox = new System.Windows.Forms.TextBox();
             this.SuspendLayout();
             // 
+            // progress_bar
+            // 
+            this.progress_bar.Location = new System.Drawing.Point(5, 222);
+            this.progress_bar.Name = "progress_bar";
+            this.progress_bar.Size = new System.Drawing.Size(271, 27);
+            this.progress_bar.TabIndex = 0;
+            // 
+            // progress_textbox
+            // 
+            this.progress_textbox.Location = new System.Drawing.Point(13, 183);
+            this.progress_textbox.Name = "progress_textbox";
+            this.progress_textbox.Size = new System.Drawing.Size(257, 22);
+            this.progress_textbox.TabIndex = 1;
+            // 
             // SplashScreenView
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(282, 255);
+            this.Controls.Add(this.progress_textbox);
+            this.Controls.Add(this.progress_bar);
             this.Name = "SplashScreenView";
             this.ShowIcon = false;
             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
             this.Text = "SplashScreenView";
             this.ResumeLayout(false);
+            this.PerformLayout();
 
         }
 
         #endregion
+
+        private System.Windows.Forms.ProgressBar progress_bar;
+        private System.Windows.Forms.TextBox progress_textbox;
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Testing/spechelpers/contexts/concerns.cs
@@ -7,18 +7,22 @@ namespace MoMoney.Testing.spechelpers.contexts
     public abstract class concerns_for<Contract> : observations_for_a_sut_without_a_contract<Contract>,
                                                    IHideObjectMembers
     {
+        protected static T when_the<T>(T item)
+        {
+            return item;
+        }
     }
 
     public abstract class concerns_for<Contract, Implementation> :
         observations_for_a_sut_with_a_contract<Contract, Implementation>, IHideObjectMembers
         where Implementation : Contract
     {
-        static protected T when_the<T>(T item)
+        protected static T when_the<T>(T item)
         {
             return item;
         }
 
-        static protected T dependency<T>() where T : class
+        protected static T dependency<T>() where T : class
         {
             return MockRepository.GenerateMock<T>();
         }
@@ -26,12 +30,12 @@ namespace MoMoney.Testing.spechelpers.contexts
 
     public abstract class concerns : observations_for_a_static_sut, IHideObjectMembers
     {
-        static protected T dependency<T>() where T : class
+        protected static T dependency<T>() where T : class
         {
             return MockRepository.GenerateMock<T>();
         }
 
-        static public T when_the<T>(T item)
+        public static T when_the<T>(T item)
         {
             return item;
         }
trunk/product/MyMoney/Utility/Core/EmptyCallback.cs
@@ -0,0 +1,13 @@
+namespace MoMoney.Utility.Core
+{
+    public class EmptyCallback<T> : ICallback<T>, ICallback
+    {
+        public void complete(T item)
+        {
+        }
+
+        public void complete()
+        {
+        }
+    }
+}
\ No newline at end of file
trunk/product/MyMoney/Utility/Extensions/func_extensions.cs
@@ -7,12 +7,20 @@ namespace MoMoney.Utility.Extensions
         public static Func<T> memorize<T>(this Func<T> item) where T : class
         {
             T the_implementation = null;
-            return () => {
-                       if (null == the_implementation) {
-                           the_implementation = item();
-                       }
-                       return the_implementation;
-                   };
+            return () =>
+                       {
+                           if (null == the_implementation)
+                           {
+                               lock (typeof (func_extensions))
+                               {
+                                   if (null == the_implementation)
+                                   {
+                                       the_implementation = item();
+                                   }
+                               }
+                           }
+                           return the_implementation;
+                       };
         }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/MyMoney.csproj
@@ -544,6 +544,7 @@
     <Compile Include="Utility\Core\chained_mapper.cs" />
     <Compile Include="Utility\Core\and_specification.cs" />
     <Compile Include="Utility\Core\DisposableCommand.cs" />
+    <Compile Include="Utility\Core\EmptyCallback.cs" />
     <Compile Include="Utility\Core\empty_command.cs" />
     <Compile Include="Utility\Core\IBuilder.cs" />
     <Compile Include="Utility\Core\ICallback.cs" />