diff options
| author | mo khan <mo@mokhan.ca> | 2009-10-23 13:09:04 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2009-10-23 13:09:04 -0600 |
| commit | 9a3430b2a1f0445c0dbac703907762e225383421 (patch) | |
| tree | 751d5742a199eae57ebb6d767e650bd6c803bdc3 | |
| parent | f76fe6ca01f3dc5fabc8bf16f299420ba9d7ef05 (diff) | |
renamed some components to something that is more descriptive.main
36 files changed, 172 insertions, 164 deletions
diff --git a/product/Boot/Modules/Core/LoadPresentationModulesCommand.cs b/product/Boot/Modules/Core/LoadPresentationModulesCommand.cs index a581756..07b87a1 100644 --- a/product/Boot/Modules/Core/LoadPresentationModulesCommand.cs +++ b/product/Boot/Modules/Core/LoadPresentationModulesCommand.cs @@ -7,9 +7,9 @@ namespace MoMoney.Modules.Core public class LoadPresentationModulesCommand : ILoadPresentationModulesCommand { readonly Registry<IModule> registry; - readonly ICommandProcessor processor; + readonly CommandProcessor processor; - public LoadPresentationModulesCommand(Registry<IModule> registry, ICommandProcessor processor) + public LoadPresentationModulesCommand(Registry<IModule> registry, CommandProcessor processor) { this.registry = registry; this.processor = processor; diff --git a/product/Boot/Modules/Core/LoadPresentationModulesCommandSpecs.cs b/product/Boot/Modules/Core/LoadPresentationModulesCommandSpecs.cs index 9b41286..4e982f3 100644 --- a/product/Boot/Modules/Core/LoadPresentationModulesCommandSpecs.cs +++ b/product/Boot/Modules/Core/LoadPresentationModulesCommandSpecs.cs @@ -15,7 +15,7 @@ namespace MoMoney.Modules.Core context c = () => { registry = the_dependency<Registry<IModule>>(); - processor = the_dependency<ICommandProcessor>(); + processor = the_dependency<CommandProcessor>(); module = an<IModule>(); when_the(registry).is_told_to(r => r.all()).it_will_return(module); }; @@ -24,6 +24,6 @@ namespace MoMoney.Modules.Core static Registry<IModule> registry; static IModule module; - static ICommandProcessor processor; + static CommandProcessor processor; } }
\ No newline at end of file diff --git a/product/Boot/boot/container/registration/wire_up_the_data_access_components_into_the.cs b/product/Boot/boot/container/registration/wire_up_the_data_access_components_into_the.cs index 03fa263..870b8cf 100644 --- a/product/Boot/boot/container/registration/wire_up_the_data_access_components_into_the.cs +++ b/product/Boot/boot/container/registration/wire_up_the_data_access_components_into_the.cs @@ -32,7 +32,7 @@ namespace MoMoney.boot.container.registration register.transient<IUnitOfWorkFactory, UnitOfWorkFactory>(); register.transient<ISessionFactory, SessionFactory>(); register.transient<IChangeTrackerFactory, ChangeTrackerFactory>(); - register.transient<IStatementRegistry, StatementRegistry>(); + register.transient<DatabaseCommandRegistry, ObjectDatabaseCommandRegistry>(); register.transient<IConnectionFactory, ConnectionFactory>(); register.transient<IConfigureDatabaseStep, ConfigureDatabaseStep>(); register.transient<IConfigureObjectContainerStep, ConfigureObjectContainerStep>(); diff --git a/product/Boot/boot/container/registration/wire_up_the_infrastructure_in_to_the.cs b/product/Boot/boot/container/registration/wire_up_the_infrastructure_in_to_the.cs index b685e11..f4bd5e8 100644 --- a/product/Boot/boot/container/registration/wire_up_the_infrastructure_in_to_the.cs +++ b/product/Boot/boot/container/registration/wire_up_the_infrastructure_in_to_the.cs @@ -49,7 +49,7 @@ namespace MoMoney.boot.container.registration registry.transient<ICommandPump, CommandPump>(); registry.transient<ICommandFactory, CommandFactory>(); registry.transient<ISynchronizationContextFactory, SynchronizationContextFactory>(); - registry.singleton<ICommandProcessor, AsynchronousCommandProcessor>(); + registry.singleton<CommandProcessor, AsynchronousCommandProcessor>(); } } }
\ No newline at end of file diff --git a/product/Boot/boot/start_the_application.cs b/product/Boot/boot/start_the_application.cs index 12280da..8a502a6 100644 --- a/product/Boot/boot/start_the_application.cs +++ b/product/Boot/boot/start_the_application.cs @@ -10,13 +10,13 @@ namespace MoMoney.boot { readonly IBackgroundThread thread; readonly ILoadPresentationModulesCommand command; - readonly ICommandProcessor processor; + readonly CommandProcessor processor; public start_the_application(IBackgroundThread thread) - : this(thread, Lazy.load<ILoadPresentationModulesCommand>(), Lazy.load<ICommandProcessor>()) {} + : this(thread, Lazy.load<ILoadPresentationModulesCommand>(), Lazy.load<CommandProcessor>()) {} public start_the_application(IBackgroundThread thread, ILoadPresentationModulesCommand command, - ICommandProcessor processor) + CommandProcessor processor) { this.thread = thread; this.command = command; diff --git a/product/Presentation/Core/ApplicationEnvironment.cs b/product/Presentation/Core/ApplicationEnvironment.cs index b3fcf38..9418efe 100644 --- a/product/Presentation/Core/ApplicationEnvironment.cs +++ b/product/Presentation/Core/ApplicationEnvironment.cs @@ -11,9 +11,9 @@ namespace MoMoney.Presentation.Core public class ApplicationEnvironment : IApplication { - readonly ICommandProcessor processor; + readonly CommandProcessor processor; - public ApplicationEnvironment(ICommandProcessor processor) + public ApplicationEnvironment(CommandProcessor processor) { this.processor = processor; } diff --git a/product/Presentation/Model/Menu/MenuItemBuilder.cs b/product/Presentation/Model/Menu/MenuItemBuilder.cs index b481c75..e87604e 100644 --- a/product/Presentation/Model/Menu/MenuItemBuilder.cs +++ b/product/Presentation/Model/Menu/MenuItemBuilder.cs @@ -22,7 +22,7 @@ namespace MoMoney.Presentation.Model.Menu { readonly DependencyRegistry registry; readonly IEventAggregator aggregator; - readonly ICommandProcessor processor; + readonly CommandProcessor processor; string name_of_the_menu { get; set; } Action command_to_execute { get; set; } @@ -30,7 +30,7 @@ namespace MoMoney.Presentation.Model.Menu ShortcutKey key { get; set; } Func<bool> can_be_clicked = () => true; - public MenuItemBuilder(DependencyRegistry registry, IEventAggregator aggregator, ICommandProcessor processor) + public MenuItemBuilder(DependencyRegistry registry, IEventAggregator aggregator, CommandProcessor processor) { name_of_the_menu = "Unknown"; command_to_execute = () => {}; diff --git a/product/Presentation/Model/Menu/ToolBarItemBuilder.cs b/product/Presentation/Model/Menu/ToolBarItemBuilder.cs index 2558453..daf2bc2 100644 --- a/product/Presentation/Model/Menu/ToolBarItemBuilder.cs +++ b/product/Presentation/Model/Menu/ToolBarItemBuilder.cs @@ -11,10 +11,10 @@ namespace MoMoney.Presentation.Model.Menu { readonly DependencyRegistry registry; readonly ToolStripButton item; - readonly ICommandProcessor processor; + readonly CommandProcessor processor; Func<bool> the_condition; - public ToolBarItemBuilder(DependencyRegistry registry, IEventAggregator aggregator, ICommandProcessor processor) + public ToolBarItemBuilder(DependencyRegistry registry, IEventAggregator aggregator, CommandProcessor processor) { this.registry = registry; this.processor = processor; diff --git a/product/Presentation/Presenters/CommandPump.cs b/product/Presentation/Presenters/CommandPump.cs index 450a2b6..bc63414 100644 --- a/product/Presentation/Presenters/CommandPump.cs +++ b/product/Presentation/Presenters/CommandPump.cs @@ -7,19 +7,17 @@ namespace MoMoney.Presentation.Presenters public interface ICommandPump { ICommandPump run<Command>() where Command : gorilla.commons.utility.Command; - ICommandPump run<Command>(Command command) where Command : gorilla.commons.utility.Command; ICommandPump run<Command, T>(T input) where Command : ParameterizedCommand<T>; - ICommandPump run<T>(Callback<T> item, Query<T> query); ICommandPump run<Output, Query>(Callback<Output> item) where Query : Query<Output>; } public class CommandPump : ICommandPump { - readonly ICommandProcessor processor; + readonly CommandProcessor processor; readonly DependencyRegistry registry; readonly ICommandFactory factory; - public CommandPump(ICommandProcessor processor, DependencyRegistry registry, ICommandFactory factory) + public CommandPump(CommandProcessor processor, DependencyRegistry registry, ICommandFactory factory) { this.processor = processor; this.factory = factory; diff --git a/product/Presentation/Presenters/RunPresenterCommand.cs b/product/Presentation/Presenters/RunPresenterCommand.cs index b90f856..7e5fe1e 100644 --- a/product/Presentation/Presenters/RunPresenterCommand.cs +++ b/product/Presentation/Presenters/RunPresenterCommand.cs @@ -6,9 +6,9 @@ namespace MoMoney.Presentation.Presenters public class RunPresenterCommand : IRunPresenterCommand { readonly IApplicationController application_controller; - readonly ICommandProcessor processor; + readonly CommandProcessor processor; - public RunPresenterCommand(IApplicationController application_controller, ICommandProcessor processor) + public RunPresenterCommand(IApplicationController application_controller, CommandProcessor processor) { this.application_controller = application_controller; this.processor = processor; diff --git a/product/Presentation/Presenters/RunThe.cs b/product/Presentation/Presenters/RunThe.cs index 547d1a2..1ce2f11 100644 --- a/product/Presentation/Presenters/RunThe.cs +++ b/product/Presentation/Presenters/RunThe.cs @@ -9,9 +9,9 @@ namespace momoney.presentation.presenters public class RunThe<TPresenter> : IRunThe<TPresenter> where TPresenter : IPresenter { readonly IApplicationController controller; - readonly ICommandProcessor processor; + readonly CommandProcessor processor; - public RunThe(IApplicationController controller, ICommandProcessor processor) + public RunThe(IApplicationController controller, CommandProcessor processor) { this.controller = controller; this.processor = processor; diff --git a/product/Presentation/Presenters/RunTheSpecs.cs b/product/Presentation/Presenters/RunTheSpecs.cs index 2781387..9a4fb42 100644 --- a/product/Presentation/Presenters/RunTheSpecs.cs +++ b/product/Presentation/Presenters/RunTheSpecs.cs @@ -19,13 +19,13 @@ namespace momoney.presentation.presenters context c = () => { controller = the_dependency<IApplicationController>(); - processor = the_dependency<ICommandProcessor>(); + processor = the_dependency<CommandProcessor>(); }; because b = () => sut.run(); static IApplicationController controller; - static ICommandProcessor processor; + static CommandProcessor processor; } } }
\ No newline at end of file diff --git a/product/database/IConnectionFactory.cs b/product/database/IConnectionFactory.cs index 25d37d0..0f0defa 100644 --- a/product/database/IConnectionFactory.cs +++ b/product/database/IConnectionFactory.cs @@ -5,6 +5,6 @@ namespace momoney.database { public interface IConnectionFactory { - IDatabaseConnection open_connection_to(File the_path_to_the_database_file); + DatabaseConnection open_connection_to(File the_path_to_the_database_file); } }
\ No newline at end of file diff --git a/product/database/ObjectDatabase.cs b/product/database/ObjectDatabase.cs index b96ad20..9ee6c1b 100644 --- a/product/database/ObjectDatabase.cs +++ b/product/database/ObjectDatabase.cs @@ -28,11 +28,11 @@ namespace momoney.database } } - public void apply(IStatement statement) + public void apply(DatabaseCommand command) { using (var connection = factory.open_connection_to(path_to_database())) { - statement.prepare(connection); + command.run(connection); connection.commit(); } } diff --git a/product/database/database.csproj b/product/database/database.csproj index df48913..252edd8 100644 --- a/product/database/database.csproj +++ b/product/database/database.csproj @@ -90,7 +90,7 @@ <Compile Include="db4o\ConfigureDatabaseStep.cs" /> <Compile Include="db4o\ConnectionFactory.cs" /> <Compile Include="ObjectDatabase.cs" /> - <Compile Include="db4o\DatabaseConnection.cs" /> + <Compile Include="db4o\ObjectDatabaseConnection.cs" /> <Compile Include="IConnectionFactory.cs" /> <Compile Include="IDatabaseConfiguration.cs" /> <Compile Include="transactions\ChangeTracker.cs" /> @@ -101,22 +101,24 @@ <Compile Include="transactions\ContextFactory.cs" /> <Compile Include="transactions\ContextFactorySpecs.cs" /> <Compile Include="transactions\CurrentThread.cs" /> + <Compile Include="transactions\DeleteFromDatabase.cs" /> <Compile Include="transactions\IChangeTracker.cs" /> <Compile Include="transactions\IChangeTrackerFactory.cs" /> <Compile Include="transactions\IContext.cs" /> <Compile Include="transactions\IDatabase.cs" /> - <Compile Include="transactions\IDatabaseConnection.cs" /> + <Compile Include="transactions\DatabaseConnection.cs" /> <Compile Include="transactions\IdentityMapProxy.cs" /> <Compile Include="transactions\IdentityMapSpecs.cs" /> <Compile Include="transactions\IIdentityMap.cs" /> <Compile Include="transactions\IKey.cs" /> <Compile Include="transactions\IScopedStorage.cs" /> - <Compile Include="transactions\IStatement.cs" /> - <Compile Include="transactions\IStatementRegistry.cs" /> + <Compile Include="transactions\DatabaseCommand.cs" /> + <Compile Include="transactions\DatabaseCommandRegistry.cs" /> <Compile Include="transactions\IThread.cs" /> <Compile Include="transactions\PerThread.cs" /> <Compile Include="transactions\PerThreadScopedStorage.cs" /> <Compile Include="transactions\PerThreadScopedStorageSpecs.cs" /> + <Compile Include="transactions\SaveOrUpdateFromDatabase.cs" /> <Compile Include="transactions\Session.cs" /> <Compile Include="transactions\SessionFactory.cs" /> <Compile Include="transactions\SessionFactorySpecs.cs" /> @@ -124,7 +126,7 @@ <Compile Include="transactions\SessionProvider.cs" /> <Compile Include="transactions\SessionSpecs.cs" /> <Compile Include="transactions\SingletonScopedStorage.cs" /> - <Compile Include="transactions\StatementRegistry.cs" /> + <Compile Include="transactions\ObjectDatabaseCommandRegistry.cs" /> <Compile Include="transactions\TrackerEntry.cs" /> <Compile Include="transactions\TrackerEntryMapper.cs" /> <Compile Include="transactions\TrackerEntrySpecs.cs" /> diff --git a/product/database/db4o/ConnectionFactory.cs b/product/database/db4o/ConnectionFactory.cs index e18895f..57260d5 100644 --- a/product/database/db4o/ConnectionFactory.cs +++ b/product/database/db4o/ConnectionFactory.cs @@ -17,11 +17,11 @@ namespace momoney.database.db4o this.setup_container = setup_container; } - public IDatabaseConnection open_connection_to(File the_path_to_the_database_file) + public DatabaseConnection open_connection_to(File the_path_to_the_database_file) { var configuration = Db4oFactory.NewConfiguration(); setup.configure(configuration); - return new DatabaseConnection(get_container(the_path_to_the_database_file, configuration)); + return new ObjectDatabaseConnection(get_container(the_path_to_the_database_file, configuration)); } IObjectContainer get_container(File the_path_to_the_database_file, IConfiguration configuration) diff --git a/product/database/db4o/DatabaseConnection.cs b/product/database/db4o/ObjectDatabaseConnection.cs index 9e8e57a..7149d25 100644 --- a/product/database/db4o/DatabaseConnection.cs +++ b/product/database/db4o/ObjectDatabaseConnection.cs @@ -5,11 +5,11 @@ using momoney.database.transactions; namespace momoney.database.db4o { - public class DatabaseConnection : IDatabaseConnection + public class ObjectDatabaseConnection : DatabaseConnection { readonly IObjectContainer container; - public DatabaseConnection(IObjectContainer container) + public ObjectDatabaseConnection(IObjectContainer container) { this.container = container; } diff --git a/product/database/transactions/ChangeTracker.cs b/product/database/transactions/ChangeTracker.cs index 4bfd41a..b6d12f2 100644 --- a/product/database/transactions/ChangeTracker.cs +++ b/product/database/transactions/ChangeTracker.cs @@ -8,11 +8,11 @@ namespace momoney.database.transactions public class ChangeTracker<T> : IChangeTracker<T> where T : Identifiable<Guid> { readonly ITrackerEntryMapper<T> mapper; - readonly IStatementRegistry registry; + readonly DatabaseCommandRegistry registry; readonly IList<ITrackerEntry<T>> items; readonly IList<T> to_be_deleted; - public ChangeTracker(ITrackerEntryMapper<T> mapper, IStatementRegistry registry) + public ChangeTracker(ITrackerEntryMapper<T> mapper, DatabaseCommandRegistry registry) { this.mapper = mapper; this.registry = registry; @@ -33,7 +33,7 @@ namespace momoney.database.transactions public void commit_to(IDatabase database) { items.each(x => commit(x, database)); - to_be_deleted.each(x => database.apply(registry.prepare_command_for(x))); + to_be_deleted.each(x => database.apply(registry.prepare_for_deletion(x))); } public bool is_dirty() @@ -48,7 +48,7 @@ namespace momoney.database.transactions void commit(ITrackerEntry<T> entry, IDatabase database) { - if (entry.has_changes()) database.apply(registry.prepare_command_for(entry.current)); + if (entry.has_changes()) database.apply(registry.prepare_for_flushing(entry.current)); } } }
\ No newline at end of file diff --git a/product/database/transactions/ChangeTrackerFactory.cs b/product/database/transactions/ChangeTrackerFactory.cs index a346cf8..940b2f6 100644 --- a/product/database/transactions/ChangeTrackerFactory.cs +++ b/product/database/transactions/ChangeTrackerFactory.cs @@ -6,10 +6,10 @@ namespace momoney.database.transactions { public class ChangeTrackerFactory : IChangeTrackerFactory { - readonly IStatementRegistry statement_registry; + readonly DatabaseCommandRegistry statement_registry; readonly DependencyRegistry registry; - public ChangeTrackerFactory(IStatementRegistry statement_registry, DependencyRegistry registry) + public ChangeTrackerFactory(DatabaseCommandRegistry statement_registry, DependencyRegistry registry) { this.statement_registry = statement_registry; this.registry = registry; diff --git a/product/database/transactions/ChangeTrackerSpecs.cs b/product/database/transactions/ChangeTrackerSpecs.cs index ef0cbb7..0a1d1bc 100644 --- a/product/database/transactions/ChangeTrackerSpecs.cs +++ b/product/database/transactions/ChangeTrackerSpecs.cs @@ -15,11 +15,11 @@ namespace momoney.database.transactions context c = () => { mapper = the_dependency<ITrackerEntryMapper<Identifiable<Guid>>>(); - registry = the_dependency<IStatementRegistry>(); + registry = the_dependency<DatabaseCommandRegistry>(); }; static protected ITrackerEntryMapper<Identifiable<Guid>> mapper; - static protected IStatementRegistry registry; + static protected DatabaseCommandRegistry registry; } [Concern(typeof (ChangeTracker<Identifiable<Guid>>))] @@ -30,14 +30,14 @@ namespace momoney.database.transactions context c = () => { item = an<Identifiable<Guid>>(); - statement = an<IStatement>(); + statement = an<DatabaseCommand>(); database = an<IDatabase>(); var entry = an<ITrackerEntry<Identifiable<Guid>>>(); when_the(mapper).is_told_to(x => x.map_from(item)).it_will_return(entry); when_the(entry).is_told_to(x => x.has_changes()).it_will_return(true); when_the(entry).is_told_to(x => x.current).it_will_return(item); - when_the(registry).is_told_to(x => x.prepare_command_for(item)).it_will_return(statement); + when_the(registry).is_told_to(x => x.prepare_for_flushing(item)).it_will_return(statement); }; because b = () => @@ -48,7 +48,7 @@ namespace momoney.database.transactions static Identifiable<Guid> item; static IDatabase database; - static IStatement statement; + static DatabaseCommand statement; } [Concern(typeof (ChangeTracker<Identifiable<Guid>>))] diff --git a/product/database/transactions/DatabaseCommand.cs b/product/database/transactions/DatabaseCommand.cs new file mode 100644 index 0000000..0f1f283 --- /dev/null +++ b/product/database/transactions/DatabaseCommand.cs @@ -0,0 +1,8 @@ +using gorilla.commons.utility; + +namespace momoney.database.transactions +{ + public interface DatabaseCommand : ParameterizedCommand<DatabaseConnection> + { + } +}
\ No newline at end of file diff --git a/product/database/transactions/DatabaseCommandRegistry.cs b/product/database/transactions/DatabaseCommandRegistry.cs new file mode 100644 index 0000000..16f01c8 --- /dev/null +++ b/product/database/transactions/DatabaseCommandRegistry.cs @@ -0,0 +1,11 @@ +using System; +using gorilla.commons.utility; + +namespace momoney.database.transactions +{ + public interface DatabaseCommandRegistry + { + DatabaseCommand prepare_for_deletion<T>(T entity) where T : Identifiable<Guid>; + DatabaseCommand prepare_for_flushing<T>(T entity) where T : Identifiable<Guid>; + } +}
\ No newline at end of file diff --git a/product/database/transactions/IDatabaseConnection.cs b/product/database/transactions/DatabaseConnection.cs index 98f79f4..19bd725 100644 --- a/product/database/transactions/IDatabaseConnection.cs +++ b/product/database/transactions/DatabaseConnection.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; namespace momoney.database.transactions { - public interface IDatabaseConnection : IDisposable + public interface DatabaseConnection : IDisposable { IEnumerable<T> query<T>(); IEnumerable<T> query<T>(Predicate<T> predicate); diff --git a/product/database/transactions/DeleteFromDatabase.cs b/product/database/transactions/DeleteFromDatabase.cs new file mode 100644 index 0000000..07c2879 --- /dev/null +++ b/product/database/transactions/DeleteFromDatabase.cs @@ -0,0 +1,17 @@ +namespace momoney.database.transactions +{ + public class DeleteFromDatabase<T> : DatabaseCommand + { + readonly T entity; + + public DeleteFromDatabase(T entity) + { + this.entity = entity; + } + + public void run(DatabaseConnection connection) + { + connection.delete(entity); + } + } +}
\ No newline at end of file diff --git a/product/database/transactions/IDatabase.cs b/product/database/transactions/IDatabase.cs index 433f52a..4401e64 100644 --- a/product/database/transactions/IDatabase.cs +++ b/product/database/transactions/IDatabase.cs @@ -7,6 +7,6 @@ namespace momoney.database.transactions public interface IDatabase { IEnumerable<T> fetch_all<T>() where T : Identifiable<Guid>; - void apply(IStatement statement); + void apply(DatabaseCommand command); } }
\ No newline at end of file diff --git a/product/database/transactions/IStatement.cs b/product/database/transactions/IStatement.cs deleted file mode 100644 index ea2092f..0000000 --- a/product/database/transactions/IStatement.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace momoney.database.transactions -{ - public interface IStatement - { - void prepare(IDatabaseConnection connection); - } -}
\ No newline at end of file diff --git a/product/database/transactions/IStatementRegistry.cs b/product/database/transactions/IStatementRegistry.cs deleted file mode 100644 index e2b3b16..0000000 --- a/product/database/transactions/IStatementRegistry.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using gorilla.commons.utility; - -namespace momoney.database.transactions -{ - public interface IStatementRegistry - { - IStatement prepare_delete_statement_for<T>(T entity) where T : Identifiable<Guid>; - IStatement prepare_command_for<T>(T entity) where T : Identifiable<Guid>; - } -}
\ No newline at end of file diff --git a/product/database/transactions/ObjectDatabaseCommandRegistry.cs b/product/database/transactions/ObjectDatabaseCommandRegistry.cs new file mode 100644 index 0000000..8b2d97e --- /dev/null +++ b/product/database/transactions/ObjectDatabaseCommandRegistry.cs @@ -0,0 +1,18 @@ +using System; +using gorilla.commons.utility; + +namespace momoney.database.transactions +{ + public class ObjectDatabaseCommandRegistry : DatabaseCommandRegistry + { + public DatabaseCommand prepare_for_deletion<T>(T entity) where T : Identifiable<Guid> + { + return new DeleteFromDatabase<T>(entity); + } + + public DatabaseCommand prepare_for_flushing<T>(T entity) where T : Identifiable<Guid> + { + return new SaveOrUpdateFromDatabase<T>(entity); + } + } +}
\ No newline at end of file diff --git a/product/database/transactions/SaveOrUpdateFromDatabase.cs b/product/database/transactions/SaveOrUpdateFromDatabase.cs new file mode 100644 index 0000000..c8babda --- /dev/null +++ b/product/database/transactions/SaveOrUpdateFromDatabase.cs @@ -0,0 +1,20 @@ +using System; +using gorilla.commons.utility; + +namespace momoney.database.transactions +{ + public class SaveOrUpdateFromDatabase<T> : DatabaseCommand where T : Identifiable<Guid> + { + readonly T entity; + + public SaveOrUpdateFromDatabase(T entity) + { + this.entity = entity; + } + + public void run(DatabaseConnection connection) + { + connection.store(entity); + } + } +}
\ No newline at end of file diff --git a/product/database/transactions/StatementRegistry.cs b/product/database/transactions/StatementRegistry.cs deleted file mode 100644 index 66ca362..0000000 --- a/product/database/transactions/StatementRegistry.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using gorilla.commons.utility; - -namespace momoney.database.transactions -{ - public class StatementRegistry : IStatementRegistry - { - public IStatement prepare_delete_statement_for<T>(T entity) where T : Identifiable<Guid> - { - return new DeletionStatement<T>(entity); - } - - public IStatement prepare_command_for<T>(T entity) where T : Identifiable<Guid> - { - return new SaveOrUpdateStatement<T>(entity); - } - } - - public class SaveOrUpdateStatement<T> : IStatement where T : Identifiable<Guid> - { - readonly T entity; - - public SaveOrUpdateStatement(T entity) - { - this.entity = entity; - } - - public void prepare(IDatabaseConnection connection) - { - connection.store(entity); - } - } - - public class DeletionStatement<T> : IStatement - { - readonly T entity; - - public DeletionStatement(T entity) - { - this.entity = entity; - } - - public void prepare(IDatabaseConnection connection) - { - connection.delete(entity); - } - } -}
\ No newline at end of file diff --git a/product/service.infrastructure/service.infrastructure.csproj b/product/service.infrastructure/service.infrastructure.csproj index 351182d..d37746e 100644 --- a/product/service.infrastructure/service.infrastructure.csproj +++ b/product/service.infrastructure/service.infrastructure.csproj @@ -101,9 +101,9 @@ <Compile Include="threading\BackgroundThreadFactory.cs" /> <Compile Include="threading\BackgroundThreadFactorySpecs.cs" /> <Compile Include="threading\BackgroundThreadSpecs.cs" /> - <Compile Include="threading\CommandProcessor.cs" /> + <Compile Include="threading\SynchronousCommandProcessor.cs" /> <Compile Include="threading\CommandProcessorSpecs.cs" /> - <Compile Include="threading\ICommandProcessor.cs" /> + <Compile Include="threading\CommandProcessor.cs" /> <Compile Include="threading\IntervalTimer.cs" /> <Compile Include="threading\IntervalTimerSpecs.cs" /> <Compile Include="threading\ITimerClient.cs" /> diff --git a/product/service.infrastructure/threading/AsynchronousCommandProcessor.cs b/product/service.infrastructure/threading/AsynchronousCommandProcessor.cs index a7b0e93..91bd835 100644 --- a/product/service.infrastructure/threading/AsynchronousCommandProcessor.cs +++ b/product/service.infrastructure/threading/AsynchronousCommandProcessor.cs @@ -6,7 +6,7 @@ using gorilla.commons.utility; namespace MoMoney.Service.Infrastructure.Threading { - public class AsynchronousCommandProcessor : ICommandProcessor + public class AsynchronousCommandProcessor : CommandProcessor { readonly Queue<Command> queued_commands; readonly EventWaitHandle manual_reset; diff --git a/product/service.infrastructure/threading/CommandProcessor.cs b/product/service.infrastructure/threading/CommandProcessor.cs index 7c7b195..170ec4c 100644 --- a/product/service.infrastructure/threading/CommandProcessor.cs +++ b/product/service.infrastructure/threading/CommandProcessor.cs @@ -1,37 +1,13 @@ using System; -using System.Collections.Generic; using System.Linq.Expressions; using gorilla.commons.utility; namespace MoMoney.Service.Infrastructure.Threading { - public class CommandProcessor : ICommandProcessor + public interface CommandProcessor : Command { - readonly Queue<Command> queued_commands; - - public CommandProcessor() - { - queued_commands = new Queue<Command>(); - } - - public void add(Expression<Action> action_to_process) - { - add(new AnonymousCommand(action_to_process)); - } - - public void add(Command command_to_process) - { - queued_commands.Enqueue(command_to_process); - } - - public void run() - { - while (queued_commands.Count > 0) queued_commands.Dequeue().run(); - } - - public void stop() - { - queued_commands.Clear(); - } + void add(Expression<Action> action_to_process); + void add(Command command_to_process); + void stop(); } }
\ No newline at end of file diff --git a/product/service.infrastructure/threading/CommandProcessorSpecs.cs b/product/service.infrastructure/threading/CommandProcessorSpecs.cs index a8bc1f8..3e68e92 100644 --- a/product/service.infrastructure/threading/CommandProcessorSpecs.cs +++ b/product/service.infrastructure/threading/CommandProcessorSpecs.cs @@ -5,10 +5,10 @@ using MoMoney.Service.Infrastructure.Threading; namespace momoney.service.infrastructure.threading { - [Concern(typeof (CommandProcessor))] - public abstract class behaves_like_a_command_processor : concerns_for<ICommandProcessor, CommandProcessor> {} + [Concern(typeof (SynchronousCommandProcessor))] + public abstract class behaves_like_a_command_processor : concerns_for<CommandProcessor, SynchronousCommandProcessor> {} - [Concern(typeof (CommandProcessor))] + [Concern(typeof (SynchronousCommandProcessor))] public class when_running_all_the_queued_commands_waiting_for_execution : behaves_like_a_command_processor { it should_run_the_first_command_in_the_queue = () => first_command.was_told_to(f => f.run()); @@ -32,7 +32,7 @@ namespace momoney.service.infrastructure.threading static Command second_command; } - [Concern(typeof (CommandProcessor))] + [Concern(typeof (SynchronousCommandProcessor))] public class when_attempting_to_rerun_the_command_processor : behaves_like_a_command_processor { it should_not_re_run_the_commands_that_have_already_executed = diff --git a/product/service.infrastructure/threading/ICommandProcessor.cs b/product/service.infrastructure/threading/ICommandProcessor.cs deleted file mode 100644 index e22ba80..0000000 --- a/product/service.infrastructure/threading/ICommandProcessor.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Linq.Expressions; -using gorilla.commons.utility; - -namespace MoMoney.Service.Infrastructure.Threading -{ - public interface ICommandProcessor : Command - { - void add(Expression<Action> action_to_process); - void add(Command command_to_process); - void stop(); - } -}
\ No newline at end of file diff --git a/product/service.infrastructure/threading/SynchronousCommandProcessor.cs b/product/service.infrastructure/threading/SynchronousCommandProcessor.cs new file mode 100644 index 0000000..87098aa --- /dev/null +++ b/product/service.infrastructure/threading/SynchronousCommandProcessor.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using gorilla.commons.utility; + +namespace MoMoney.Service.Infrastructure.Threading +{ + public class SynchronousCommandProcessor : CommandProcessor + { + readonly Queue<Command> queued_commands; + + public SynchronousCommandProcessor() + { + queued_commands = new Queue<Command>(); + } + + public void add(Expression<Action> action_to_process) + { + add(new AnonymousCommand(action_to_process)); + } + + public void add(Command command_to_process) + { + queued_commands.Enqueue(command_to_process); + } + + public void run() + { + while (queued_commands.Count > 0) queued_commands.Dequeue().run(); + } + + public void stop() + { + queued_commands.Clear(); + } + } +}
\ No newline at end of file |
