Commit c720e3f
Changed files (8)
trunk
product
MyMoney
Domain
Core
Presentation
Presenters
Views
Tasks
infrastructure
trunk/product/MyMoney/Domain/Core/Money.cs
@@ -14,13 +14,15 @@ namespace MoMoney.Domain.Core
internal class Money : IMoney
{
public Money(long dollars) : this(dollars, 0)
- {}
+ {
+ }
public Money(long dollars, int cents)
{
this.dollars = dollars;
this.cents = cents;
- if (this.cents >= 100) {
+ if (this.cents >= 100)
+ {
this.dollars += (this.cents/100).to_long();
this.cents = this.cents%100;
}
@@ -32,7 +34,8 @@ namespace MoMoney.Domain.Core
public IMoney add(IMoney other)
{
var new_dollars = dollars + other.dollars;
- if (other.cents + cents > 100) {
+ if (other.cents + cents > 100)
+ {
++new_dollars;
var pennies = cents + other.cents - 100;
return new Money(new_dollars, pennies);
@@ -51,7 +54,8 @@ namespace MoMoney.Domain.Core
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
- if (typeof (IMoney).IsAssignableFrom(obj.GetType())) {
+ if (typeof (IMoney).IsAssignableFrom(obj.GetType()))
+ {
return Equals((IMoney) obj);
}
return false;
@@ -59,7 +63,8 @@ namespace MoMoney.Domain.Core
public override int GetHashCode()
{
- unchecked {
+ unchecked
+ {
return (dollars.GetHashCode()*397) ^ cents;
}
}
trunk/product/MyMoney/Domain/Core/Percent.cs
@@ -0,0 +1,46 @@
+namespace MoMoney.Domain.Core
+{
+ public class Percent
+ {
+ readonly long whole;
+ readonly long fraction;
+
+ public Percent(long whole) : this(whole, 0)
+ {
+ }
+
+ public Percent(long whole, int fraction)
+ {
+ this.whole = whole;
+ this.fraction = fraction;
+ }
+
+ static public implicit operator Percent(int whole)
+ {
+ return new Percent(whole);
+ }
+
+ public bool Equals(Percent other)
+ {
+ if (ReferenceEquals(null, other)) return false;
+ if (ReferenceEquals(this, other)) return true;
+ return other.whole == whole && other.fraction == fraction;
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ if (ReferenceEquals(this, obj)) return true;
+ if (obj.GetType() != typeof (Percent)) return false;
+ return Equals((Percent) obj);
+ }
+
+ public override int GetHashCode()
+ {
+ unchecked
+ {
+ return (whole.GetHashCode()*397) ^ fraction.GetHashCode();
+ }
+ }
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Presenters/updates/CheckForUpdatesPresenter.cs
@@ -1,3 +1,4 @@
+using MoMoney.Domain.Core;
using MoMoney.Presentation.Core;
using MoMoney.Presentation.Presenters.Commands;
using MoMoney.Presentation.Views.updates;
@@ -6,7 +7,7 @@ using MoMoney.Utility.Core;
namespace MoMoney.Presentation.Presenters.updates
{
- public interface ICheckForUpdatesPresenter : IPresenter, ICallback
+ public interface ICheckForUpdatesPresenter : IPresenter, ICallback<Percent>
{
void begin_update();
void cancel_update();
@@ -53,9 +54,12 @@ namespace MoMoney.Presentation.Presenters.updates
view.close();
}
- public void complete()
+ public void complete(Percent completed)
{
- view.update_complete();
+ if (completed.Equals(new Percent(100)))
+ view.update_complete();
+ else
+ view.downloaded(completed);
}
}
}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Presenters/updates/CheckForUpdatesPresenterSpecs.cs
@@ -10,13 +10,9 @@ using MoMoney.Testing.spechelpers.core;
namespace MoMoney.Presentation.Presenters.updates
{
[Concern(typeof (CheckForUpdatesPresenter))]
- public abstract class behaves_like_check_for_updates_presenter : concerns_for<ICheckForUpdatesPresenter, CheckForUpdatesPresenter>
+ public abstract class behaves_like_check_for_updates_presenter :
+ concerns_for<ICheckForUpdatesPresenter, CheckForUpdatesPresenter>
{
- //public override ICheckForUpdatesPresenter create_sut()
- //{
- // return new CheckForUpdatesPresenter(view, tasks, command);
- //}
-
context c = () =>
{
view = the_dependency<ICheckForUpdatesView>();
@@ -24,9 +20,9 @@ namespace MoMoney.Presentation.Presenters.updates
command = the_dependency<IRestartCommand>();
};
- protected static ICheckForUpdatesView view;
- protected static IUpdateTasks tasks;
- protected static IRestartCommand command;
+ static protected ICheckForUpdatesView view;
+ static protected IUpdateTasks tasks;
+ static protected IRestartCommand command;
}
public class when_attempting_to_check_for_updates : behaves_like_check_for_updates_presenter
@@ -55,11 +51,18 @@ namespace MoMoney.Presentation.Presenters.updates
because b = () => sut.begin_update();
}
+ public class when_downloading_an_update : behaves_like_check_for_updates_presenter
+ {
+ it should_notify_you_of_the_progress_of_the_update = () => view.was_told_to(x => x.downloaded(50));
+
+ because b = () => sut.complete(50);
+ }
+
public class when_an_update_is_completed : behaves_like_check_for_updates_presenter
{
it should_notify_the_view_that_the_update_is_complete = () => view.was_told_to(x => x.update_complete());
- because b = () => sut.complete();
+ because b = () => sut.complete(100);
}
public class when_an_update_is_cancelled : behaves_like_check_for_updates_presenter
trunk/product/MyMoney/Presentation/Views/updates/CheckForUpdatesView.cs
@@ -1,5 +1,6 @@
using System.Reflection;
using System.Windows.Forms;
+using MoMoney.Domain.Core;
using MoMoney.Presentation.Model.updates;
using MoMoney.Presentation.Presenters.updates;
using MoMoney.Presentation.Resources;
@@ -47,9 +48,12 @@ namespace MoMoney.Presentation.Views.updates
ShowDialog();
}
+ public void downloaded(Percent percentage_complete)
+ {
+ }
+
public void update_complete()
{
- //execute(()=> MessageBox.Show("update complete, the application will now restart.", "Complete", MessageBoxButtons.OK));
MessageBox.Show("update complete, the application will now restart.", "Complete", MessageBoxButtons.OK);
the_presenter.restart();
}
trunk/product/MyMoney/Presentation/Views/updates/ICheckForUpdatesView.cs
@@ -1,3 +1,4 @@
+using MoMoney.Domain.Core;
using MoMoney.Presentation.Model.updates;
using MoMoney.Presentation.Presenters.updates;
using MoMoney.Presentation.Views.core;
@@ -7,6 +8,7 @@ namespace MoMoney.Presentation.Views.updates
public interface ICheckForUpdatesView : IView<ICheckForUpdatesPresenter>
{
void display(ApplicationVersion information);
+ 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 MoMoney.Domain.Core;
using MoMoney.Presentation.Model.updates;
using MoMoney.Utility.Core;
@@ -7,7 +8,7 @@ namespace MoMoney.Tasks.infrastructure
public interface IUpdateTasks
{
ApplicationVersion current_application_version();
- void grab_the_latest_version(ICallback callback);
+ void grab_the_latest_version(ICallback<Percent> callback);
void stop_updating();
}
@@ -45,9 +46,10 @@ namespace MoMoney.Tasks.infrastructure
};
}
- public void grab_the_latest_version(ICallback callback)
+ public void grab_the_latest_version(ICallback<Percent> callback)
{
- deployment.UpdateCompleted += (sender, args) => callback.complete();
+ deployment.UpdateProgressChanged += (o, e) => callback.complete(new Percent(e.BytesCompleted/e.BytesTotal));
+ deployment.UpdateCompleted += (sender, args) => callback.complete(new Percent(100));
deployment.UpdateAsync();
}
trunk/product/MyMoney/MyMoney.csproj
@@ -189,6 +189,7 @@
<Compile Include="Domain\Core\MoneyExtensions.cs" />
<Compile Include="Domain\Core\MoneyExtensionsSpecs.cs" />
<Compile Include="Domain\Core\MoneySpecs.cs" />
+ <Compile Include="Domain\Core\Percent.cs" />
<Compile Include="Domain\Core\range.cs" />
<Compile Include="Domain\Core\range_specs.cs" />
<Compile Include="Domain\repositories\IBillRepository.cs" />