Commit 9b6122f

mokhan <mokhan@ce5e1baf-6525-42e4-a1b2-857ea38da20a>
2009-04-06 03:53:50
broken...
git-svn-id: https://svn.xp-dev.com/svn/mokhan-mo.money@144 ce5e1baf-6525-42e4-a1b2-857ea38da20a
1 parent ef7433b
Changed files (12)
trunk
product
trunk/product/MyMoney/DataAccess/repositories/BillRepositorySpecs.cs
@@ -12,7 +12,7 @@ namespace MoMoney.DataAccess.repositories
     {
         it should_return_all_the_bills_in_the_database = () => results.should_contain(first_bill);
 
-        context c = () => { first_bill = new Bill(new Company("mokhan.ca"), new Money(1, 00), DateTime.Now); };
+        context c = () => { first_bill = new Bill(new Company(), new Money(1, 00), DateTime.Now); };
 
         because b = () =>
                         {
trunk/product/MyMoney/Infrastructure/transactions2/ConnectionFactory.cs
@@ -1,4 +1,6 @@
 using Db4objects.Db4o;
+using Db4objects.Db4o.Config;
+using Db4objects.Db4o.Events;
 using MoMoney.Infrastructure.Extensions;
 using MoMoney.Presentation.Model.Projects;
 
@@ -23,7 +25,19 @@ namespace MoMoney.Infrastructure.transactions2
             this.log().debug("opening connection to: {0}", the_path_to_the_database_file);
             var configuration = Db4oFactory.NewConfiguration();
             setup.configure(configuration);
-            return Db4oFactory.OpenFile(configuration, the_path_to_the_database_file.path);
+
+            return get_container(the_path_to_the_database_file, configuration);
+        }
+
+        IObjectContainer get_container(IFile the_path_to_the_database_file, IConfiguration configuration)
+        {
+            var container = Db4oFactory.OpenFile(configuration, the_path_to_the_database_file.path);
+            var registry = EventRegistryFactory.ForObjectContainer(container);
+
+            registry.ClassRegistered += (sender, args) => this.log().debug("class registered: {0}", args);
+            registry.Instantiated += (sender, args) => this.log().debug("class instantiated: {0}", args.Object);
+
+            return container;
         }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/transactions2/DatabaseConfiguration.cs
@@ -9,6 +9,7 @@ namespace MoMoney.Infrastructure.transactions2
     public interface IDatabaseConfiguration
     {
         IFile path_to_database();
+        void change_path_to(IFile file);
     }
 
     public class DatabaseConfiguration : IDatabaseConfiguration, IEventSubscriber<NewProjectOpened>
@@ -26,6 +27,12 @@ namespace MoMoney.Infrastructure.transactions2
             lock (mutex) return path;
         }
 
+        public void change_path_to(IFile file)
+        {
+            path = new ApplicationFile(Path.GetTempFileName());
+            file.copy_to(path.path);
+        }
+
         public void notify(NewProjectOpened message)
         {
             within_lock(() => path = new ApplicationFile(Path.GetTempFileName()));
trunk/product/MyMoney/Presentation/Model/Projects/CurrentProject.cs
@@ -1,6 +1,5 @@
-using MoMoney.DataAccess.db40;
 using MoMoney.Infrastructure.eventing;
-using MoMoney.Infrastructure.transactions;
+using MoMoney.Infrastructure.transactions2;
 using MoMoney.Presentation.Model.messages;
 using MoMoney.Utility.Extensions;
 
@@ -19,19 +18,19 @@ namespace MoMoney.Presentation.Model.Projects
         bool is_open();
     }
 
-    public class CurrentProject : IProject
+    public class CurrentProject : IProject, IEventSubscriber<UnsavedChangesEvent>
     {
         readonly IEventAggregator broker;
-        readonly IUnitOfWorkRegistry registry;
-        readonly ISessionContext context;
+        IDatabaseConfiguration configuration;
         IFile current_file;
         bool is_project_open = false;
+        bool unsaved_changes = false;
 
-        public CurrentProject(IEventAggregator broker, IUnitOfWorkRegistry registry, ISessionContext context)
+        public CurrentProject(IEventAggregator broker, IDatabaseConfiguration configuration)
         {
             this.broker = broker;
-            this.registry = registry;
-            this.context = context;
+            this.configuration = configuration;
+            broker.subscribe(this);
         }
 
         public string name()
@@ -42,7 +41,6 @@ namespace MoMoney.Presentation.Model.Projects
         public void start_new_project()
         {
             close_project();
-            context.close_session_to(current_file);
             is_project_open = true;
             current_file = null;
             broker.publish(new NewProjectOpened(name()));
@@ -52,26 +50,23 @@ namespace MoMoney.Presentation.Model.Projects
         {
             if (!file.does_the_file_exist()) return;
             close_project();
+            configuration.change_path_to(file);
             current_file = file;
             is_project_open = true;
-            context.start_session_for(current_file);
             broker.publish(new NewProjectOpened(name()));
         }
 
         public void save_changes()
         {
             ensure_that_a_path_to_save_to_has_been_specified();
-            registry.commit_all();
-            registry.Dispose();
-            context.commit_current_session();
+            configuration.path_to_database().copy_to(current_file.path);
+            unsaved_changes = false;
             broker.publish<SavedChangesEvent>();
         }
 
         public void save_project_to(IFile new_file)
         {
             if (new_file.path.is_blank()) return;
-
-            context.start_session_for(new_file);
             current_file = new_file;
             save_changes();
         }
@@ -79,8 +74,6 @@ namespace MoMoney.Presentation.Model.Projects
         public void close_project()
         {
             if (!is_project_open) return;
-            registry.Dispose();
-            context.close_session_to(current_file);
             is_project_open = false;
             current_file = null;
             broker.publish<ClosingProjectEvent>();
@@ -93,7 +86,7 @@ namespace MoMoney.Presentation.Model.Projects
 
         public bool has_unsaved_changes()
         {
-            return registry.has_changes_to_commit();
+            return unsaved_changes;
         }
 
         public bool is_open()
@@ -108,5 +101,10 @@ namespace MoMoney.Presentation.Model.Projects
                 throw new FileNotSpecifiedException();
             }
         }
+
+        public void notify(UnsavedChangesEvent message)
+        {
+            unsaved_changes = true;
+        }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Presentation/Model/Projects/file.cs
@@ -1,4 +1,3 @@
-using System;
 using System.IO;
 
 namespace MoMoney.Presentation.Model.Projects
@@ -7,6 +6,7 @@ namespace MoMoney.Presentation.Model.Projects
     {
         string path { get; }
         bool does_the_file_exist();
+        void copy_to(string path);
     }
 
     internal class ApplicationFile : IFile
@@ -23,6 +23,11 @@ namespace MoMoney.Presentation.Model.Projects
             return !string.IsNullOrEmpty(path) && File.Exists(path);
         }
 
+        public void copy_to(string other_path)
+        {
+            File.Copy(path, other_path, true);
+        }
+
         public static implicit operator ApplicationFile(string file_path)
         {
             return new ApplicationFile(file_path);
trunk/product/MyMoney/Presentation/Presenters/AddCompanyPresenter.cs
@@ -1,4 +1,6 @@
+using System.Collections.Generic;
 using System.Linq;
+using MoMoney.Domain.accounting.billing;
 using MoMoney.Presentation.Core;
 using MoMoney.Presentation.Presenters.billing.dto;
 using MoMoney.Presentation.Views;
@@ -30,7 +32,8 @@ namespace MoMoney.Presentation.Presenters
         public void run()
         {
             view.attach_to(this);
-            view.display(tasks.all_companys());
+            view.run(tasks.all_companys());
+            //pump.run<IEnumerable<ICompany>, IGetAllCompanysQuery>(view);
         }
 
         public void submit(RegisterNewCompany dto)
@@ -42,8 +45,8 @@ namespace MoMoney.Presentation.Presenters
             else
             {
                 pump.run<IRegisterNewCompanyCommand, RegisterNewCompany>(dto);
-                //tasks.register_new_company(dto);
-                view.display(tasks.all_companys());
+                //pump.run<IEnumerable<ICompany>, IGetAllCompanysQuery>(view);
+                view.run(tasks.all_companys());
             }
         }
 
trunk/product/MyMoney/Presentation/Views/AddCompanyView.cs
@@ -59,7 +59,7 @@ namespace MoMoney.Presentation.Views
             ux_cancel_button.Click += (x, y) => Dispose();
         }
 
-        public void display(IEnumerable<ICompany> companies)
+        public void run(IEnumerable<ICompany> companies)
         {
             ux_companys_listing.DataSource = companies.databind();
 
trunk/product/MyMoney/Presentation/Views/IAddCompanyView.cs
@@ -3,11 +3,12 @@ using MoMoney.Domain.accounting.billing;
 using MoMoney.Presentation.Model.interaction;
 using MoMoney.Presentation.Presenters;
 using MoMoney.Presentation.Views.core;
+using MoMoney.Utility.Core;
 
 namespace MoMoney.Presentation.Views
 {
-    public interface IAddCompanyView : IDockedContentView, INotification, IView<IAddCompanyPresenter>
+    public interface IAddCompanyView : IDockedContentView, INotification, IView<IAddCompanyPresenter>, ICallback<IEnumerable<ICompany>>
     {
-        void display(IEnumerable<ICompany> companies);
+        //void run(IEnumerable<ICompany> companies);
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Tasks/application/GetAllCompanysQuery.cs
@@ -0,0 +1,26 @@
+using System.Collections.Generic;
+using MoMoney.Domain.accounting.billing;
+using MoMoney.Domain.repositories;
+using MoMoney.Utility.Core;
+
+namespace MoMoney.Tasks.application
+{
+    public interface IGetAllCompanysQuery : IQuery<IEnumerable<ICompany>>
+    {
+    }
+
+    public class GetAllCompanysQuery : IGetAllCompanysQuery
+    {
+        readonly ICompanyRepository companys;
+
+        public GetAllCompanysQuery(ICompanyRepository companys)
+        {
+            this.companys = companys;
+        }
+
+        public IEnumerable<ICompany> fetch()
+        {
+            return companys.all();
+        }
+    }
+}
\ No newline at end of file
trunk/product/MyMoney/Tasks/infrastructure/core/CommandPump.cs
@@ -10,6 +10,7 @@ namespace MoMoney.Tasks.infrastructure.core
         void run<Command>(Command command) where Command : ICommand;
         void run<Command, T>(T input) where Command : IParameterizedCommand<T>;
         void run<T>(ICallback<T> item, IQuery<T> query);
+        void run<Output, Query>(ICallback<Output> item) where Query : IQuery<Output>;
     }
 
     public class CommandPump : ICommandPump
@@ -44,5 +45,10 @@ namespace MoMoney.Tasks.infrastructure.core
         {
             run(factory.create_for(item, query));
         }
+
+        public void run<Output, Query>(ICallback<Output> item) where Query : IQuery<Output>
+        {
+            run(factory.create_for(item, registry.get_a<Query>()));
+        }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Utility/Extensions/string_extensions.cs → trunk/product/MyMoney/Utility/Extensions/StringExtensions.cs
@@ -1,10 +1,10 @@
 namespace MoMoney.Utility.Extensions
 {
-    public static class string_extensions
+    public static class StringExtensions
     {
-        public static string formatted_using(this string formattedString, params object[] arguments)
+        public static string formatted_using(this string formatted_string, params object[] arguments)
         {
-            return string.Format(formattedString, arguments);
+            return string.Format(formatted_string, arguments);
         }
 
         public static bool is_equal_to_ignoring_case(this string left, string right)
trunk/product/MyMoney/MyMoney.csproj
@@ -597,6 +597,7 @@
     <Compile Include="Presentation\Views\updates\ICheckForUpdatesView.cs" />
     <Compile Include="Tasks\application\BillingTasks.cs" />
     <Compile Include="Tasks\application\CustomerTasks.cs" />
+    <Compile Include="Tasks\application\GetAllCompanysQuery.cs" />
     <Compile Include="Tasks\application\IncomeTasks.cs" />
     <Compile Include="Tasks\application\RegisterNewCompanyCommand.cs" />
     <Compile Include="Tasks\infrastructure\core\CommandPump.cs" />
@@ -741,7 +742,7 @@
     <Compile Include="Infrastructure\Container\Windsor\WindsorDependencyRegistrySpecs.cs" />
     <Compile Include="Utility\Core\ICommand.cs" />
     <Compile Include="Utility\Core\IMapper.cs" />
-    <Compile Include="Utility\Extensions\string_extensions.cs" />
+    <Compile Include="Utility\Extensions\StringExtensions.cs" />
     <Compile Include="Presentation\Model\Menu\File\Commands\ExitCommandSpecs.cs" />
     <Compile Include="Presentation\Core\ApplicationControllerSpecs.cs" />
     <Compile Include="Presentation\Core\ApplicationController.cs" />