main
1using System;
2using System.Reflection;
3using System.Windows.Forms;
4using Gorilla.Commons.Utility;
5using momoney.presentation.presenters;
6using momoney.presentation.views;
7using MoMoney.Presentation.Views;
8using MoMoney.Presentation.Winforms.Resources;
9using momoney.service.infrastructure.updating;
10
11namespace MoMoney.Presentation.Winforms.Views
12{
13 public partial class CheckForUpdatesView : ApplicationWindow, ICheckForUpdatesView
14 {
15 readonly IShell shell;
16 ControlAction<EventArgs> update_button;
17 ControlAction<EventArgs> dont_update_button;
18 ControlAction<EventArgs> cancel_button;
19
20 public CheckForUpdatesView(IShell shell)
21 {
22 InitializeComponent();
23
24 this.shell = shell;
25 ux_image.Image = ApplicationImages.Splash;
26 ux_image.SizeMode = PictureBoxSizeMode.StretchImage;
27
28 titled("Check For Updates")
29 .create_tool_tip_for("Update", "Update the application, and then re-start it.", ux_update_button)
30 .create_tool_tip_for("Don't Update", "Discard the latest version.", ux_dont_update_button)
31 .create_tool_tip_for("Cancel", "Go back.", ux_cancel_button);
32
33 ux_update_button.Click += (o, e) => update_button(e);
34 ux_dont_update_button.Click += (o, e) => dont_update_button(e);
35 ux_cancel_button.Click += (o, e) => cancel_button(e);
36 }
37
38 public void attach_to(ICheckForUpdatesPresenter presenter)
39 {
40 update_button = x =>
41 {
42 ux_update_button.Enabled = false;
43 ux_dont_update_button.Enabled = false;
44 ux_cancel_button.Enabled = true;
45 presenter.begin_update();
46 };
47 dont_update_button = x => presenter.do_not_update();
48 cancel_button = x => presenter.cancel_update();
49 }
50
51 public void display()
52 {
53 ux_update_button.Enabled = false;
54 ux_dont_update_button.Enabled = false;
55 ux_cancel_button.Enabled = false;
56 Show(shell);
57 }
58
59 public void downloaded(Percent percentage_complete)
60 {
61 shell.region<ToolStripProgressBar>(
62 x =>
63 {
64 while (percentage_complete.is_less_than(x.Value))
65 {
66 if (percentage_complete.represents(x.Value)) break;
67 x.PerformStep();
68 }
69 });
70 }
71
72 public void update_complete()
73 {
74 downloaded(100);
75 }
76
77 public void close()
78 {
79 Close();
80 }
81
82 public void run(ApplicationVersion information)
83 {
84 if (information.updates_available)
85 {
86 ux_update_button.Enabled = true;
87 ux_dont_update_button.Enabled = true;
88 ux_cancel_button.Enabled = true;
89 ux_update_button.Enabled = information.updates_available;
90 ux_current_version.Text = "Current: " + information.current;
91 ux_new_version.Text = "New: " + information.available_version;
92 }
93 else
94 {
95 ux_update_button.Enabled = false;
96 ux_dont_update_button.Enabled = true;
97 ux_cancel_button.Enabled = false;
98 ux_current_version.Text = "Current: " + Assembly.GetExecutingAssembly().GetName().Version;
99 ux_new_version.Text = "New: " + Assembly.GetExecutingAssembly().GetName().Version;
100 }
101 }
102 }
103}