Winify – Blame information for rev 11

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