Fixing clients management.
2 // Copyright (C) 2014-2015 Stéphane Lenclud.
4 // This file is part of SharpDisplayManager.
6 // SharpDisplayManager is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
11 // SharpDisplayManager is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with SharpDisplayManager. If not, see <http://www.gnu.org/licenses/>.
21 using System.Collections.Generic;
24 using System.Threading.Tasks;
25 using System.Net.NetworkInformation;
26 using System.Runtime.InteropServices;
27 using System.Runtime.InteropServices.ComTypes;
28 using System.Diagnostics;
31 namespace SharpDisplayManager
33 public class NetworkManager: INetworkListManagerEvents, IDisposable
35 public delegate void OnConnectivityChangedDelegate(NetworkManager aNetworkManager, NLM_CONNECTIVITY aConnectivity);
36 public event OnConnectivityChangedDelegate OnConnectivityChanged;
38 private int iCookie = 0;
39 private IConnectionPoint iConnectionPoint;
40 private INetworkListManager iNetworkListManager;
43 public NetworkManager()
45 iNetworkListManager = new NetworkListManager();
46 ConnectToNetworkListManagerEvents();
51 //Not sure why this is not working form here
52 //Possibly because something is doing automatically before we get there
53 //DisconnectFromNetworkListManagerEvents();
57 public INetworkListManager NetworkListManager
59 get { return iNetworkListManager; }
62 public void ConnectivityChanged(NLM_CONNECTIVITY newConnectivity)
65 OnConnectivityChanged(this, newConnectivity);
68 public void ConnectToNetworkListManagerEvents()
70 Debug.WriteLine("Subscribing to INetworkListManagerEvents");
71 IConnectionPointContainer icpc = (IConnectionPointContainer)iNetworkListManager;
72 //similar event subscription can be used for INetworkEvents and INetworkConnectionEvents
73 Guid tempGuid = typeof(INetworkListManagerEvents).GUID;
74 icpc.FindConnectionPoint(ref tempGuid, out iConnectionPoint);
75 iConnectionPoint.Advise(this, out iCookie);
79 public void DisconnectFromNetworkListManagerEvents()
81 Debug.WriteLine("Un-subscribing to INetworkListManagerEvents");
82 iConnectionPoint.Unadvise(iCookie);