Winify – Blame information for rev 8
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | using System; |
7 | office | 2 | using System.Collections.Specialized; |
1 | office | 3 | using System.ComponentModel; |
4 | using System.Configuration; |
||
4 | office | 5 | using System.Diagnostics; |
6 | using System.IO; |
||
7 | using System.Threading.Tasks; |
||
1 | office | 8 | using System.Windows.Forms; |
9 | using AutoUpdaterDotNET; |
||
10 | using Winify.Gotify; |
||
11 | using Winify.Properties; |
||
8 | office | 12 | using Winify.Servers.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 | |||
8 | office | 20 | private readonly global::Servers.Servers _servers; |
4 | office | 21 | |
1 | office | 22 | private AboutForm _aboutForm; |
23 | |||
7 | office | 24 | private GotifyConnectionManager _gotifyConnectionManager; |
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 | |||
8 | office | 49 | _servers = new global::Servers.Servers(); |
7 | office | 50 | _servers.Server.CollectionChanged += Server_CollectionChanged; |
1 | office | 51 | |
7 | office | 52 | _gotifyConnectionManager = new GotifyConnectionManager(_servers); |
53 | |||
4 | office | 54 | Task.Run(async () => |
55 | { |
||
7 | office | 56 | var restoredServers = await LoadServers(); |
4 | office | 57 | |
7 | office | 58 | foreach (var server in restoredServers.Server) |
59 | { |
||
60 | _servers.Server.Add(server); |
||
61 | } |
||
4 | office | 62 | }); |
1 | office | 63 | } |
64 | |||
65 | /// <summary> |
||
66 | /// Clean up any resources being used. |
||
67 | /// </summary> |
||
68 | /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> |
||
69 | protected override void Dispose(bool disposing) |
||
70 | { |
||
71 | if (disposing && components != null) |
||
72 | { |
||
7 | office | 73 | _servers.Server.CollectionChanged -= Server_CollectionChanged; |
74 | |||
75 | Settings.Default.SettingsLoaded -= Default_SettingsLoaded; |
||
76 | Settings.Default.SettingsSaving -= Default_SettingsSaving; |
||
77 | Settings.Default.PropertyChanged -= Default_PropertyChanged; |
||
78 | |||
79 | _gotifyConnectionManager?.Dispose(); |
||
80 | _gotifyConnectionManager = null; |
||
81 | |||
1 | office | 82 | components.Dispose(); |
83 | } |
||
84 | |||
85 | base.Dispose(disposing); |
||
86 | } |
||
87 | |||
88 | #endregion |
||
89 | |||
90 | #region Event Handlers |
||
91 | |||
7 | office | 92 | private async void Server_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) |
93 | { |
||
94 | switch (await ServersSerialization.Serialize(_servers, Constants.ServersFile)) |
||
95 | { |
||
8 | office | 96 | case ServersSerializationFailure serializationFailure: |
7 | office | 97 | Debug.WriteLine(serializationFailure.Exception.Message); |
98 | break; |
||
99 | } |
||
100 | } |
||
101 | |||
1 | office | 102 | private static void Default_PropertyChanged(object sender, PropertyChangedEventArgs e) |
103 | { |
||
104 | Settings.Default.Save(); |
||
105 | } |
||
106 | |||
107 | private static void Default_SettingsSaving(object sender, CancelEventArgs e) |
||
108 | { |
||
109 | } |
||
110 | |||
111 | private static void Default_SettingsLoaded(object sender, SettingsLoadedEventArgs e) |
||
112 | { |
||
113 | } |
||
114 | |||
115 | private void SettingsToolStripMenuItem_Click(object sender, EventArgs e) |
||
116 | { |
||
117 | if (_settingsForm != null) |
||
118 | { |
||
119 | return; |
||
120 | } |
||
121 | |||
4 | office | 122 | _settingsForm = new SettingsForm(_servers); |
1 | office | 123 | _settingsForm.Closing += SettingsForm_Closing; |
124 | _settingsForm.Show(); |
||
125 | } |
||
126 | |||
127 | private void SettingsForm_Closing(object sender, CancelEventArgs e) |
||
128 | { |
||
5 | office | 129 | if (_settingsForm == null) |
1 | office | 130 | { |
131 | return; |
||
132 | } |
||
6 | office | 133 | |
1 | office | 134 | _settingsForm.Closing -= SettingsForm_Closing; |
135 | _settingsForm.Dispose(); |
||
136 | _settingsForm = null; |
||
137 | } |
||
138 | |||
139 | private void AboutToolStripMenuItem_Click(object sender, EventArgs e) |
||
140 | { |
||
141 | if (_aboutForm != null) |
||
142 | { |
||
143 | return; |
||
144 | } |
||
145 | |||
146 | _aboutForm = new AboutForm(); |
||
147 | _aboutForm.Closing += AboutForm_Closing; |
||
148 | _aboutForm.Show(); |
||
149 | } |
||
150 | |||
151 | private void AboutForm_Closing(object sender, CancelEventArgs e) |
||
152 | { |
||
153 | if (_aboutForm == null) |
||
154 | { |
||
155 | return; |
||
156 | } |
||
157 | |||
158 | _aboutForm.Closing -= AboutForm_Closing; |
||
159 | _aboutForm.Dispose(); |
||
160 | _aboutForm = null; |
||
161 | } |
||
162 | |||
163 | private void QuitToolStripMenuItem_Click(object sender, EventArgs e) |
||
164 | { |
||
165 | Application.Exit(); |
||
166 | } |
||
167 | |||
168 | #endregion |
||
4 | office | 169 | |
170 | #region Private Methods |
||
171 | |||
8 | office | 172 | private static async Task<global::Servers.Servers> LoadServers() |
4 | office | 173 | { |
174 | if (!Directory.Exists(Constants.UserApplicationDirectory)) |
||
175 | { |
||
176 | Directory.CreateDirectory(Constants.UserApplicationDirectory); |
||
177 | } |
||
178 | |||
179 | var deserializationResult = await ServersSerialization.Deserialize(Constants.ServersFile); |
||
180 | |||
181 | switch (deserializationResult) |
||
182 | { |
||
8 | office | 183 | case ServersSerializationSuccess serializationSuccess: |
4 | office | 184 | return serializationSuccess.Servers; |
185 | |||
186 | default: |
||
8 | office | 187 | return new global::Servers.Servers(); |
4 | office | 188 | } |
189 | } |
||
190 | |||
191 | #endregion |
||
1 | office | 192 | } |
193 | } |