Commit 6289e8e
Changed files (24)
product
desktop.ui
bootstrappers
handlers
views
infrastructure
threading
product/desktop.ui/bootstrappers/Bootstrapper.cs
@@ -4,6 +4,7 @@ using System.Windows.Threading;
using Autofac;
using desktop.ui.eventing;
using desktop.ui.handlers;
+using desktop.ui.handlers.orm;
using desktop.ui.presenters;
using desktop.ui.views;
using infrastructure.container;
@@ -33,6 +34,7 @@ namespace desktop.ui.bootstrappers
register_presentation_infrastructure(builder);
register_presenters(builder);
register_for_message_to_listen_for(builder);
+ server_registration(builder);
shell_window.Closed += (o, e) => Resolve.the<CommandProcessor>().stop();
shell_window.Closed += (o, e) => Resolve.the<IEnumerable<NeedsShutdown>>();
@@ -73,11 +75,6 @@ namespace desktop.ui.bootstrappers
builder.RegisterType<AddFamilyMemberPresenter>();
builder.RegisterType<AddFamilyMemberPresenter.SaveCommand>();
- builder.RegisterType<AccountPresenter>();
- builder.RegisterType<AccountPresenter.ImportTransactionCommand>();
-
- builder.RegisterType<AddNewDetailAccountPresenter>();
- builder.RegisterType<AddNewDetailAccountPresenter.CreateNewAccount>();
builder.RegisterType<AddNewIncomeViewModel>();
builder.RegisterType<AddNewIncomeViewModel.AddIncomeCommand>();
@@ -89,5 +86,12 @@ namespace desktop.ui.bootstrappers
{
builder.RegisterType<PublishEventHandler<AddedNewFamilyMember>>().As<Handles<AddedNewFamilyMember>>();
}
+
+ static void server_registration(ContainerBuilder builder)
+ {
+ builder.RegisterType<AddNewFamilyMemberHandler>().As<Handles<FamilyMemberToAdd>>();
+ builder.RegisterType<FindAllFamilyHandler>().As<Handles<FindAllFamily>>();
+ builder.RegisterType<InMemoryDatabase>().As<PersonRepository>().SingleInstance();
+ }
}
}
\ No newline at end of file
product/desktop.ui/bootstrappers/ComposeShell.cs
@@ -16,7 +16,6 @@ namespace desktop.ui.bootstrappers
public void run()
{
- controller.add_tab<AccountPresenter, AccountTab>();
controller.add_tab<TaxSummaryPresenter, TaxSummaryTab>();
region_manager.region<MainMenu>(x =>
@@ -25,9 +24,6 @@ namespace desktop.ui.bootstrappers
{
controller.launch_dialog<AddFamilyMemberPresenter, AddFamilyMemberDialog>();
});
- //x.add("_Accounts").add("_Add Account", () => {
- //controller.launch_dialog<AddNewDetailAccountPresenter, AddNewDetailAccountDialog>();
- //});
x.add("_Income").add("_Add Income", () => {
controller.launch_dialog<AddNewIncomeViewModel, AddNewIncomeDialog>();
}) ;
product/desktop.ui/bootstrappers/ConfigureMappings.cs
@@ -1,9 +1,79 @@
+using System;
+using System.Collections.Generic;
+using desktop.ui.handlers.domain;
+using desktop.ui.presenters;
+using utility;
+
namespace desktop.ui.bootstrappers
{
public class ConfigureMappings : NeedStartup
{
public void run()
{
+ Map<AddedNewFamilyMember, PersonDetails>(x =>
+ {
+ return new PersonDetails
+ {
+ id = x.id,
+ first_name = x.first_name,
+ last_name = x.last_name,
+ };
+ });
+ Map<Person, AddedNewFamilyMember>(x =>
+ {
+ return new AddedNewFamilyMember
+ {
+ id = x.id,
+ first_name = x.first_name,
+ last_name = x.last_name,
+ };
+ });
+ }
+
+ void Map<Input, Output>(Func<Input, Output> conversion)
+ {
+ MapperRegistery.Register(conversion);
+ }
+ }
+
+ static public class MapperRegistery
+ {
+ static Dictionary<MapKey, object> mappings = new Dictionary<MapKey, object>();
+
+ static public void Register<Input, Output>(Func<Input, Output> conversion)
+ {
+ mappings.Add(new MapKey<Input, Output>(), conversion);
+ }
+
+ static public Output Map<Input, Output>(Input item)
+ {
+ var converter = mappings[new MapKey<Input, Output>()];
+ return converter.downcast_to<Func<Input, Output>>()(item);
+ }
+ }
+
+ public interface MapKey
+ {
+ }
+
+ public class MapKey<Input, Output> : MapKey
+ {
+ public bool Equals(MapKey<Input, Output> obj)
+ {
+ return !ReferenceEquals(null, obj);
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ if (ReferenceEquals(this, obj)) return true;
+ if (obj.GetType() != typeof (MapKey<Input, Output>)) return false;
+ return Equals((MapKey<Input, Output>) obj);
+ }
+
+ public override int GetHashCode()
+ {
+ return GetType().GetHashCode();
}
}
}
\ No newline at end of file
product/desktop.ui/bootstrappers/DefaultMapper.cs
@@ -8,7 +8,7 @@ namespace desktop.ui.bootstrappers
public Output map_from<Input, Output>(Input item)
{
//return AutoMapper.Mapper.Map<Input, Output>(item);
- throw new NotImplementedException();
+ return MapperRegistery.Map<Input, Output>(item);
}
}
}
\ No newline at end of file
product/desktop.ui/handlers/domain/Entity.cs
@@ -0,0 +1,46 @@
+using System;
+using utility;
+
+namespace desktop.ui.handlers.domain
+{
+ public class Entity : IEquatable<Entity>, Identifiable<Guid>
+ {
+ protected Entity()
+ {
+ id = Id<Guid>.Default;
+ }
+
+ public virtual Id<Guid> id { get; set; }
+
+ public virtual bool Equals(Entity other)
+ {
+ if (ReferenceEquals(null, other)) return false;
+ if (ReferenceEquals(this, other)) return true;
+ if (id.Equals(Id<Guid>.Default) || other.id.Equals(Id<Guid>.Default)) return false;
+ return other.id.Equals(id);
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ if (ReferenceEquals(this, obj)) return true;
+ if (!(obj is Entity)) return false;
+ return Equals((Entity) obj);
+ }
+
+ public override int GetHashCode()
+ {
+ return id.GetHashCode();
+ }
+
+ static public bool operator ==(Entity left, Entity right)
+ {
+ return Equals(left, right);
+ }
+
+ static public bool operator !=(Entity left, Entity right)
+ {
+ return !Equals(left, right);
+ }
+ }
+}
\ No newline at end of file
product/desktop.ui/handlers/domain/Person.cs
@@ -0,0 +1,21 @@
+using utility;
+
+namespace desktop.ui.handlers.domain
+{
+ public class Person : Entity
+ {
+ static public Person New(string first_name, string last_name, Date date_of_birth)
+ {
+ return new Person
+ {
+ first_name = first_name,
+ last_name = last_name,
+ date_of_birth = date_of_birth,
+ };
+ }
+
+ public virtual string first_name { get; set; }
+ public virtual string last_name { get; set; }
+ public virtual Date date_of_birth { get; set; }
+ }
+}
\ No newline at end of file
product/desktop.ui/handlers/orm/InMemoryDatabase.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using desktop.ui.handlers.domain;
+using utility;
+using System.Linq;
+
+namespace desktop.ui.handlers.orm
+{
+ public class InMemoryDatabase : PersonRepository
+ {
+ HashSet<Person> people = new HashSet<Person>();
+
+ public void save(Person person)
+ {
+ person.id = new Id<Guid>(Guid.NewGuid());
+ people.Add(person);
+ }
+
+ public Person find_by(Guid id)
+ {
+ return people.Single(x => x.id == id);
+ }
+
+ public IEnumerable<Person> find_all()
+ {
+ return people.all();
+ }
+ }
+}
\ No newline at end of file
product/desktop.ui/handlers/orm/PersonRepository.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using desktop.ui.handlers.domain;
+
+namespace desktop.ui.handlers.orm
+{
+ public interface PersonRepository
+ {
+ void save(Person person);
+ Person find_by(Guid id);
+ IEnumerable<Person> find_all();
+ }
+}
\ No newline at end of file
product/desktop.ui/handlers/AddNewFamilyMemberHandler.cs
@@ -0,0 +1,30 @@
+using desktop.ui.handlers.domain;
+using desktop.ui.handlers.orm;
+using desktop.ui.presenters;
+
+namespace desktop.ui.handlers
+{
+ public class AddNewFamilyMemberHandler : Handles<FamilyMemberToAdd>
+ {
+ PersonRepository people;
+ ServiceBus bus;
+
+ public AddNewFamilyMemberHandler(PersonRepository people, ServiceBus bus)
+ {
+ this.people = people;
+ this.bus = bus;
+ }
+
+ public void handle(FamilyMemberToAdd item)
+ {
+ var person = Person.New(item.first_name, item.last_name, item.date_of_birth);
+ people.save(person);
+ bus.publish<AddedNewFamilyMember>(x =>
+ {
+ x.id = person.id;
+ x.first_name = person.first_name;
+ x.last_name = person.last_name;
+ });
+ }
+ }
+}
\ No newline at end of file
product/desktop.ui/handlers/FindAllFamilyHandler.cs
@@ -0,0 +1,29 @@
+using desktop.ui.handlers.domain;
+using desktop.ui.handlers.orm;
+using desktop.ui.presenters;
+using utility;
+
+namespace desktop.ui.handlers
+{
+ public class FindAllFamilyHandler : Handles<FindAllFamily>
+ {
+ PersonRepository people;
+ Mapper mapper;
+ ServiceBus bus;
+
+ public FindAllFamilyHandler(PersonRepository people, Mapper mapper, ServiceBus bus)
+ {
+ this.people = people;
+ this.bus = bus;
+ this.mapper = mapper;
+ }
+
+ public void handle(FindAllFamily item)
+ {
+ people
+ .find_all()
+ .map_all_using<Person, AddedNewFamilyMember>(mapper)
+ .each(x => bus.publish(x));
+ }
+ }
+}
\ No newline at end of file
product/desktop.ui/presenters/AccountPresenter.cs
@@ -1,38 +0,0 @@
-namespace desktop.ui.presenters
-{
- public class AccountPresenter : TabPresenter
- {
- UICommandBuilder ui_builder;
-
- public AccountPresenter(UICommandBuilder ui_builder)
- {
- this.ui_builder = ui_builder;
- }
-
- public void present()
- {
- import = ui_builder.build<ImportTransactionCommand>(this);
- }
-
- public SelectedAccountDetails SelectedAccount { get; set; }
-
- public IObservableCommand import { get; set; }
-
- public string Header
- {
- get { return "Accounts"; }
- }
-
- public class ImportTransactionCommand : UICommand<AccountPresenter>
- {
- ApplicationController controller;
-
- public override void run(AccountPresenter presenter)
- {
- //controller.launch_dialog<ImportTransactionsPresenter, ImportTransactionDialog>(presenter.SelectedAccount);
- }
- }
- }
-
- public class SelectedAccountDetails {}
-}
\ No newline at end of file
product/desktop.ui/presenters/AddNewDetailAccountPresenter.cs
@@ -1,56 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace desktop.ui.presenters
-{
- public class AddNewDetailAccountPresenter : DialogPresenter
- {
- UICommandBuilder builder;
-
- public AddNewDetailAccountPresenter(UICommandBuilder builder)
- {
- this.builder = builder;
- }
-
- public void present()
- {
- add = builder.build<CreateNewAccount>(this);
- cancel = builder.build<CancelCommand>(this);
- currencies = new[] { "CAD" }.to_observable();
- }
-
- public string account_name { get; set; }
- public string currency { get; set; }
- public IEnumerable<string> currencies { get; set; }
- public Action close { get; set; }
- public IObservableCommand add { get; set; }
- public IObservableCommand cancel { get; set; }
-
- public class CreateNewAccount : UICommand<AddNewDetailAccountPresenter>
- {
- ServiceBus bus;
-
- public CreateNewAccount(ServiceBus bus)
- {
- this.bus = bus;
- }
-
- public override void run(AddNewDetailAccountPresenter presenter)
- {
- bus.publish<CreateNewDetailAccountCommand>(x =>
- {
- x.account_name = presenter.account_name;
- x.currency = presenter.currency;
- });
- presenter.close();
- }
- }
- }
-
- public class CreateNewDetailAccountCommand
- {
- public string account_name { get; set; }
-
- public string currency { get; set; }
- }
-}
\ No newline at end of file
product/desktop.ui/views/AccountTab.xaml
@@ -1,8 +0,0 @@
-<UserControl x:Class="desktop.ui.views.AccountTab"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
- <StackPanel>
- <Label>Accounts</Label>
- <Button Command="{Binding import}">Import Transactions</Button>
- </StackPanel>
-</UserControl>
product/desktop.ui/views/AccountTab.xaml.cs
@@ -1,12 +0,0 @@
-using desktop.ui.presenters;
-
-namespace desktop.ui.views
-{
- public partial class AccountTab : Tab<AccountPresenter>
- {
- public AccountTab()
- {
- InitializeComponent();
- }
- }
-}
\ No newline at end of file
product/desktop.ui/views/AddNewDetailAccountDialog.xaml
@@ -1,27 +0,0 @@
-<Window x:Class="desktop.ui.views.AddNewDetailAccountDialog" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:views="clr-namespace:desktop.ui.views" Title="Add New Detail Account">
- <StackPanel>
- <ListView HorizontalContentAlignment="Stretch" KeyboardNavigation.TabNavigation="Continue">
- <ListView.ItemContainerStyle>
- <Style TargetType="{x:Type ListViewItem}">
- <Setter Property="IsTabStop" Value="False" />
- </Style>
- </ListView.ItemContainerStyle>
- <ListViewItem>
- <DockPanel HorizontalAlignment="Stretch">
- <Label Width="150">Name:</Label>
- <TextBox HorizontalAlignment="Stretch" Text="{Binding Path=account_name}"/>
- </DockPanel>
- </ListViewItem>
- <ListViewItem>
- <DockPanel>
- <Label Width="150">Currency:</Label>
- <ComboBox SelectedItem="{Binding Path=currency}" ItemsSource="{Binding Path=currencies}"></ComboBox>
- </DockPanel>
- </ListViewItem>
- </ListView>
- <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
- <views:ImageButton ImageSource="images\save.png" ToolTip="Add" Label="_Add" Command="{Binding Path=add}" IsDefault="True"/>
- <views:ImageButton ImageSource="images\cancel.png" ToolTip="Cancel" Label="_Cancel" Command="{Binding Path=cancel}" IsCancel="True" />
- </StackPanel>
- </StackPanel>
-</Window>
\ No newline at end of file
product/desktop.ui/views/AddNewDetailAccountDialog.xaml.cs
@@ -1,19 +0,0 @@
-using System.Windows;
-using desktop.ui.presenters;
-
-namespace desktop.ui.views
-{
- public partial class AddNewDetailAccountDialog : Dialog<AddNewDetailAccountPresenter>
- {
- public AddNewDetailAccountDialog()
- {
- InitializeComponent();
- }
-
- public void open()
- {
- Owner = Application.Current.MainWindow;
- ShowDialog();
- }
- }
-}
\ No newline at end of file
product/desktop.ui/desktop.ui.csproj
@@ -73,15 +73,19 @@
<Compile Include="eventing\SynchronizedEventAggregator.cs" />
<Compile Include="events\SelectedFamilyMember.cs" />
<Compile Include="events\UpdateOnLongRunningProcess.cs" />
+ <Compile Include="handlers\AddNewFamilyMemberHandler.cs" />
+ <Compile Include="handlers\domain\Entity.cs" />
+ <Compile Include="handlers\domain\Person.cs" />
+ <Compile Include="handlers\FindAllFamilyHandler.cs" />
<Compile Include="handlers\Handles.cs" />
+ <Compile Include="handlers\orm\InMemoryDatabase.cs" />
+ <Compile Include="handlers\orm\PersonRepository.cs" />
<Compile Include="handlers\PublishEventHandler.cs" />
<Compile Include="IObservableCommand.cs" />
<Compile Include="Observable.cs" />
<Compile Include="Presenter.cs" />
<Compile Include="PresenterFactory.cs" />
- <Compile Include="presenters\AccountPresenter.cs" />
<Compile Include="presenters\AddFamilyMemberPresenter.cs" />
- <Compile Include="presenters\AddNewDetailAccountPresenter.cs" />
<Compile Include="presenters\AddNewIncomeViewModel.cs" />
<Compile Include="presenters\PersonDetails.cs" />
<Compile Include="presenters\SelectedFamilyMemberPresenter.cs" />
@@ -98,15 +102,9 @@
<Compile Include="UICommand.cs" />
<Compile Include="UICommandBuilder.cs" />
<Compile Include="View.cs" />
- <Compile Include="views\AccountTab.xaml.cs">
- <DependentUpon>AccountTab.xaml</DependentUpon>
- </Compile>
<Compile Include="views\AddFamilyMemberDialog.xaml.cs">
<DependentUpon>AddFamilyMemberDialog.xaml</DependentUpon>
</Compile>
- <Compile Include="views\AddNewDetailAccountDialog.xaml.cs">
- <DependentUpon>AddNewDetailAccountDialog.xaml</DependentUpon>
- </Compile>
<Compile Include="views\AddNewIncomeDialog.xaml.cs">
<DependentUpon>AddNewIncomeDialog.xaml</DependentUpon>
</Compile>
@@ -158,18 +156,10 @@
<AppDesigner Include="Properties\" />
</ItemGroup>
<ItemGroup>
- <Page Include="views\AccountTab.xaml">
- <Generator>MSBuild:Compile</Generator>
- <SubType>Designer</SubType>
- </Page>
<Page Include="views\AddFamilyMemberDialog.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
- <Page Include="views\AddNewDetailAccountDialog.xaml">
- <Generator>MSBuild:Compile</Generator>
- <SubType>Designer</SubType>
- </Page>
<Page Include="views\AddNewIncomeDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -209,6 +199,7 @@
<Name>utility</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
product/infrastructure/threading/PerThread.cs
@@ -16,22 +16,22 @@ namespace infrastructure.threading
slots = new Dictionary<int, LocalDataStoreSlot>();
}
- public bool contains<T>(IKey<T> key)
+ public bool contains<T>(Key<T> key)
{
return key.is_found_in(get_items());
}
- public void add<T>(IKey<T> key, T value)
+ public void add<T>(Key<T> key, T value)
{
key.add_value_to(get_items(), value);
}
- public T value_for<T>(IKey<T> key)
+ public T value_for<T>(Key<T> key)
{
return key.parse_from(get_items());
}
- public void remove<T>(IKey<T> key)
+ public void remove<T>(Key<T> key)
{
key.remove_from(get_items());
}
product/utility/Context.cs
@@ -11,22 +11,22 @@ namespace utility
this.items = items;
}
- public bool contains<T>(IKey<T> key)
+ public bool contains<T>(Key<T> key)
{
return key.is_found_in(items);
}
- public void add<T>(IKey<T> key, T value)
+ public void add<T>(Key<T> key, T value)
{
key.add_value_to(items, value);
}
- public T value_for<T>(IKey<T> key)
+ public T value_for<T>(Key<T> key)
{
return key.parse_from(items);
}
- public void remove<T>(IKey<T> key)
+ public void remove<T>(Key<T> key)
{
key.remove_from(items);
}
product/utility/IContext.cs
@@ -2,9 +2,9 @@
{
public interface IContext
{
- bool contains<T>(IKey<T> key);
- void add<T>(IKey<T> key, T value);
- T value_for<T>(IKey<T> key);
- void remove<T>(IKey<T> key);
+ bool contains<T>(Key<T> key);
+ void add<T>(Key<T> key, T value);
+ T value_for<T>(Key<T> key);
+ void remove<T>(Key<T> key);
}
}
\ No newline at end of file
product/utility/IKey.cs → product/utility/Key.cs
@@ -2,7 +2,7 @@
namespace utility
{
- public interface IKey<T>
+ public interface Key<T>
{
bool is_found_in(IDictionary items);
T parse_from(IDictionary items);
product/utility/MappingExtensions.cs
@@ -24,7 +24,7 @@ namespace utility
static public IEnumerable<Output> map_all_using<Input, Output>(this IEnumerable<Input> items,
Converter<Input, Output> mapper)
{
- return null == items ? new List<Output>() : items.Select(x => mapper(x));
+ return null == items ? Enumerable.Empty<Output>() : items.Select(x => mapper(x));
}
static public IEnumerable<Output> map_all_using<Input, Output>(this IEnumerable<Input> items,
product/utility/TypedKey.cs
@@ -2,7 +2,7 @@
namespace utility
{
- public class TypedKey<T> : IKey<T>
+ public class TypedKey<T> : Key<T>
{
public bool is_found_in(IDictionary items)
{
product/utility/utility.csproj
@@ -79,7 +79,7 @@
<Compile Include="IContextFactory.cs" />
<Compile Include="Id.cs" />
<Compile Include="Identifiable.cs" />
- <Compile Include="IKey.cs" />
+ <Compile Include="Key.cs" />
<Compile Include="Import.cs" />
<Compile Include="IScopedStorage.cs" />
<Compile Include="ListExtensions.cs" />