Winify – Blame information for rev 7

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