/trunk/Winify/Form1.cs |
@@ -4,6 +4,7 @@ |
using System.Configuration; |
using System.Diagnostics; |
using System.IO; |
using System.Linq; |
using System.Text; |
using System.Threading; |
using System.Threading.Tasks; |
@@ -11,6 +12,7 @@ |
using AutoUpdaterDotNET; |
using Serilog; |
using Servers; |
using ToastNotifications; |
using Winify.Gotify; |
using Winify.Properties; |
using Winify.Servers.Serialization; |
@@ -26,14 +28,12 @@ |
|
private readonly global::Servers.Servers _servers; |
|
private readonly TaskScheduler _taskScheduler; |
private readonly TaskScheduler _uiTaskScheduler; |
|
private AboutForm _aboutForm; |
|
private GotifyConnectionManager _gotifyConnectionManager; |
|
private NotificationManager _notificationManager; |
|
private SettingsForm _settingsForm; |
|
#endregion |
@@ -75,14 +75,12 @@ |
_servers = new global::Servers.Servers(); |
_servers.Server.CollectionChanged += Server_CollectionChanged; |
_servers.Server.ListChanged += Server_ListChanged; |
_announcements = new global::Announcements.Announcements(); |
_announcements = new Announcements.Announcements(); |
_announcements.Announcement.CollectionChanged += Announcements_CollectionChanged; |
_announcements.Announcement.ListChanged += Announcement_ListChanged; |
|
_taskScheduler = TaskScheduler.FromCurrentSynchronizationContext(); |
_uiTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext(); |
|
_notificationManager = new NotificationManager(_taskScheduler); |
|
_gotifyConnectionManager = new GotifyConnectionManager(_servers); |
_gotifyConnectionManager.GotifyNotification += GotifyConnectionManager_GotifyNotification; |
|
@@ -129,9 +127,6 @@ |
_gotifyConnectionManager?.Dispose(); |
_gotifyConnectionManager = null; |
|
_notificationManager?.Dispose(); |
_notificationManager = null; |
|
components.Dispose(); |
} |
|
@@ -159,9 +154,30 @@ |
|
private void GotifyConnectionManager_GotifyNotification(object sender, GotifyNotificationEventArgs e) |
{ |
_notificationManager.ShowNotification(e, _announcements); |
Task.Factory.StartNew(() => |
{ |
foreach (var announcement in _announcements.Announcement) |
{ |
if (announcement.AppId == e.Notification.AppId) |
{ |
var configuredNotification = new Notification($"{e.Notification.Title} ({e.Notification.Server.Name}/{e.Notification.AppId})", |
e.Notification.Message, announcement.LingerTime, e.Image, FormAnimator.AnimationMethod.Slide, |
FormAnimator.AnimationDirection.Up); |
|
configuredNotification.Show(); |
|
return; |
} |
} |
|
var notification = new Notification($"{e.Notification.Title} ({e.Notification.Server.Name}/{e.Notification.AppId})", |
e.Notification.Message, 5000, e.Image, FormAnimator.AnimationMethod.Slide, |
FormAnimator.AnimationDirection.Up); |
|
notification.Show(); |
}, CancellationToken.None, TaskCreationOptions.None, _uiTaskScheduler); |
} |
|
private async void Server_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) |
{ |
await SaveServers(); |