Commit 0c8b166

mokhan <mokhan@ce5e1baf-6525-42e4-a1b2-857ea38da20a>
2009-03-16 21:21:02
broke some stuff, but trying to get the progress to show up on the splash screen when registering components.
git-svn-id: https://svn.xp-dev.com/svn/mokhan-mo.money@82 ce5e1baf-6525-42e4-a1b2-857ea38da20a
1 parent a7cacb3
trunk/product/MyMoney/DataAccess/repositories/BillRepository.cs
@@ -7,7 +7,7 @@ namespace MoMoney.DataAccess.repositories
 {
     public class BillRepository : IBillRepository
     {
-        IDatabaseGateway gateway;
+        readonly IDatabaseGateway gateway;
 
         public BillRepository(IDatabaseGateway gateway)
         {
trunk/product/MyMoney/Infrastructure/Container/Windsor/configuration/ComponentRegistrationConfiguration.cs
@@ -1,4 +1,6 @@
+using System;
 using Castle.MicroKernel.Registration;
+using MoMoney.Presentation.Model.interaction;
 using MoMoney.Utility.Core;
 using MoMoney.Utility.Extensions;
 
@@ -10,6 +12,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 +26,8 @@ namespace MoMoney.Infrastructure.Container.Windsor.configuration
                 .then(new ApplyLoggingInterceptor())
                 //.then(new LogComponent())
                 .configure(registration);
+
+            callback.complete("registering: {0}".formatted_using(registration.Implementation));
         }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/Container/Windsor/WindsorContainerFactory.cs
@@ -17,11 +17,6 @@ namespace MoMoney.Infrastructure.Container.Windsor
         readonly IComponentExclusionSpecification criteria_to_satisfy;
         readonly IRegistrationConfiguration configuration;
 
-        public WindsorContainerFactory()
-            : this(new ComponentExclusionSpecification(), new ComponentRegistrationConfiguration())
-        {
-        }
-
         public WindsorContainerFactory(IComponentExclusionSpecification criteria_to_satisfy,
                                        IRegistrationConfiguration configuration)
         {
@@ -61,9 +56,9 @@ namespace MoMoney.Infrastructure.Container.Windsor
         }
     }
 
-    public static class e
+    static public class e
     {
-        public static BasedOnDescriptor LastInterface(this ServiceDescriptor descriptor)
+        static public BasedOnDescriptor LastInterface(this ServiceDescriptor descriptor)
         {
             return descriptor.Select(delegate(Type type, Type baseType)
                                          {
trunk/product/MyMoney/Infrastructure/Container/Windsor/WindsorDependencyRegistry.cs
@@ -12,13 +12,9 @@ namespace MoMoney.Infrastructure.Container.Windsor
     {
         readonly IWindsorContainer underlying_container;
 
-        public WindsorDependencyRegistry() : this(new WindsorContainerFactory())
+        public WindsorDependencyRegistry(IWindsorContainer container)
         {
-        }
-
-        public WindsorDependencyRegistry(IWindsorContainerFactory factory)
-        {
-            underlying_container = factory.create();
+            underlying_container = container;
         }
 
         public Interface get_a<Interface>()
trunk/product/MyMoney/Infrastructure/Container/Windsor/WindsorDependencyRegistrySpecs.cs
@@ -4,6 +4,7 @@ using developwithpassion.bdd.contexts;
 using MoMoney.Testing.MetaData;
 using MoMoney.Testing.spechelpers.contexts;
 using MoMoney.Testing.spechelpers.core;
+using MoMoney.windows.ui;
 
 namespace MoMoney.Infrastructure.Container.Windsor
 {
@@ -17,33 +18,21 @@ namespace MoMoney.Infrastructure.Container.Windsor
 
         public override IDependencyRegistry create_sut()
         {
-            return new WindsorDependencyRegistry();
-        }
-
-        because b = () => { result = sut.get_a<IBird>(); };
-
-        static IBird result;
-    }
-
-    [Concern(typeof (WindsorDependencyRegistry))]
-    public class when_creating_the_windsor_resolver_ : concerns_for<IDependencyRegistry>
-    {
-        it should_leverage_the_factory_to_create_the_underlying_container = () => factory.was_told_to(f => f.create());
-
-        public override IDependencyRegistry create_sut()
-        {
-            return new WindsorDependencyRegistry(factory);
+            return get_the.registry(null);
+            //return new WindsorDependencyRegistry(new WindsorContainerFactory().create());
         }
 
         context c = () =>
                         {
-                            var container = an<IWindsorContainer>();
-                            factory = an<IWindsorContainerFactory>();
-                            factory.is_told_to(f => f.create()).it_will_return(container);
+                            var container = the_dependency<IWindsorContainer>();
+                            var bird = new BlueBird();
+                            container.is_told_to(x => x.Resolve<IBird>()).it_will_return(bird);
                         };
 
+        because b = () => { result = sut.get_a<IBird>(); };
+
 
-        static IWindsorContainerFactory factory;
+        static IBird result;
     }
 
     [Singleton]
trunk/product/MyMoney/Infrastructure/Container/Resolve.cs
@@ -2,28 +2,30 @@ using System;
 
 namespace MoMoney.Infrastructure.Container
 {
-    public static class resolve
+    static public class resolve
     {
-        private static IDependencyRegistry underlying_registry;
-        private static bool initialized;
+        static IDependencyRegistry underlying_registry;
+        static bool initialized;
 
-        public static void initialize_with(IDependencyRegistry registry)
+        static public void initialize_with(IDependencyRegistry registry)
         {
             underlying_registry = registry;
             initialized = registry != null;
         }
 
-        public static DependencyToResolve dependency_for<DependencyToResolve>()
+        static public DependencyToResolve dependency_for<DependencyToResolve>()
         {
-            try {
+            try
+            {
                 return underlying_registry.get_a<DependencyToResolve>();
             }
-            catch (Exception e) {
+            catch (Exception e)
+            {
                 throw new dependency_resolution_exception<DependencyToResolve>(e);
             }
         }
 
-        public static bool is_initialized()
+        static public bool is_initialized()
         {
             return initialized;
         }
trunk/product/MyMoney/Presentation/Presenters/Commands/display_the_splash_screen.cs
@@ -1,6 +1,4 @@
-using MoMoney.Infrastructure.Threading;
 using MoMoney.Presentation.Presenters.Startup;
-using MoMoney.Presentation.Views.Startup;
 using MoMoney.Utility.Core;
 
 namespace MoMoney.Presentation.Presenters.Commands
@@ -9,11 +7,6 @@ namespace MoMoney.Presentation.Presenters.Commands
     {
         readonly ISplashScreenPresenter presenter;
 
-        public display_the_splash_screen()
-            : this(new SplashScreenPresenter(new IntervalTimer(new TimerFactory()), new SplashScreenView()))
-        {
-        }
-
         public display_the_splash_screen(ISplashScreenPresenter presenter)
         {
             this.presenter = presenter;
trunk/product/MyMoney/Presentation/Presenters/Startup/SplashScreenPresenter.cs
@@ -1,18 +1,19 @@
 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
     {
-        private readonly ITimer timer;
-        private readonly ISplashScreenView view;
-        private ISplashScreenState current_state;
+        readonly ITimer timer;
+        readonly ISplashScreenView view;
+        ISplashScreenState current_state;
 
         public SplashScreenPresenter(ITimer timer, ISplashScreenView view)
         {
@@ -35,5 +36,10 @@ namespace MoMoney.Presentation.Presenters.Startup
         {
             current_state.update();
         }
+
+        public void complete(notification_message item)
+        {
+            view.update_progress(item);
+        }
     }
 }
\ No newline at end of file
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 update_progress(notification_message message);
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Presentation/Views/Startup/SplashScreenView.cs
@@ -1,4 +1,5 @@
 using System.Windows.Forms;
+using MoMoney.Presentation.Model.interaction;
 using MoMoney.Presentation.Resources;
 using MoMoney.Presentation.Views.core;
 
@@ -6,28 +7,36 @@ namespace MoMoney.Presentation.Views.Startup
 {
     public partial class SplashScreenView : ApplicationWindow, ISplashScreenView
     {
+        readonly TextBox progress_textbox;
+
         public SplashScreenView()
         {
             InitializeComponent();
             ApplyWindowStyles();
+
+            progress_textbox = new TextBox();
+            Controls.Add(progress_textbox);
         }
 
         void ApplyWindowStyles()
         {
-            BackgroundImage = ApplicationImages.Splash;
-            FormBorderStyle = FormBorderStyle.None;
-            StartPosition = FormStartPosition.CenterScreen;
-            if (null != BackgroundImage)
-            {
-                ClientSize = BackgroundImage.Size;
-            }
-            TopMost = true;
-            Opacity = 0;
+            on_ui_thread(() =>
+                             {
+                                 BackgroundImage = ApplicationImages.Splash;
+                                 FormBorderStyle = FormBorderStyle.None;
+                                 StartPosition = FormStartPosition.CenterScreen;
+                                 if (null != BackgroundImage)
+                                 {
+                                     ClientSize = BackgroundImage.Size;
+                                 }
+                                 TopMost = true;
+                                 Opacity = 0;
+                             });
         }
 
         public void increment_the_opacity()
         {
-            Opacity += 0.2;
+            on_ui_thread(() => { Opacity += 0.2; });
         }
 
         public double current_opacity()
@@ -37,18 +46,26 @@ namespace MoMoney.Presentation.Views.Startup
 
         public void decrement_the_opacity()
         {
-            Opacity -= .1;
+            on_ui_thread(() => { Opacity -= .1; });
         }
 
         public void close_the_screen()
         {
-            Close();
-            Dispose();
+            on_ui_thread(() =>
+                             {
+                                 Close();
+                                 Dispose();
+                             });
+        }
+
+        public void update_progress(notification_message message)
+        {
+            on_ui_thread(() => { progress_textbox.Text = message; });
         }
 
         public void display()
         {
-            Show();
+            on_ui_thread(Show);
         }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Presentation/Views/updates/CheckForUpdatesView.cs
@@ -50,6 +50,11 @@ namespace MoMoney.Presentation.Views.updates
 
         public void downloaded(Percent percentage_complete)
         {
+            //var bar = new ProgressBar {Visible = true, Minimum = 1, Value = 1};
+            //while (true)
+            //{
+            //    if (bar.Value.Equals(percentage_complete)) { }
+            //}
         }
 
         public void update_complete()
trunk/product/MyMoney/Testing/MetaData/run_in_real_container.cs
@@ -3,6 +3,7 @@ using MbUnit.Core.Framework;
 using MbUnit.Core.Invokers;
 using MoMoney.Infrastructure.Container;
 using MoMoney.Infrastructure.Container.Windsor;
+using MoMoney.windows.ui;
 
 namespace MoMoney.Testing.MetaData
 {
@@ -24,7 +25,8 @@ namespace MoMoney.Testing.MetaData
         {
             try
             {
-                resolve.initialize_with(new WindsorDependencyRegistry());
+                //resolve.initialize_with(new WindsorDependencyRegistry());
+                get_the.registry(null);
                 return Invoker.Execute(o, args);
             }
             finally
trunk/product/MyMoney/Testing/spechelpers/contexts/behaves_like_a_repository.cs
@@ -1,15 +1,14 @@
 using developwithpassion.bdd.contexts;
-using MbUnit.Framework;
 using MoMoney.DataAccess.core;
 using MoMoney.Infrastructure.Container;
 using MoMoney.Infrastructure.Container.Windsor;
 using MoMoney.Testing.MetaData;
+using MoMoney.windows.ui;
 
 namespace MoMoney.Testing.spechelpers.contexts
 {
     //[run_in_real_container]
     [Concern(typeof (IDatabaseGateway))]
-    [Ignore]
     public abstract class behaves_like_a_repository : concerns_for<IDatabaseGateway>
     {
         public override IDatabaseGateway create_sut()
@@ -17,7 +16,7 @@ namespace MoMoney.Testing.spechelpers.contexts
             return resolve.dependency_for<IDatabaseGateway>();
         }
 
-        before_all_observations all = () => resolve.initialize_with(new WindsorDependencyRegistry());
+        before_all_observations all = () => get_the.registry(null);
 
         after_all_observations after_all = () => resolve.initialize_with(null);
     }
trunk/product/MyMoney/windows.ui/get_the.cs
@@ -0,0 +1,34 @@
+using MoMoney.Infrastructure.Container.Windsor;
+using MoMoney.Infrastructure.Container.Windsor.configuration;
+using MoMoney.Presentation.Model.interaction;
+using MoMoney.Utility.Core;
+
+namespace MoMoney.windows.ui
+{
+    static public class get_the
+    {
+        static WindsorDependencyRegistry registry_resolver;
+
+        static public WindsorDependencyRegistry registry(ICallback<notification_message> callback)
+        {
+            if (null == registry_resolver)
+            {
+                var exclusions = new ComponentExclusionSpecification();
+                var registration =
+                    new ComponentRegistrationConfiguration(callback ?? new EmptyCallback<notification_message>());
+                var container = new WindsorContainerFactory(exclusions, registration).create();
+                registry_resolver = new WindsorDependencyRegistry(container);
+                registry_resolver.singleton(container);
+                return registry_resolver;
+            }
+            return registry_resolver;
+        }
+    }
+
+    public class EmptyCallback<T> : ICallback<T>
+    {
+        public void complete(T item)
+        {
+        }
+    }
+}
\ No newline at end of file
trunk/product/MyMoney/windows.ui/wire_up_the_container.cs
@@ -1,8 +1,12 @@
 using MoMoney.Infrastructure.Container.Windsor;
 using MoMoney.Infrastructure.Extensions;
-using MoMoney.Presentation.Presenters.Commands;
+using MoMoney.Infrastructure.Threading;
+using MoMoney.Presentation.Model.interaction;
+using MoMoney.Presentation.Presenters.Startup;
+using MoMoney.Presentation.Views.Startup;
 using MoMoney.Utility.Core;
 using MoMoney.Utility.Extensions;
+using display_the_splash_screen=MoMoney.Presentation.Presenters.Commands.display_the_splash_screen;
 
 namespace MoMoney.windows.ui
 {
@@ -10,9 +14,10 @@ namespace MoMoney.windows.ui
     {
         public void run()
         {
-            using (new display_the_splash_screen().on_a_background_thread())
+            var presenter = get_presenter();
+            using (new display_the_splash_screen(presenter).on_a_background_thread())
             {
-                var registry = new WindsorDependencyRegistry();
+                var registry = get_registry(presenter);
                 new wire_up_the_core_services_into_the(registry)
                     .then(new wire_up_the_mappers_in_to_the(registry))
                     .then(new wire_up_the_views_in_to_the(registry))
@@ -20,5 +25,15 @@ namespace MoMoney.windows.ui
                     .run();
             }
         }
+
+        ISplashScreenPresenter get_presenter()
+        {
+            return new SplashScreenPresenter(new IntervalTimer(new TimerFactory()), new SplashScreenView());
+        }
+
+        WindsorDependencyRegistry get_registry(ICallback<notification_message> callback)
+        {
+            return get_the.registry(callback);
+        }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/MyMoney.csproj
@@ -637,6 +637,7 @@
     <Compile Include="Utility\Extensions\TypeExtensionsSpecs.cs" />
     <Compile Include="Utility\Extensions\visitor_extensions.cs" />
     <Compile Include="windows.ui\check_for_updates.cs" />
+    <Compile Include="windows.ui\get_the.cs" />
     <Compile Include="windows.ui\hookup.cs" />
     <Compile Include="Presentation\Model\Menu\ISubMenu.cs" />
     <Compile Include="Utility\Core\IRegistry.cs" />