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