Winify – Diff between revs 6 and 7

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 6 Rev 7
Line -... Line 1...
-   1 using System;
1 using System.Collections.Generic; 2 using System.Collections.Concurrent;
-   3 using System.Collections.Specialized;
-   4 using System.Linq;
-   5 using Servers;
Line 2... Line 6...
2   6  
3 namespace Winify.Gotify 7 namespace Winify.Gotify
4 { 8 {
5 public class GotifyConnectionManager 9 public class GotifyConnectionManager : IDisposable
6 { 10 {
Line 7... Line 11...
7 #region Private Delegates, Events, Enums, Properties, Indexers and Fields 11 #region Private Delegates, Events, Enums, Properties, Indexers and Fields
-   12  
-   13 private readonly ConcurrentDictionary<string, GotifyConnection> _gotifyConnections;
Line 8... Line 14...
8   14  
Line 9... Line 15...
9 private readonly List<GotifyConnection> _gotifyConnections; 15 private readonly Servers.Servers _servers;
Line 10... Line 16...
10   16  
11 #endregion 17 #endregion
12   18  
13 #region Constructors, Destructors and Finalizers 19 #region Constructors, Destructors and Finalizers
Line -... Line 20...
-   20  
14   21 private GotifyConnectionManager()
-   22 {
Line 15... Line 23...
15 public GotifyConnectionManager() 23 _gotifyConnections = new ConcurrentDictionary<string, GotifyConnection>();
-   24 }
Line 16... Line 25...
16 { 25  
17 _gotifyConnections = new List<GotifyConnection>(); 26 public GotifyConnectionManager(Servers.Servers servers) : this()
18 } 27 {
19   -  
20 #endregion 28 _servers = servers;
Line 21... Line 29...
21   29  
Line 22... Line 30...
22 #region Event Handlers 30 _servers.Server.CollectionChanged += Server_CollectionChanged;
Line 23... Line 31...
23   31 }
24 private static void Connection_GotifyNotification(object sender, GotifyNotificationEventArgs e) 32  
25 { 33 public void Dispose()
26 var notification = new NotificationForm(e.Image, e.Notification.Title, e.Notification.Message, 5000); -  
27 notification.ShowDialog(); -  
28 } 34 {
29   35 _servers.Server.CollectionChanged -= Server_CollectionChanged;
30 #endregion 36 }
31   37  
-   38 #endregion
-   39  
-   40 #region Event Handlers
32 #region Public Methods 41  
-   42 private void Server_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
33   43 {
Line 34... Line 44...
34 public void UpdateServers(Servers.Servers servers) 44 if (e.NewItems != null)
35 { 45 {
-   46 foreach (var server in e.NewItems.OfType<Server>())
-   47 {
-   48 var connection = new GotifyConnection();
-   49 connection.GotifyNotification += Connection_GotifyNotification;
-   50  
-   51 connection.Start(server.Username, server.Password, server.Host, server.Port);
-   52 _gotifyConnections.TryAdd(server.Name, connection);
-   53 }
-   54 }
-   55  
36 // Update connections. 56 if (e.OldItems != null)
-   57 {
37 var removeConnections = new List<GotifyConnection>(); 58 foreach (var server in e.OldItems.OfType<Server>())
-   59 {
Line 38... Line 60...
38 foreach (var gotifyConnection in _gotifyConnections) 60 if (!_gotifyConnections.TryRemove(server.Name, out var gotifyConnection))
39 { 61 {
40 gotifyConnection.GotifyNotification -= Connection_GotifyNotification; -  
41 gotifyConnection.Stop(); -  
42 gotifyConnection.Dispose(); 62 continue;
43 removeConnections.Add(gotifyConnection); 63 }
44 } -  
45   64  
Line 46... Line 65...
46 foreach (var connection in removeConnections) 65 gotifyConnection.GotifyNotification -= Connection_GotifyNotification;
47 { 66  
48 _gotifyConnections.Remove(connection); 67 gotifyConnection.Stop();
49 } 68 gotifyConnection.Dispose();