Winify

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 3  →  ?path2? @ 4
/trunk/Winify/Gotify/GotifyConnectionManager.cs
@@ -0,0 +1,63 @@
using System.Collections.Generic;
using Winify.Connections;
 
namespace Winify.Gotify
{
public class GotifyConnectionManager
{
#region Private Delegates, Events, Enums, Properties, Indexers and Fields
 
private readonly List<GotifyConnection> _gotifyConnections;
 
#endregion
 
#region Constructors, Destructors and Finalizers
 
public GotifyConnectionManager()
{
_gotifyConnections = new List<GotifyConnection>();
}
 
#endregion
 
#region Event Handlers
 
private static void Connection_GotifyNotification(object sender, GotifyNotificationEventArgs e)
{
var notification = new NotificationForm(e.Image, e.Notification.Title, e.Notification.Message, 5000);
notification.ShowDialog();
}
 
#endregion
 
#region Public Methods
 
public void UpdateServers(Servers servers)
{
// Update connections.
var removeConnections = new List<GotifyConnection>();
foreach (var gotifyConnection in _gotifyConnections)
{
gotifyConnection.GotifyNotification -= Connection_GotifyNotification;
gotifyConnection.Stop();
gotifyConnection.Dispose();
removeConnections.Add(gotifyConnection);
}
 
foreach (var connection in removeConnections)
{
_gotifyConnections.Remove(connection);
}
 
foreach (var server in servers.Server)
{
var connection = new GotifyConnection();
connection.Start(server.Username, server.Password, server.Host, server.Port);
connection.GotifyNotification += Connection_GotifyNotification;
_gotifyConnections.Add(connection);
}
}
 
#endregion
}
}