Commit 10388f4

mokhan <mokhan@ce5e1baf-6525-42e4-a1b2-857ea38da20a>
2009-02-26 16:38:44
implemented the update task, and restart command.
git-svn-id: https://svn.xp-dev.com/svn/mokhan-mo.money@14 ce5e1baf-6525-42e4-a1b2-857ea38da20a
1 parent d7c3168
trunk/src/MyMoney/Infrastructure/System/application_environment.cs
@@ -4,15 +4,21 @@ namespace MyMoney.Infrastructure.System
 {
     public interface IApplicationEnvironment
     {
-        void ShutDown();
+        void shut_down();
+        void restart();
     }
 
     public class application_environment : IApplicationEnvironment
     {
-        public void ShutDown()
+        public void shut_down()
         {
             Application.Exit();
             //Environment.Exit(Environment.ExitCode);
         }
+
+        public void restart()
+        {
+            Application.Restart();
+        }
     }
 }
\ No newline at end of file
trunk/src/MyMoney/Presentation/Model/Menu/File/Commands/exit_command.cs
@@ -6,12 +6,13 @@ using MyMoney.Utility.Core;
 namespace MyMoney.Presentation.Model.Menu.File.Commands
 {
     public interface IExitCommand : ICommand
-    {}
+    {
+    }
 
     public class exit_command : IExitCommand
     {
-        private readonly IApplicationEnvironment application;
-        private readonly IEventAggregator broker;
+        readonly IApplicationEnvironment application;
+        readonly IEventAggregator broker;
 
         public exit_command(IApplicationEnvironment application, IEventAggregator broker)
         {
@@ -22,7 +23,7 @@ namespace MyMoney.Presentation.Model.Menu.File.Commands
         public void run()
         {
             broker.publish<closing_the_application>();
-            application.ShutDown();
+            application.shut_down();
         }
     }
 }
\ No newline at end of file
trunk/src/MyMoney/Presentation/Model/Menu/File/Commands/exit_command_specs.cs
@@ -11,7 +11,7 @@ namespace MyMoney.Presentation.Model.Menu.File.Commands
     [Concern(typeof (exit_command))]
     public class when_closing_the_application : concerns_for<IExitCommand, exit_command>
     {
-        it should_ask_the_application_environment_to_shut_down = () => application.was_told_to(x => x.ShutDown());
+        it should_ask_the_application_environment_to_shut_down = () => application.was_told_to(x => x.shut_down());
 
         it should_publish_the_shut_down_event = () => broker.was_told_to(x => x.publish<closing_the_application>());
 
trunk/src/MyMoney/Presentation/Model/messages/closing_the_application.cs
@@ -3,5 +3,6 @@ using MyMoney.Infrastructure.eventing;
 namespace MyMoney.Presentation.Model.messages
 {
     public class closing_the_application : IEvent
-    {}
+    {
+    }
 }
\ No newline at end of file
trunk/src/MyMoney/Presentation/Model/updates/ApplicationVersion.cs
@@ -4,5 +4,14 @@ namespace MyMoney.Presentation.Model.updates
 {
     public class ApplicationVersion
     {
+        public Uri activation_url { get; set; }
+        public Version current { get; set; }
+        public string data_directory { get; set; }
+        public bool updates_available { get; set; }
+        public DateTime last_checked_for_updates { get; set; }
+        public string application_name { get; set; }
+        public Uri deployment_url { get; set; }
+        public Version available_version { get; set; }
+        public long size_of_update_in_bytes { get; set; }
     }
 }
\ No newline at end of file
trunk/src/MyMoney/Presentation/Presenters/Commands/RestartCommand.cs
@@ -0,0 +1,29 @@
+using MyMoney.Infrastructure.eventing;
+using MyMoney.Infrastructure.System;
+using MyMoney.Presentation.Model.messages;
+using MyMoney.Utility.Core;
+
+namespace MyMoney.Presentation.Presenters.Commands
+{
+    public interface IRestartCommand : ICommand
+    {
+    }
+
+    public class RestartCommand : IRestartCommand
+    {
+        readonly IApplicationEnvironment application;
+        readonly IEventAggregator broker;
+
+        public RestartCommand(IApplicationEnvironment application, IEventAggregator broker)
+        {
+            this.application = application;
+            this.broker = broker;
+        }
+
+        public void run()
+        {
+            broker.publish<closing_the_application>();
+            application.restart();
+        }
+    }
+}
\ No newline at end of file
trunk/src/MyMoney/Presentation/Presenters/updates/CheckForUpdatesPresenter.cs
@@ -1,4 +1,5 @@
 using MyMoney.Presentation.Core;
+using MyMoney.Presentation.Presenters.Commands;
 using MyMoney.Presentation.Views.updates;
 using MyMoney.Tasks.infrastructure;
 using MyMoney.Utility.Core;
@@ -8,17 +9,21 @@ namespace MyMoney.Presentation.Presenters.updates
     public interface ICheckForUpdatesPresenter : IPresenter, ICallback
     {
         void begin_update();
+        void cancel_update();
+        void restart();
     }
 
     public class CheckForUpdatesPresenter : ICheckForUpdatesPresenter
     {
         readonly ICheckForUpdatesView view;
         readonly IUpdateTasks tasks;
+        readonly IRestartCommand command;
 
-        public CheckForUpdatesPresenter(ICheckForUpdatesView view, IUpdateTasks tasks)
+        public CheckForUpdatesPresenter(ICheckForUpdatesView view, IUpdateTasks tasks, IRestartCommand command)
         {
             this.view = view;
             this.tasks = tasks;
+            this.command = command;
         }
 
         public void run()
@@ -32,6 +37,16 @@ namespace MyMoney.Presentation.Presenters.updates
             tasks.grab_the_latest_version(this);
         }
 
+        public void cancel_update()
+        {
+            tasks.stop_updating();
+        }
+
+        public void restart()
+        {
+            command.run();
+        }
+
         public void complete()
         {
             view.update_complete();
trunk/src/MyMoney/Presentation/Presenters/updates/CheckForUpdatesPresenterSpecs.cs
@@ -1,5 +1,6 @@
 using jpboodhoo.bdd.contexts;
 using MyMoney.Presentation.Model.updates;
+using MyMoney.Presentation.Presenters.Commands;
 using MyMoney.Presentation.Views.updates;
 using MyMoney.Tasks.infrastructure;
 using MyMoney.Testing.MetaData;
@@ -9,21 +10,24 @@ using MyMoney.Testing.spechelpers.core;
 namespace MyMoney.Presentation.Presenters.updates
 {
     [Concern(typeof (CheckForUpdatesPresenter))]
-    public class behaves_like_check_for_updates_presenter : concerns_for<ICheckForUpdatesPresenter, CheckForUpdatesPresenter>
+    public class behaves_like_check_for_updates_presenter :
+        concerns_for<ICheckForUpdatesPresenter, CheckForUpdatesPresenter>
     {
         public override ICheckForUpdatesPresenter create_sut()
         {
-            return new CheckForUpdatesPresenter(view, tasks);
+            return new CheckForUpdatesPresenter(view, tasks, command);
         }
 
         context c = () =>
                         {
                             view = the_dependency<ICheckForUpdatesView>();
                             tasks = the_dependency<IUpdateTasks>();
+                            command = the_dependency<IRestartCommand>();
                         };
 
         protected static ICheckForUpdatesView view;
         protected static IUpdateTasks tasks;
+        protected static IRestartCommand command;
     }
 
     public class when_attempting_to_check_for_updates : behaves_like_check_for_updates_presenter
@@ -58,4 +62,19 @@ namespace MyMoney.Presentation.Presenters.updates
 
         because b = () => sut.complete();
     }
+
+    public class when_an_update_is_cancelled : behaves_like_check_for_updates_presenter
+    {
+        it should_stop_downloading_the_latest_update = () => tasks.was_told_to(x => x.stop_updating());
+
+        because b = () => sut.cancel_update();
+    }
+
+    public class when_an_update_is_complete_and_the_user_agrees_to_restart_the_application :
+        behaves_like_check_for_updates_presenter
+    {
+        it should_restart_the_application = () => command.run();
+
+        because b = () => sut.restart();
+    }
 }
\ No newline at end of file
trunk/src/MyMoney/Tasks/infrastructure/IUpdateTasks.cs
@@ -1,11 +0,0 @@
-using MyMoney.Presentation.Model.updates;
-using MyMoney.Utility.Core;
-
-namespace MyMoney.Tasks.infrastructure
-{
-    public interface IUpdateTasks
-    {
-        ApplicationVersion current_application_version();
-        void grab_the_latest_version(ICallback callback);
-    }
-}
\ No newline at end of file
trunk/src/MyMoney/Tasks/infrastructure/UpdateTasks.cs
@@ -0,0 +1,59 @@
+using System.Deployment.Application;
+using MyMoney.Presentation.Model.updates;
+using MyMoney.Utility.Core;
+
+namespace MyMoney.Tasks.infrastructure
+{
+    public interface IUpdateTasks
+    {
+        ApplicationVersion current_application_version();
+        void grab_the_latest_version(ICallback callback);
+        void stop_updating();
+    }
+
+    public class UpdateTasks : IUpdateTasks
+    {
+        readonly ApplicationDeployment deployment;
+
+        public UpdateTasks()
+        {
+            if (ApplicationDeployment.IsNetworkDeployed)
+            {
+                deployment = ApplicationDeployment.CurrentDeployment;
+            }
+        }
+
+        public ApplicationVersion current_application_version()
+        {
+            if (null == deployment)
+            {
+                return new ApplicationVersion {updates_available = false,};
+            }
+
+            var update = deployment.CheckForDetailedUpdate();
+            return new ApplicationVersion
+                       {
+                           activation_url = deployment.ActivationUri,
+                           current = deployment.CurrentVersion,
+                           data_directory = deployment.DataDirectory,
+                           updates_available = update.IsUpdateRequired || update.UpdateAvailable,
+                           last_checked_for_updates = deployment.TimeOfLastUpdateCheck,
+                           application_name = deployment.UpdatedApplicationFullName,
+                           deployment_url = deployment.UpdateLocation,
+                           available_version = update.AvailableVersion,
+                           size_of_update_in_bytes=update.UpdateSizeBytes,
+                       };
+        }
+
+        public void grab_the_latest_version(ICallback callback)
+        {
+            deployment.UpdateCompleted += (sender, args) => callback.complete();
+            deployment.UpdateAsync();
+        }
+
+        public void stop_updating()
+        {
+            deployment.UpdateAsyncCancel();
+        }
+    }
+}
\ No newline at end of file
trunk/src/MyMoney/MyMoney.csproj
@@ -287,6 +287,7 @@
     <Compile Include="Presentation\Presenters\billing\dto\bill_information_dto.cs" />
     <Compile Include="Presentation\Presenters\billing\dto\register_new_company.cs" />
     <Compile Include="Presentation\Presenters\billing\view_all_bills_presenter.cs" />
+    <Compile Include="Presentation\Presenters\Commands\RestartCommand.cs" />
     <Compile Include="Presentation\Presenters\Commands\run_presenter_command.cs" />
     <Compile Include="Presentation\Presenters\Commands\run_the.cs" />
     <Compile Include="Presentation\Presenters\Commands\run_the_specs.cs" />
@@ -410,7 +411,7 @@
     <Compile Include="Tasks\application\customer_tasks.cs" />
     <Compile Include="Tasks\application\file_system_tasks.cs" />
     <Compile Include="Tasks\application\income_tasks.cs" />
-    <Compile Include="Tasks\infrastructure\IUpdateTasks.cs" />
+    <Compile Include="Tasks\infrastructure\UpdateTasks.cs" />
     <Compile Include="Testing\spechelpers\contexts\concerns_for.cs" />
     <Compile Include="Testing\spechelpers\contexts\behaves_like_a_repository.cs" />
     <Compile Include="Testing\spechelpers\core\IHideObjectMembers.cs" />