Winify

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 66  →  ?path2? @ 67
/trunk/Winify/MainForm.cs
@@ -21,7 +21,6 @@
using Winify.Utilities;
using Winify.Utilities.Serialization;
using ScheduledContinuation = Toasts.ScheduledContinuation;
using Toasts = Toasts.Toasts;
 
namespace Winify
{
@@ -55,7 +54,7 @@
 
private readonly LogMemorySink _memorySink;
 
private readonly global::Toasts.Toasts _toasts;
private readonly Toasts.Toasts _toasts;
 
#endregion
 
@@ -63,18 +62,18 @@
 
public MainForm()
{
InitializeComponent();
 
_cancellationTokenSource = new CancellationTokenSource();
_cancellationToken = _cancellationTokenSource.Token;
 
ChangedConfigurationContinuation = new ScheduledContinuation();
 
_toasts = new global::Toasts.Toasts(_cancellationToken);
_toasts = new Toasts.Toasts(_cancellationToken);
}
 
public MainForm(Mutex mutex) : this()
{
InitializeComponent();
 
_memorySink = new LogMemorySink();
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
@@ -121,7 +120,7 @@
foreach (var server in servers.Server)
{
var gotifyConnection = new GotifyConnection(server, Configuration);
gotifyConnection.GotifyNotification += GotifyConnection_GotifyNotification;
gotifyConnection.GotifyMessage += GotifyConnectionGotifyMessage;
gotifyConnection.Start();
_gotifyConnections.Add(gotifyConnection);
}
@@ -129,7 +128,10 @@
 
private void LogViewToolStripMenuItem_Click(object sender, EventArgs e)
{
if (_logViewForm != null) return;
if (_logViewForm != null)
{
return;
}
 
_logViewForm = new LogViewForm(this, _memorySink, _cancellationToken);
_logViewForm.Closing += LogViewForm_Closing;
@@ -138,7 +140,10 @@
 
private void LogViewForm_Closing(object sender, CancelEventArgs e)
{
if (_logViewForm == null) return;
if (_logViewForm == null)
{
return;
}
 
_logViewForm.Closing -= LogViewForm_Closing;
_logViewForm.Close();
@@ -172,42 +177,45 @@
// Update connections to gotify servers.
while (_gotifyConnections.TryTake(out var gotifyConnection))
{
gotifyConnection.GotifyNotification -= GotifyConnection_GotifyNotification;
gotifyConnection.Stop();
gotifyConnection.GotifyMessage -= GotifyConnectionGotifyMessage;
await gotifyConnection.Stop();
gotifyConnection.Dispose();
gotifyConnection = null;
}
 
foreach (var server in e.Servers.Server)
{
var gotifyConnection = new GotifyConnection(server, Configuration);
gotifyConnection.GotifyNotification += GotifyConnection_GotifyNotification;
gotifyConnection.GotifyMessage += GotifyConnectionGotifyMessage;
gotifyConnection.Start();
_gotifyConnections.Add(gotifyConnection);
}
}
 
private async void GotifyConnection_GotifyNotification(object sender, GotifyNotificationEventArgs e)
private async void GotifyConnectionGotifyMessage(object sender, GotifyMessageEventArgs e)
{
var announcements = await LoadAnnouncements();
 
foreach (var announcement in announcements.Announcement)
if (announcement.AppId == e.Notification.AppId)
{
if (announcement.AppId != e.Message.AppId)
{
var configuredNotification = new ToastForm(
$"{e.Notification.Title} ({e.Notification.Server.Name}/{e.Notification.AppId})",
e.Notification.Message, announcement.LingerTime, e.Image);
await _toasts.Queue(configuredNotification);
 
return;
continue;
}
 
var configuredNotification = new ToastForm(
$"{e.Message.Title} ({e.Message.Server.Name}/{e.Message.AppId})",
e.Message.Message, announcement.LingerTime, e.Image);
 
await _toasts.Queue(configuredNotification);
 
return;
}
 
if (Configuration.InfiniteToastDuration)
{
var infiniteToastForm = new ToastForm(
$"{e.Notification.Title} ({e.Notification.Server.Name}/{e.Notification.AppId})",
e.Notification.Message, e.Image);
$"{e.Message.Title} ({e.Message.Server.Name}/{e.Message.AppId})",
e.Message.Message, e.Image);
 
await _toasts.Queue(infiniteToastForm);
 
@@ -215,15 +223,18 @@
}
 
var toastForm = new ToastForm(
$"{e.Notification.Title} ({e.Notification.Server.Name}/{e.Notification.AppId})",
e.Notification.Message, Configuration.ToastDuration, e.Image);
$"{e.Message.Title} ({e.Message.Server.Name}/{e.Message.AppId})",
e.Message.Message, Configuration.ToastDuration, e.Image);
 
await _toasts.Queue(toastForm);
}
 
private void SettingsForm_Closing(object sender, CancelEventArgs e)
{
if (_settingsForm == null) return;
if (_settingsForm == null)
{
return;
}
 
_settingsForm.Save -= SettingsForm_Save;
_settingsForm.Closing -= SettingsForm_Closing;
@@ -233,7 +244,10 @@
 
private void AboutToolStripMenuItem_Click(object sender, EventArgs e)
{
if (_aboutForm != null) return;
if (_aboutForm != null)
{
return;
}
 
_aboutForm = new AboutForm();
_aboutForm.Closing += AboutForm_Closing;
@@ -242,7 +256,10 @@
 
private void AboutForm_Closing(object sender, CancelEventArgs e)
{
if (_aboutForm == null) return;
if (_aboutForm == null)
{
return;
}
 
_aboutForm.Closing -= AboutForm_Closing;
_aboutForm.Dispose();