Commit 251a0fa
Changed files (12)
build
product
client
presentation.windows
bootstrappers
events
orm
nhibernate
build/project.build
@@ -30,7 +30,7 @@
<target name="app.compile" depends="init">
<exec program="C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe"
workingdir="${base.dir}"
- commandline="solution.sln /p:Configuration=Release;OutDir=${build.compile.dir}\ /t:Rebuild /nologo /m"
+ commandline="solution.sln /p:Configuration=Release;OutDir=${build.compile.dir}\ /t:Rebuild /nologo /m /v:q"
/>
</target>
product/client/presentation.windows/bootstrappers/Bootstrapper.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
+using System.Diagnostics;
using System.IO;
using Autofac.Builder;
using FluentNHibernate.Cfg;
@@ -36,6 +37,7 @@ namespace presentation.windows.bootstrappers
static public ShellWindow create_window()
{
var builder = new ContainerBuilder();
+ Resolve.initialize_with(new AutofacDependencyRegistryBuilder(builder).build());
var shell_window = new ShellWindow();
builder.Register(x => shell_window).SingletonScoped();
builder.Register(x => shell_window).As<RegionManager>().SingletonScoped();
@@ -50,9 +52,9 @@ namespace presentation.windows.bootstrappers
var session_factory = bootstrap_nhibernate();
builder.Register(x => session_factory).SingletonScoped();
- builder.Register(x => x.Resolve<IContext>().value_for(new TypedKey<ISession>()));
+ builder.Register(x => current_session(x));
builder.Register<NHibernateUnitOfWorkFactory>().As<IUnitOfWorkFactory>();
- builder.Register(x => new ContextFactory().create_for(new PerThreadScopedStorage(new CurrentThread())));
+ builder.Register(x => create_application_context()).SingletonScoped();
// presentation infrastructure
builder.Register<WpfApplicationController>().As<ApplicationController>().SingletonScoped();
@@ -77,15 +79,26 @@ namespace presentation.windows.bootstrappers
builder.Register<ContainerAwareQueryBuilder>().As<QueryBuilder>();
// repositories
- builder.Register<NHibernatePersonRepository>().As<PersonRepository>();
+ builder.Register<NHibernatePersonRepository>().As<PersonRepository>().FactoryScoped();
- Resolve.initialize_with(new AutofacDependencyRegistryBuilder(builder).build());
Resolve.the<IEnumerable<NeedStartup>>().each(x => x.run());
Resolve.the<CommandProcessor>().run();
return shell_window;
}
+ static IContext create_application_context()
+ {
+ return new ContextFactory().create_for(new PerThreadScopedStorage(new CurrentThread()));
+ }
+
+ static ISession current_session(Autofac.IContext x)
+ {
+ var session = x.Resolve<IContext>().value_for(new TypedKey<ISession>());
+ if(null == session) Debugger.Break();
+ return session;
+ }
+
static ISessionFactory bootstrap_nhibernate()
{
var configuration = new Configuration();
@@ -110,13 +123,12 @@ namespace presentation.windows.bootstrappers
static void export(Configuration configuration)
{
- //var database_path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"mokhan.ca\momoney\default.db");
- //if (!File.Exists(database_path))
+ var database_path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"mokhan.ca\momoney\default.db");
+ if (File.Exists(database_path))
{
- //Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"mokhan.ca\momoney"));
- var export = new SchemaExport(configuration);
- export.Execute(true, true, false);
+ File.Delete(database_path);
}
+ new SchemaExport(configuration).Execute(true, true, false);
}
}
}
\ No newline at end of file
product/client/presentation.windows/events/SelectedFamilyMember.cs
@@ -0,0 +1,10 @@
+using System;
+using MoMoney.Service.Infrastructure.Eventing;
+
+namespace presentation.windows.events
+{
+ public class SelectedFamilyMember : IEvent
+ {
+ public Guid id { get; set; }
+ }
+}
\ No newline at end of file
product/client/presentation.windows/orm/nhibernate/NHibernateUnitOfWorkFactory.cs
@@ -1,5 +1,6 @@
using momoney.database.transactions;
using momoney.service.infrastructure.transactions;
+using MoMoney.Service.Infrastructure.Transactions;
using ISession = NHibernate.ISession;
using ISessionFactory = NHibernate.ISessionFactory;
@@ -18,8 +19,13 @@ namespace presentation.windows.orm.nhibernate
public IUnitOfWork create()
{
+ var key = new TypedKey<ISession>();
+ if (context.contains(key))
+ {
+ return new EmptyUnitOfWork();
+ }
var open_session = factory.OpenSession();
- context.add(new TypedKey<ISession>(), open_session);
+ context.add(key, open_session);
return new NHibernateUnitOfWork(open_session, context);
}
}
product/client/presentation.windows/presenters/AddFamilyMemberPresenter.cs
@@ -42,7 +42,6 @@ namespace presentation.windows.presenters
public DateTime date_of_birth { get; set; }
public IObservableCommand Save { get; set; }
public IObservableCommand Cancel { get; set; }
-
public Action close { get; set; }
}
}
\ No newline at end of file
product/client/presentation.windows/presenters/SelectedFamilyMemberPresenter.cs
@@ -10,14 +10,14 @@ namespace presentation.windows.presenters
{
PersonDetails selected_member;
QueryBuilder builder;
+ EventAggregator event_aggregator;
- public SelectedFamilyMemberPresenter(QueryBuilder builder)
+ public SelectedFamilyMemberPresenter(QueryBuilder builder, EventAggregator event_aggregator)
{
this.builder = builder;
+ this.event_aggregator = event_aggregator;
}
- public string first_name { get; set; }
- public string last_name { get; set; }
public IList<PersonDetails> family_members { get; set; }
public PersonDetails SelectedMember
@@ -26,21 +26,20 @@ namespace presentation.windows.presenters
set
{
selected_member = value;
- first_name = selected_member.first_name;
- last_name = selected_member.last_name;
- update(x => x.first_name, x => x.last_name);
+ update(x => x.SelectedMember);
+ event_aggregator.publish(new SelectedFamilyMember {id = value.id});
}
}
public void present()
{
- family_members = builder.build<FindAllFamily>().fetch().ToList();
+ builder.build<FindAllFamily>(x => family_members = x.fetch().ToList());
update(x => x.family_members);
}
public void notify(AddedNewFamilyMember message)
{
- family_members.Add(builder.build<FindMemberIdentifiedBy>().fetch(message.id));
+ builder.build<FindMemberIdentifiedBy>(x => family_members.Add(x.fetch(message.id)));
update(x => x.family_members);
}
}
product/client/presentation.windows/queries/ContainerAwareQueryBuilder.cs
@@ -1,36 +1,25 @@
-using Castle.DynamicProxy;
+using System;
+using Gorilla.Commons.Infrastructure.Container;
using momoney.service.infrastructure.transactions;
-using presentation.windows.infrastructure;
namespace presentation.windows.queries
{
public class ContainerAwareQueryBuilder : QueryBuilder
{
IUnitOfWorkFactory factory;
- ProxyGenerator generator;
- AnonymousInterceptor anonymous_interceptor;
public ContainerAwareQueryBuilder(IUnitOfWorkFactory factory)
{
this.factory = factory;
- generator = new ProxyGenerator();
- anonymous_interceptor = new AnonymousInterceptor(x =>
- {
- using (var unit_of_work = factory.create())
- {
- x.Proceed();
- unit_of_work.commit();
- }
- });
}
- public Query build<Query>() where Query : class
+ public void build<Query>(Action<Query> action) where Query : class
{
- return generator.CreateClassProxy<Query>(anonymous_interceptor);
-
- //var proxy_builder = new CastleDynamicProxyBuilder<Query>();
- //proxy_builder.add_interceptor(anonymous_interceptor);
- //return proxy_builder.create_proxy_for(Resolve.the<Query>());
+ using (var unit_of_work = factory.create())
+ {
+ action(Resolve.the<Query>());
+ unit_of_work.commit();
+ }
}
}
}
\ No newline at end of file
product/client/presentation.windows/queries/PersonDetails.cs
@@ -1,4 +1,5 @@
using System;
+using gorilla.commons.utility;
namespace presentation.windows.queries
{
@@ -9,5 +10,10 @@ namespace presentation.windows.queries
public string first_name { get; set; }
public string last_name { get; set; }
+
+ public override string ToString()
+ {
+ return "{0} {1}".formatted_using(first_name, last_name);
+ }
}
}
\ No newline at end of file
product/client/presentation.windows/queries/QueryBuilder.cs
@@ -1,7 +1,9 @@
+using System;
+
namespace presentation.windows.queries
{
public interface QueryBuilder
{
- Query build<Query>() where Query : class;
+ void build<Query>(Action<Query> action) where Query : class;
}
}
\ No newline at end of file
product/client/presentation.windows/views/AddFamilyMemberDialog.xaml
@@ -7,11 +7,11 @@
<DockPanel>
<UniformGrid Rows="3">
<Label>first name</Label>
- <TextBox Text="{Binding first_name}"></TextBox>
+ <TextBox Text="{Binding Path=first_name, Mode=TwoWay}"></TextBox>
<Label>last name</Label>
- <TextBox Text="{Binding last_name}"></TextBox>
+ <TextBox Text="{Binding Path=last_name, Mode=TwoWay}"></TextBox>
<Label>date of birth</Label>
- <Controls:DatePicker SelectedDate="{Binding date_of_birth}"></Controls:DatePicker>
+ <Controls:DatePicker SelectedDate="{Binding Path=date_of_birth, Mode=TwoWay}"></Controls:DatePicker>
</UniformGrid>
</DockPanel>
<Button Command="{Binding Save}">_Save</Button>
product/client/presentation.windows/views/SelectedFamilyMemberRegion.xaml
@@ -5,14 +5,14 @@
<Expander.Header>
<DockPanel>
<Label>Family Member:</Label>
- <ComboBox ItemsSource="{Binding family_members}" SelectedItem="{Binding selected_member}" Width="150"></ComboBox>
+ <ComboBox ItemsSource="{Binding family_members}" SelectedItem="{Binding SelectedMember}" Width="150"></ComboBox>
</DockPanel>
</Expander.Header>
<UniformGrid>
<Label FontWeight="Bold">First Name</Label>
- <Label Content="{Binding fist_name}"/>
+ <Label Content="{Binding Path=SelectedMember.first_name, Mode=OneWay}"/>
<Label FontWeight="Bold">Last Name</Label>
- <Label Content="{Binding last_name}"/>
+ <Label Content="{Binding Path=SelectedMember.last_name, Mode=OneWay}"/>
</UniformGrid>
</Expander>
</UserControl>
product/client/presentation.windows/presentation.windows.csproj
@@ -42,14 +42,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\build\lib\app\automapper\AutoMapper.dll</HintPath>
</Reference>
- <Reference Include="Castle.Core, Version=1.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\..\build\lib\app\nhibernate\Castle.Core.dll</HintPath>
- </Reference>
- <Reference Include="Castle.DynamicProxy2, Version=2.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\..\build\lib\app\nhibernate\Castle.DynamicProxy2.dll</HintPath>
- </Reference>
<Reference Include="FluentNHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8aa435e3cb308880, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\build\lib\app\nhibernate\FluentNHibernate.dll</HintPath>
@@ -130,6 +122,7 @@
<Compile Include="ApplicationController.cs" />
<Compile Include="bootstrappers\Bootstrapper.cs" />
<Compile Include="bootstrappers\ConfigureMappings.cs" />
+ <Compile Include="events\SelectedFamilyMember.cs" />
<Compile Include="orm\nhibernate\NHibernateUnitOfWorkFactory.cs" />
<Compile Include="orm\nhibernate\NHibernateUnitOfWork.cs" />
<Compile Include="infrastructure\DefaultMapper.cs" />
@@ -148,7 +141,6 @@
<Compile Include="presenters\AddFamilyMemberPresenter.cs" />
<Compile Include="commands\CommandBuilder.cs" />
<Compile Include="commands\AddFamilyMemberCommand.cs" />
- <Compile Include="infrastructure\AnonymousInterceptor.cs" />
<Compile Include="presenters\CompensationPresenter.cs" />
<Compile Include="commands\dto\FamilyMemberToAdd.cs" />
<Compile Include="commands\ContainerCommandBuilder.cs" />