Commit f8745c1
Changed files (7)
trunk
product
MyMoney
Presentation
Presenters
Views
Tasks
infrastructure
Utility
Core
trunk/product/MyMoney/Presentation/Presenters/updates/CheckForUpdatesPresenter.cs
@@ -1,5 +1,7 @@
using MoMoney.Domain.Core;
+using MoMoney.Infrastructure.Threading;
using MoMoney.Presentation.Core;
+using MoMoney.Presentation.Model.updates;
using MoMoney.Presentation.Presenters.Commands;
using MoMoney.Presentation.Views.updates;
using MoMoney.Tasks.infrastructure;
@@ -20,10 +22,13 @@ namespace MoMoney.Presentation.Presenters.updates
readonly ICheckForUpdatesView view;
readonly IUpdateTasks tasks;
readonly IRestartCommand command;
+ readonly ICommandProcessor processor;
- public CheckForUpdatesPresenter(ICheckForUpdatesView view, IUpdateTasks tasks, IRestartCommand command)
+ public CheckForUpdatesPresenter(ICheckForUpdatesView view, IUpdateTasks tasks, IRestartCommand command,
+ ICommandProcessor processor)
{
this.view = view;
+ this.processor = processor;
this.tasks = tasks;
this.command = command;
}
@@ -31,7 +36,12 @@ namespace MoMoney.Presentation.Presenters.updates
public void run()
{
view.attach_to(this);
- view.display(tasks.current_application_version());
+ processor.add(
+ new RunQueryCommand<ApplicationVersion>(
+ view,
+ new ProcessQueryCommand<ApplicationVersion>(new WhatIsTheAvailableVersion(tasks)))
+ );
+ view.display();
}
public void begin_update()
@@ -42,6 +52,7 @@ namespace MoMoney.Presentation.Presenters.updates
public void cancel_update()
{
tasks.stop_updating();
+ view.close();
}
public void restart()
@@ -56,10 +67,63 @@ namespace MoMoney.Presentation.Presenters.updates
public void run(Percent completed)
{
- if (completed.Equals(new Percent(100)))
- view.update_complete();
- else
- view.downloaded(completed);
+ if (completed.Equals(new Percent(100))) view.update_complete();
+ else view.downloaded(completed);
+ }
+ }
+
+ public interface IProcessQueryCommand<T> : IParameterizedCommand<ICallback<T>>
+ {
+ }
+
+ public class ProcessQueryCommand<T> : IProcessQueryCommand<T>
+ {
+ readonly IQuery<T> query;
+
+ public ProcessQueryCommand(IQuery<T> query)
+ {
+ this.query = query;
+ }
+
+ public void run(ICallback<T> item)
+ {
+ item.run(query.fetch());
+ }
+ }
+
+ public interface IRunQueryCommand<T> : ICommand
+ {
+ }
+
+ public class RunQueryCommand<T> : IRunQueryCommand<T>
+ {
+ readonly ICallback<T> callback;
+ readonly IProcessQueryCommand<T> command;
+
+ public RunQueryCommand(ICallback<T> callback, IProcessQueryCommand<T> command)
+ {
+ this.callback = callback;
+ this.command = command;
+ }
+
+ public void run()
+ {
+ command.run(callback);
+ }
+ }
+
+ public class WhatIsTheAvailableVersion : IQuery<ApplicationVersion>
+ {
+ readonly IUpdateTasks tasks;
+
+ public WhatIsTheAvailableVersion(IUpdateTasks tasks)
+ {
+ this.tasks = tasks;
+ }
+
+ public ApplicationVersion fetch()
+ {
+ return tasks.current_application_version();
}
}
}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Presenters/updates/CheckForUpdatesPresenterSpecs.cs
@@ -30,7 +30,7 @@ namespace MoMoney.Presentation.Presenters.updates
it should_tell_the_view_to_attach_itself_to_the_presenter = () => view.was_told_to(x => x.attach_to(sut));
it should_tell_the_view_to_display_the_information_on_the_current_version_of_the_application =
- () => view.was_told_to(x => x.display(version));
+ () => view.was_told_to(x => x.display());
context c = () =>
{
trunk/product/MyMoney/Presentation/Views/updates/CheckForUpdatesView.cs
@@ -1,5 +1,4 @@
-using System;
-using System.Reflection;
+using System.Reflection;
using System.Windows.Forms;
using MoMoney.Domain.Core;
using MoMoney.Presentation.Model.updates;
@@ -27,37 +26,45 @@ namespace MoMoney.Presentation.Views.updates
public void attach_to(ICheckForUpdatesPresenter presenter)
{
- ux_update_button.Click += (sender, e) => presenter.begin_update();
- ux_dont_update_button.Click += (sender, e) => presenter.do_not_update();
- ux_cancel_button.Click += (sender, e) => presenter.cancel_update();
- the_presenter = presenter;
+ on_ui_thread(() =>
+ {
+ ux_update_button.Click += (sender, e) =>
+ {
+ ux_update_button.Enabled = false;
+ ux_dont_update_button.Enabled = false;
+ ux_cancel_button.Enabled = true;
+ presenter.begin_update();
+ };
+ ux_dont_update_button.Click += (sender, e) => presenter.do_not_update();
+ ux_cancel_button.Click += (sender, e) => presenter.cancel_update();
+ the_presenter = presenter;
+ });
}
- public void display(ApplicationVersion information)
+ public void display()
{
- if (information.updates_available)
- {
- ux_update_button.Enabled = information.updates_available;
- ux_current_version.Text = "Current: " + information.current;
- ux_new_version.Text = "New: " + information.available_version;
- }
- else
- {
- ux_current_version.Text = "Current: " + Assembly.GetExecutingAssembly().GetName().Version;
- ux_new_version.Text = "New: " + Assembly.GetExecutingAssembly().GetName().Version;
- }
- ShowDialog();
+ on_ui_thread(() =>
+ {
+ ux_update_button.Enabled = false;
+ ux_dont_update_button.Enabled = false;
+ ux_cancel_button.Enabled = false;
+ Show();
+ //ShowDialog();
+ });
}
public void downloaded(Percent percentage_complete)
{
- while (percentage_complete.is_less_than(progress_bar.Value))
- {
- if (percentage_complete.represents(progress_bar.Value))
- break;
+ on_ui_thread(() =>
+ {
+ while (percentage_complete.is_less_than(progress_bar.Value))
+ {
+ if (percentage_complete.represents(progress_bar.Value))
+ break;
- progress_bar.PerformStep();
- }
+ progress_bar.PerformStep();
+ }
+ });
}
public void update_complete()
@@ -67,7 +74,33 @@ namespace MoMoney.Presentation.Views.updates
public void close()
{
- Close();
+ on_ui_thread(() => { Close(); });
+ }
+
+ public void run(ApplicationVersion information)
+ {
+ on_ui_thread(
+ () =>
+ {
+ if (information.updates_available)
+ {
+ ux_update_button.Enabled = true;
+ ux_dont_update_button.Enabled = true;
+ ux_cancel_button.Enabled = true;
+ ux_update_button.Enabled = information.updates_available;
+ ux_current_version.Text = "Current: " + information.current;
+ ux_new_version.Text = "New: " + information.available_version;
+ }
+ else
+ {
+ ux_update_button.Enabled = false;
+ ux_dont_update_button.Enabled = true;
+ ux_cancel_button.Enabled = false;
+ ux_current_version.Text = "Current: " +
+ Assembly.GetExecutingAssembly().GetName().Version;
+ ux_new_version.Text = "New: " + Assembly.GetExecutingAssembly().GetName().Version;
+ }
+ });
}
}
}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Views/updates/ICheckForUpdatesView.cs
@@ -2,12 +2,13 @@ using MoMoney.Domain.Core;
using MoMoney.Presentation.Model.updates;
using MoMoney.Presentation.Presenters.updates;
using MoMoney.Presentation.Views.core;
+using MoMoney.Utility.Core;
namespace MoMoney.Presentation.Views.updates
{
- public interface ICheckForUpdatesView : IView<ICheckForUpdatesPresenter>
+ public interface ICheckForUpdatesView : IView<ICheckForUpdatesPresenter>, ICallback<ApplicationVersion>
{
- void display(ApplicationVersion information);
+ void display();
void downloaded(Percent percentage_complete);
void update_complete();
void close();
trunk/product/MyMoney/Tasks/infrastructure/UpdateTasks.cs
@@ -1,4 +1,5 @@
using System.Deployment.Application;
+using System.Threading;
using MoMoney.Domain.Core;
using MoMoney.Presentation.Model.updates;
using MoMoney.Utility.Core;
@@ -28,6 +29,7 @@ namespace MoMoney.Tasks.infrastructure
{
if (null == deployment)
{
+ Thread.Sleep(5000);
return new ApplicationVersion {updates_available = false,};
}
trunk/product/MyMoney/Utility/Core/IQuery.cs
@@ -0,0 +1,7 @@
+namespace MoMoney.Utility.Core
+{
+ public interface IQuery<T>
+ {
+ T fetch();
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/MyMoney.csproj
@@ -586,6 +586,7 @@
<Compile Include="Utility\Core\IDisposableCommand.cs" />
<Compile Include="Utility\Core\IFactory.cs" />
<Compile Include="Utility\Core\IParameterizedCommand.cs" />
+ <Compile Include="Utility\Core\IQuery.cs" />
<Compile Include="Utility\Core\IState.cs" />
<Compile Include="Utility\Core\IStateContext.cs" />
<Compile Include="Utility\Core\IValueReturningVisitor.cs" />