Commit 5da4aa7

mokhan <mokhan@ce5e1baf-6525-42e4-a1b2-857ea38da20a>
2009-03-30 03:32:26
git-svn-id: https://svn.xp-dev.com/svn/mokhan-mo.money@127 ce5e1baf-6525-42e4-a1b2-857ea38da20a
1 parent e602071
trunk/product/MyMoney/boot/container/registration/wire_up_the_essential_services_into_the.cs
@@ -6,6 +6,7 @@ using MoMoney.Infrastructure.Container;
 using MoMoney.Infrastructure.Logging;
 using MoMoney.Infrastructure.Logging.Log4NetLogging;
 using MoMoney.Infrastructure.Threading;
+using MoMoney.Tasks.infrastructure.updating;
 using MoMoney.Utility.Core;
 
 namespace MoMoney.boot.container.registration
@@ -35,7 +36,8 @@ namespace MoMoney.boot.container.registration
                         return SynchronizationContext.Current;
                     });
             registration.singleton<AsyncOperation>(() => AsyncOperationManager.CreateOperation(null));
-            registration.singleton<ApplicationDeployment>( () => ApplicationDeployment.IsNetworkDeployed ? ApplicationDeployment.CurrentDeployment : null);
+            registration.singleton<ApplicationDeployment>(() => ApplicationDeployment.IsNetworkDeployed ? ApplicationDeployment.CurrentDeployment : null);
+            registration.singleton<IDeployment>(() => ApplicationDeployment.IsNetworkDeployed ? (IDeployment)new CurrentDeployment() : (IDeployment)new NullDeployment());
         }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/boot/container/wire_up_the_container.cs
@@ -9,8 +9,8 @@ namespace MoMoney.boot.container
 {
     internal class wire_up_the_container : ICommand
     {
-        IDependencyRegistration registry;
-        IComponentExclusionSpecification specification;
+        readonly IDependencyRegistration registry;
+        readonly IComponentExclusionSpecification specification;
 
         public wire_up_the_container()
             : this(new AutofacDependencyRegistryBuilder(), new ComponentExclusionSpecification())
trunk/product/MyMoney/boot/check_for_updates.cs
@@ -1,41 +0,0 @@
-using System.Deployment.Application;
-using System.Windows.Forms;
-using MoMoney.Infrastructure.Extensions;
-using MoMoney.Utility.Core;
-
-namespace MoMoney.windows.ui
-{
-    public class check_for_updates : ICommand
-    {
-        private readonly ApplicationDeployment deployment;
-
-        public check_for_updates()
-        {
-            if (!ApplicationDeployment.IsNetworkDeployed) {
-                return;
-            }
-            deployment = ApplicationDeployment.CurrentDeployment;
-        }
-
-        public void run()
-        {
-            if (null == deployment) {
-                return;
-            }
-            if (deployment.IsFirstRun) {
-                this.log().debug("this is the first time the application is run");
-                MessageBox.Show("It looks like this is the first time you've used this application", "Welcome");
-                return;
-            }
-            if (deployment.CheckForUpdate()) {
-                MessageBox.Show("Looks like there are updates...", "Updates are available");
-                this.log().debug("starting_update");
-                deployment.Update();
-                this.log().debug("update completed");
-                MessageBox.Show("Updates were downloaded. The application will restart now", "Restarting application");
-                Application.Restart();
-                this.log().debug("restarting application");
-            }
-        }
-    }
-}
\ No newline at end of file
trunk/product/MyMoney/Tasks/infrastructure/updating/CancelUpdate.cs
@@ -1,4 +1,3 @@
-using System.Deployment.Application;
 using MoMoney.Utility.Core;
 
 namespace MoMoney.Tasks.infrastructure.updating
@@ -9,9 +8,9 @@ namespace MoMoney.Tasks.infrastructure.updating
 
     public class CancelUpdate : ICancelUpdate
     {
-        readonly ApplicationDeployment deployment;
+        readonly IDeployment deployment;
 
-        public CancelUpdate(ApplicationDeployment deployment)
+        public CancelUpdate(IDeployment deployment)
         {
             this.deployment = deployment;
         }
trunk/product/MyMoney/Tasks/infrastructure/updating/CancelUpdateSpecs.cs
@@ -1,6 +1,4 @@
-using System.Deployment.Application;
 using developwithpassion.bdd.contexts;
-using MbUnit.Framework;
 using MoMoney.Testing.spechelpers.contexts;
 using MoMoney.Testing.spechelpers.core;
 
@@ -10,15 +8,14 @@ namespace MoMoney.Tasks.infrastructure.updating
     {
     }
 
-    [Ignore("cant mock ApplicationDeployment")]
     public class when_cancelling_an_update_of_the_application : concerns_for<ICancelUpdate, CancelUpdate>
     {
         it should_stop_downloading_the_update = () => deployment.was_told_to(x => x.UpdateAsyncCancel());
 
-        context c = () => { deployment = the_dependency<ApplicationDeployment>(); };
+        context c = () => { deployment = the_dependency<IDeployment>(); };
 
         because b = () => sut.run();
 
-        static ApplicationDeployment deployment;
+        static IDeployment deployment;
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Tasks/infrastructure/updating/CurrentDeployment.cs
@@ -0,0 +1,162 @@
+using System;
+using System.ComponentModel;
+using System.Deployment.Application;
+
+namespace MoMoney.Tasks.infrastructure.updating
+{
+    public class CurrentDeployment : IDeployment
+    {
+        readonly ApplicationDeployment deployment;
+
+        public CurrentDeployment()
+        {
+            deployment = ApplicationDeployment.CurrentDeployment;
+        }
+
+        public UpdateCheckInfo CheckForDetailedUpdate()
+        {
+            return deployment.CheckForDetailedUpdate();
+        }
+
+        public UpdateCheckInfo CheckForDetailedUpdate(bool persistUpdateCheckResult)
+        {
+            return deployment.CheckForDetailedUpdate(persistUpdateCheckResult);
+        }
+
+        public bool CheckForUpdate()
+        {
+            return deployment.CheckForUpdate();
+        }
+
+        public bool CheckForUpdate(bool persistUpdateCheckResult)
+        {
+            return deployment.CheckForUpdate(persistUpdateCheckResult);
+        }
+
+        public void CheckForUpdateAsync()
+        {
+            deployment.CheckForUpdateAsync();
+        }
+
+        public void CheckForUpdateAsyncCancel()
+        {
+            deployment.CheckForUpdateAsyncCancel();
+        }
+
+        public bool Update()
+        {
+            return deployment.Update();
+        }
+
+        public void UpdateAsync()
+        {
+            deployment.UpdateAsync();
+        }
+
+        public void UpdateAsyncCancel()
+        {
+            deployment.UpdateAsyncCancel();
+        }
+
+        public void DownloadFileGroup(string groupName)
+        {
+            deployment.DownloadFileGroup(groupName);
+        }
+
+        public void DownloadFileGroupAsync(string groupName)
+        {
+            deployment.DownloadFileGroupAsync(groupName);
+        }
+
+        public void DownloadFileGroupAsync(string groupName, object userState)
+        {
+            deployment.DownloadFileGroupAsync(groupName, userState);
+        }
+
+        public bool IsFileGroupDownloaded(string groupName)
+        {
+            return deployment.IsFileGroupDownloaded(groupName);
+        }
+
+        public void DownloadFileGroupAsyncCancel(string groupName)
+        {
+            deployment.DownloadFileGroupAsyncCancel(groupName);
+        }
+
+        public Version CurrentVersion
+        {
+            get { return deployment.CurrentVersion; }
+        }
+
+        public Version UpdatedVersion
+        {
+            get { return deployment.UpdatedVersion; }
+        }
+
+        public string UpdatedApplicationFullName
+        {
+            get { return deployment.UpdatedApplicationFullName; }
+        }
+
+        public DateTime TimeOfLastUpdateCheck
+        {
+            get { return deployment.TimeOfLastUpdateCheck; }
+        }
+
+        public Uri UpdateLocation
+        {
+            get { return deployment.UpdateLocation; }
+        }
+
+        public Uri ActivationUri
+        {
+            get { return deployment.ActivationUri; }
+        }
+
+        public string DataDirectory
+        {
+            get { return deployment.DataDirectory; }
+        }
+
+        public bool IsFirstRun
+        {
+            get { return deployment.IsFirstRun; }
+        }
+
+        public event DeploymentProgressChangedEventHandler CheckForUpdateProgressChanged
+        {
+            add { deployment.CheckForUpdateProgressChanged += value; }
+            remove { deployment.CheckForUpdateProgressChanged -= value; }
+        }
+
+        public event CheckForUpdateCompletedEventHandler CheckForUpdateCompleted
+        {
+            add { deployment.CheckForUpdateCompleted += value; }
+            remove { deployment.CheckForUpdateCompleted -= value; }
+        }
+
+        public event DeploymentProgressChangedEventHandler UpdateProgressChanged
+        {
+            add { deployment.UpdateProgressChanged += value; }
+            remove { deployment.UpdateProgressChanged -= value; }
+        }
+
+        public event AsyncCompletedEventHandler UpdateCompleted
+        {
+            add { deployment.UpdateCompleted += value; }
+            remove { deployment.UpdateCompleted -= value; }
+        }
+
+        public event DeploymentProgressChangedEventHandler DownloadFileGroupProgressChanged
+        {
+            add { deployment.DownloadFileGroupProgressChanged += value; }
+            remove { deployment.DownloadFileGroupProgressChanged -= value; }
+        }
+
+        public event DownloadFileGroupCompletedEventHandler DownloadFileGroupCompleted
+        {
+            add { deployment.DownloadFileGroupCompleted += value; }
+            remove { deployment.DownloadFileGroupCompleted -= value; }
+        }
+    }
+}
\ No newline at end of file
trunk/product/MyMoney/Tasks/infrastructure/updating/DownloadTheLatestVersion.cs
@@ -1,4 +1,3 @@
-using System.Deployment.Application;
 using MoMoney.Domain.Core;
 using MoMoney.Tasks.infrastructure.core;
 using MoMoney.Utility.Core;
@@ -11,9 +10,9 @@ namespace MoMoney.Tasks.infrastructure.updating
 
     public class DownloadTheLatestVersion : IDownloadTheLatestVersion
     {
-        readonly ApplicationDeployment deployment;
+        readonly IDeployment deployment;
 
-        public DownloadTheLatestVersion(ApplicationDeployment deployment)
+        public DownloadTheLatestVersion(IDeployment deployment)
         {
             this.deployment = deployment;
         }
trunk/product/MyMoney/Tasks/infrastructure/updating/IDeployment.cs
@@ -0,0 +1,38 @@
+using System;
+using System.ComponentModel;
+using System.Deployment.Application;
+
+namespace MoMoney.Tasks.infrastructure.updating
+{
+    public interface IDeployment
+    {
+        UpdateCheckInfo CheckForDetailedUpdate();
+        UpdateCheckInfo CheckForDetailedUpdate(bool persistUpdateCheckResult);
+        bool CheckForUpdate();
+        bool CheckForUpdate(bool persistUpdateCheckResult);
+        void CheckForUpdateAsync();
+        void CheckForUpdateAsyncCancel();
+        bool Update();
+        void UpdateAsync();
+        void UpdateAsyncCancel();
+        void DownloadFileGroup(string groupName);
+        void DownloadFileGroupAsync(string groupName);
+        void DownloadFileGroupAsync(string groupName, object userState);
+        bool IsFileGroupDownloaded(string groupName);
+        void DownloadFileGroupAsyncCancel(string groupName);
+        Version CurrentVersion { get; }
+        Version UpdatedVersion { get; }
+        string UpdatedApplicationFullName { get; }
+        DateTime TimeOfLastUpdateCheck { get; }
+        Uri UpdateLocation { get; }
+        Uri ActivationUri { get; }
+        string DataDirectory { get; }
+        bool IsFirstRun { get; }
+        event DeploymentProgressChangedEventHandler CheckForUpdateProgressChanged;
+        event CheckForUpdateCompletedEventHandler CheckForUpdateCompleted;
+        event DeploymentProgressChangedEventHandler UpdateProgressChanged;
+        event AsyncCompletedEventHandler UpdateCompleted;
+        event DeploymentProgressChangedEventHandler DownloadFileGroupProgressChanged;
+        event DownloadFileGroupCompletedEventHandler DownloadFileGroupCompleted;
+    }
+}
\ No newline at end of file
trunk/product/MyMoney/Tasks/infrastructure/updating/NullDeployment.cs
@@ -0,0 +1,120 @@
+using System;
+using System.ComponentModel;
+using System.Deployment.Application;
+using System.Threading;
+
+namespace MoMoney.Tasks.infrastructure.updating
+{
+    public class NullDeployment : IDeployment
+    {
+        public UpdateCheckInfo CheckForDetailedUpdate()
+        {
+            Thread.Sleep(5000);
+            return null;
+        }
+
+        public UpdateCheckInfo CheckForDetailedUpdate(bool persistUpdateCheckResult)
+        {
+            throw new NotImplementedException();
+        }
+
+        public bool CheckForUpdate()
+        {
+            return false;
+        }
+
+        public bool CheckForUpdate(bool persistUpdateCheckResult)
+        {
+            return false;
+        }
+
+        public void CheckForUpdateAsync()
+        {
+        }
+
+        public void CheckForUpdateAsyncCancel()
+        {
+        }
+
+        public bool Update()
+        {
+            return false;
+        }
+
+        public void UpdateAsync()
+        {
+        }
+
+        public void UpdateAsyncCancel()
+        {
+        }
+
+        public void DownloadFileGroup(string groupName)
+        {
+        }
+
+        public void DownloadFileGroupAsync(string groupName)
+        {
+        }
+
+        public void DownloadFileGroupAsync(string groupName, object userState)
+        {
+        }
+
+        public bool IsFileGroupDownloaded(string groupName)
+        {
+            return false;
+        }
+
+        public void DownloadFileGroupAsyncCancel(string groupName)
+        {
+        }
+
+        public Version CurrentVersion
+        {
+            get { throw new NotImplementedException(); }
+        }
+
+        public Version UpdatedVersion
+        {
+            get { throw new NotImplementedException(); }
+        }
+
+        public string UpdatedApplicationFullName
+        {
+            get { throw new NotImplementedException(); }
+        }
+
+        public DateTime TimeOfLastUpdateCheck
+        {
+            get { throw new NotImplementedException(); }
+        }
+
+        public Uri UpdateLocation
+        {
+            get { throw new NotImplementedException(); }
+        }
+
+        public Uri ActivationUri
+        {
+            get { throw new NotImplementedException(); }
+        }
+
+        public string DataDirectory
+        {
+            get { throw new NotImplementedException(); }
+        }
+
+        public bool IsFirstRun
+        {
+            get { throw new NotImplementedException(); }
+        }
+
+        public event DeploymentProgressChangedEventHandler CheckForUpdateProgressChanged;
+        public event CheckForUpdateCompletedEventHandler CheckForUpdateCompleted;
+        public event DeploymentProgressChangedEventHandler UpdateProgressChanged;
+        public event AsyncCompletedEventHandler UpdateCompleted;
+        public event DeploymentProgressChangedEventHandler DownloadFileGroupProgressChanged;
+        public event DownloadFileGroupCompletedEventHandler DownloadFileGroupCompleted;
+    }
+}
\ No newline at end of file
trunk/product/MyMoney/Tasks/infrastructure/updating/WhatIsTheAvailableVersion.cs
@@ -1,5 +1,3 @@
-using System.Deployment.Application;
-using System.Threading;
 using MoMoney.Presentation.Model.updates;
 using MoMoney.Utility.Core;
 
@@ -11,22 +9,20 @@ namespace MoMoney.Tasks.infrastructure.updating
 
     public class WhatIsTheAvailableVersion : IWhatIsTheAvailableVersion
     {
-        readonly ApplicationDeployment deployment;
+        readonly IDeployment deployment;
 
-        public WhatIsTheAvailableVersion(ApplicationDeployment deployment)
+        public WhatIsTheAvailableVersion(IDeployment deployment)
         {
             this.deployment = deployment;
         }
 
         public ApplicationVersion fetch()
         {
-            if (null == deployment)
+            var update = deployment.CheckForDetailedUpdate();
+            if (null == update)
             {
-                Thread.Sleep(5000);
                 return new ApplicationVersion {updates_available = false,};
             }
-
-            var update = deployment.CheckForDetailedUpdate();
             return new ApplicationVersion
                        {
                            activation_url = deployment.ActivationUri,
trunk/product/MyMoney/MyMoney.csproj
@@ -564,10 +564,13 @@
     <Compile Include="Tasks\infrastructure\core\CommandFactory.cs" />
     <Compile Include="Tasks\infrastructure\updating\CancelUpdate.cs" />
     <Compile Include="Tasks\infrastructure\updating\CancelUpdateSpecs.cs" />
+    <Compile Include="Tasks\infrastructure\updating\CurrentDeployment.cs" />
     <Compile Include="Tasks\infrastructure\updating\DisplayNextAvailableVersion.cs" />
     <Compile Include="Tasks\infrastructure\core\ProcessQueryCommand.cs" />
     <Compile Include="Tasks\infrastructure\core\RunQueryCommand.cs" />
     <Compile Include="Tasks\infrastructure\updating\DownloadTheLatestVersion.cs" />
+    <Compile Include="Tasks\infrastructure\updating\IDeployment.cs" />
+    <Compile Include="Tasks\infrastructure\updating\NullDeployment.cs" />
     <Compile Include="Tasks\infrastructure\updating\WhatIsTheAvailableVersion.cs" />
     <Compile Include="Testing\MetaData\IntegrationAttribute.cs" />
     <Compile Include="Testing\spechelpers\contexts\concerns.cs" />
@@ -686,7 +689,6 @@
     <Compile Include="Utility\Extensions\TypeExtensions.cs" />
     <Compile Include="Utility\Extensions\TypeExtensionsSpecs.cs" />
     <Compile Include="Utility\Extensions\visitor_extensions.cs" />
-    <Compile Include="boot\check_for_updates.cs" />
     <Compile Include="boot\hookup.cs" />
     <Compile Include="Presentation\Model\Menu\ISubMenu.cs" />
     <Compile Include="Utility\Core\IRegistry.cs" />