main
 1using Gorilla.Commons.Infrastructure.Logging;
 2using gorilla.commons.utility;
 3using Gorilla.Commons.Utility;
 4using MoMoney.Presentation.Core;
 5using MoMoney.Presentation.Presenters;
 6using momoney.presentation.views;
 7using momoney.service.infrastructure.updating;
 8
 9namespace momoney.presentation.presenters
10{
11    public interface ICheckForUpdatesPresenter : IPresenter, Callback<Percent>
12    {
13        void begin_update();
14        void cancel_update();
15        void restart();
16        void do_not_update();
17    }
18
19    public class CheckForUpdatesPresenter : ICheckForUpdatesPresenter
20    {
21        readonly ICheckForUpdatesView view;
22        readonly ICommandPump pump;
23
24        public CheckForUpdatesPresenter(ICheckForUpdatesView view, ICommandPump pump)
25        {
26            this.pump = pump;
27            this.view = view;
28        }
29
30        public void run()
31        {
32            pump.run<ApplicationVersion, IWhatIsTheAvailableVersion>(view);
33            view.attach_to(this);
34            view.display();
35        }
36
37        public void begin_update()
38        {
39            pump.run<IDownloadTheLatestVersion, Callback<Percent>>(this);
40        }
41
42        public void cancel_update()
43        {
44            pump.run<ICancelUpdate>();
45            view.close();
46        }
47
48        public void restart()
49        {
50            pump.run<IRestartCommand>();
51        }
52
53        public void do_not_update()
54        {
55            view.close();
56        }
57
58        public void run(Percent completed)
59        {
60            if (completed.Equals(new Percent(100)))
61            {
62                this.log().debug("completed download");
63                view.update_complete();
64                restart();
65            }
66            else
67            {
68                this.log().debug("completed {0}", completed);
69                view.downloaded(completed);
70            }
71        }
72    }
73}