Winify – Rev
?pathlinks?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Win32;
using Winify.Gotify;
namespace Winify
{
public class NotificationManager : IDisposable
{
#region Private Delegates, Events, Enums, Properties, Indexers and Fields
private readonly TaskScheduler _uiScheduler;
private List<NotificationForm> _notificationList;
private Rectangle _screenWorkingArea;
#endregion
#region Constructors, Destructors and Finalizers
public NotificationManager(TaskScheduler uiScheduler) : this()
{
_uiScheduler = uiScheduler;
}
private NotificationManager()
{
UpdateScreenResolution();
SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;
}
public void Dispose()
{
SystemEvents.DisplaySettingsChanged -= SystemEvents_DisplaySettingsChanged;
}
#endregion
#region Event Handlers
private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
{
UpdateScreenResolution();
}
private void NotificationForm_Closing(object sender, CancelEventArgs e)
{
var notificationForm = (NotificationForm) sender;
notificationForm.Closing += NotificationForm_Closing;
_notificationList[notificationForm.Index] = null;
}
#endregion
#region Public Methods
public void UpdateScreenResolution()
{
_notificationList = new List<NotificationForm>();
_screenWorkingArea = Screen.GetWorkingArea(new Point(0, 0));
using (var notificationForm = new NotificationForm())
{
var items = _screenWorkingArea.Bottom / notificationForm.Height;
foreach (var _ in Enumerable.Range(0, items))
{
_notificationList.Add(null);
}
}
}
public void ShowNotification(GotifyNotificationEventArgs e)
{
Task.Factory.StartNew(() =>
{
var i = _notificationList.FindIndex(item => item == null);
if (i == -1)
{
return;
}
var notificationForm =
new NotificationForm(i, e.Image, e.Notification.Title,
e.Notification.Message, 5000);
_notificationList[i] = notificationForm;
var notificationX = _screenWorkingArea.Right - notificationForm.Width;
var notificationY = _screenWorkingArea.Bottom - (i + 1) * notificationForm.Height;
notificationForm.UpdateLocation(notificationX, notificationY);
notificationForm.Closing += NotificationForm_Closing;
notificationForm.Show();
}, CancellationToken.None, TaskCreationOptions.None, _uiScheduler);
}
#endregion
}
}
Generated by GNU Enscript 1.6.5.90.