Winify – Blame information for rev 6
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | using System; |
2 | using System.ComponentModel; |
||
3 | using System.Configuration; |
||
4 | office | 4 | using System.Diagnostics; |
5 | using System.IO; |
||
6 | using System.Threading.Tasks; |
||
1 | office | 7 | using System.Windows.Forms; |
8 | using AutoUpdaterDotNET; |
||
4 | office | 9 | using Winify.Connections; |
1 | office | 10 | using Winify.Gotify; |
11 | using Winify.Properties; |
||
6 | office | 12 | using Winify.Serialization; |
1 | office | 13 | |
14 | namespace Winify |
||
15 | { |
||
16 | public partial class Form1 : Form |
||
17 | { |
||
18 | #region Private Delegates, Events, Enums, Properties, Indexers and Fields |
||
19 | |||
4 | office | 20 | private readonly GotifyConnectionManager _gotifyConnectionManager; |
21 | |||
1 | office | 22 | private AboutForm _aboutForm; |
23 | |||
6 | office | 24 | private Servers.Servers _servers; |
1 | office | 25 | |
26 | private SettingsForm _settingsForm; |
||
27 | |||
28 | #endregion |
||
29 | |||
30 | #region Constructors, Destructors and Finalizers |
||
31 | |||
32 | public Form1() |
||
33 | { |
||
34 | InitializeComponent(); |
||
35 | |||
36 | AutoUpdater.Start("http://winify.grimore.org/update/winify.xml"); |
||
37 | |||
38 | // Upgrade settings if required. |
||
39 | if (!ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).HasFile) |
||
40 | { |
||
41 | Settings.Default.Upgrade(); |
||
42 | } |
||
43 | |||
44 | // Bind to settings changed event. |
||
45 | Settings.Default.SettingsLoaded += Default_SettingsLoaded; |
||
46 | Settings.Default.SettingsSaving += Default_SettingsSaving; |
||
47 | Settings.Default.PropertyChanged += Default_PropertyChanged; |
||
48 | |||
4 | office | 49 | _gotifyConnectionManager = new GotifyConnectionManager(); |
1 | office | 50 | |
4 | office | 51 | Task.Run(async () => |
52 | { |
||
53 | _servers = await LoadServers(); |
||
54 | |||
55 | _gotifyConnectionManager.UpdateServers(_servers); |
||
56 | }); |
||
1 | office | 57 | } |
58 | |||
59 | /// <summary> |
||
60 | /// Clean up any resources being used. |
||
61 | /// </summary> |
||
62 | /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> |
||
63 | protected override void Dispose(bool disposing) |
||
64 | { |
||
65 | if (disposing && components != null) |
||
66 | { |
||
67 | components.Dispose(); |
||
68 | } |
||
69 | |||
70 | base.Dispose(disposing); |
||
71 | } |
||
72 | |||
73 | #endregion |
||
74 | |||
75 | #region Event Handlers |
||
76 | |||
77 | private static void Default_PropertyChanged(object sender, PropertyChangedEventArgs e) |
||
78 | { |
||
79 | Settings.Default.Save(); |
||
80 | } |
||
81 | |||
82 | private static void Default_SettingsSaving(object sender, CancelEventArgs e) |
||
83 | { |
||
84 | } |
||
85 | |||
86 | private static void Default_SettingsLoaded(object sender, SettingsLoadedEventArgs e) |
||
87 | { |
||
88 | } |
||
89 | |||
90 | private void SettingsToolStripMenuItem_Click(object sender, EventArgs e) |
||
91 | { |
||
92 | if (_settingsForm != null) |
||
93 | { |
||
94 | return; |
||
95 | } |
||
96 | |||
4 | office | 97 | _settingsForm = new SettingsForm(_servers); |
1 | office | 98 | _settingsForm.Closing += SettingsForm_Closing; |
4 | office | 99 | _settingsForm.ServersUpdated += SettingsForm_ServersUpdated; |
1 | office | 100 | _settingsForm.Show(); |
101 | } |
||
102 | |||
4 | office | 103 | private async void SettingsForm_ServersUpdated(object sender, ServersUpdatedEventArgs e) |
104 | { |
||
105 | _servers = e.Servers; |
||
106 | |||
107 | switch (await ServersSerialization.Serialize(e.Servers, Constants.ServersFile)) |
||
108 | { |
||
109 | case SerializationSuccess _: |
||
110 | _gotifyConnectionManager.UpdateServers(e.Servers); |
||
111 | break; |
||
112 | case SerializationFailure serializationFailure: |
||
113 | Debug.WriteLine(serializationFailure.Exception.Message); |
||
114 | break; |
||
115 | } |
||
116 | } |
||
117 | |||
1 | office | 118 | private void SettingsForm_Closing(object sender, CancelEventArgs e) |
119 | { |
||
5 | office | 120 | if (_settingsForm == null) |
1 | office | 121 | { |
122 | return; |
||
123 | } |
||
6 | office | 124 | |
1 | office | 125 | _settingsForm.Closing -= SettingsForm_Closing; |
5 | office | 126 | _settingsForm.ServersUpdated -= SettingsForm_ServersUpdated; |
1 | office | 127 | _settingsForm.Dispose(); |
128 | _settingsForm = null; |
||
129 | } |
||
130 | |||
131 | private void AboutToolStripMenuItem_Click(object sender, EventArgs e) |
||
132 | { |
||
133 | if (_aboutForm != null) |
||
134 | { |
||
135 | return; |
||
136 | } |
||
137 | |||
138 | _aboutForm = new AboutForm(); |
||
139 | _aboutForm.Closing += AboutForm_Closing; |
||
140 | _aboutForm.Show(); |
||
141 | } |
||
142 | |||
143 | private void AboutForm_Closing(object sender, CancelEventArgs e) |
||
144 | { |
||
145 | if (_aboutForm == null) |
||
146 | { |
||
147 | return; |
||
148 | } |
||
149 | |||
150 | _aboutForm.Closing -= AboutForm_Closing; |
||
151 | _aboutForm.Dispose(); |
||
152 | _aboutForm = null; |
||
153 | } |
||
154 | |||
155 | private void QuitToolStripMenuItem_Click(object sender, EventArgs e) |
||
156 | { |
||
157 | Application.Exit(); |
||
158 | } |
||
159 | |||
160 | #endregion |
||
4 | office | 161 | |
162 | #region Private Methods |
||
163 | |||
6 | office | 164 | private static async Task<Servers.Servers> LoadServers() |
4 | office | 165 | { |
166 | if (!Directory.Exists(Constants.UserApplicationDirectory)) |
||
167 | { |
||
168 | Directory.CreateDirectory(Constants.UserApplicationDirectory); |
||
169 | } |
||
170 | |||
171 | var deserializationResult = await ServersSerialization.Deserialize(Constants.ServersFile); |
||
172 | |||
173 | switch (deserializationResult) |
||
174 | { |
||
175 | case SerializationSuccess serializationSuccess: |
||
176 | return serializationSuccess.Servers; |
||
177 | |||
178 | default: |
||
6 | office | 179 | return new Servers.Servers(); |
4 | office | 180 | } |
181 | } |
||
182 | |||
183 | #endregion |
||
1 | office | 184 | } |
185 | } |