private void CheckNetworkInterfaceStatuses(Dictionary <int, NetworkInterfaceHandler> interfaceHandlers) { lock (interfaceHandlers) { if (interfaceHandlers != _interfaceHandlers) { return; } HashSet <NetworkInterfaceHandler> handlers = new HashSet <NetworkInterfaceHandler>(_interfaceHandlers.Values); NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface networkInterface in networkInterfaces) { if (networkInterface.NetworkInterfaceType == NetworkInterfaceType.Loopback) { continue; } if (networkInterface.NetworkInterfaceType == NetworkInterfaceType.Tunnel) { continue; } if (!networkInterface.SupportsMulticast) { continue; } if (!networkInterface.Supports(NetworkInterfaceComponent.IPv4)) { continue; } int index = networkInterface.GetIPProperties().GetIPv4Properties().Index; NetworkInterfaceHandler interfaceHandler; _interfaceHandlers.TryGetValue(index, out interfaceHandler); if (interfaceHandler == null) { index = networkInterface.GetIPProperties().GetIPv4Properties().Index; interfaceHandler = new NetworkInterfaceHandler(this, networkInterface); _interfaceHandlers.Add(index, interfaceHandler); OnNetworkInterfaceAdded(networkInterface); interfaceHandler.StartBrowse(_serviceTypes.Select(st => new Name(st.ToLower() + ".local."))); } if (networkInterface.OperationalStatus == OperationalStatus.Up) { interfaceHandler.Enable(); } else { interfaceHandler.Disable(); } handlers.Remove(interfaceHandler); } foreach (NetworkInterfaceHandler handler in handlers) { _interfaceHandlers.Remove(handler.Index); handler.Disable(); OnNetworkInterfaceRemoved(handler.NetworkInterface); } } }
private void CheckNetworkInterfaceStatuses(Dictionary<int, NetworkInterfaceHandler> interfaceHandlers) { lock (interfaceHandlers) { if (interfaceHandlers != _interfaceHandlers) { return; } HashSet<NetworkInterfaceHandler> handlers = new HashSet<NetworkInterfaceHandler>(_interfaceHandlers.Values); NetworkInterfaceInformation[] interfaceInfos = NetworkInterfaceInformation.GetAllNetworkInterfaces(); foreach (NetworkInterfaceInformation interfaceInfo in interfaceInfos) { if (interfaceInfo.NetworkInterfaceType == NetworkInterfaceType.Loopback) { continue; } if (interfaceInfo.NetworkInterfaceType == NetworkInterfaceType.Tunnel) { continue; } int index = interfaceInfo.GetIPProperties().GetIPv4Properties().Index; NetworkInterfaceHandler interfaceHandler; _interfaceHandlers.TryGetValue(index, out interfaceHandler); if (interfaceHandler == null) { var networkInterface = new NetworkInterface(interfaceInfo); index = interfaceInfo.GetIPProperties().GetIPv4Properties().Index; interfaceHandler = new NetworkInterfaceHandler(this, networkInterface); _interfaceHandlers.Add(index, interfaceHandler); OnNetworkInterfaceAdded(networkInterface); interfaceHandler.StartBrowse(_serviceTypes.Select(st => new Name(st.ToLower() + ".local."))); } if (interfaceInfo.OperationalStatus == OperationalStatus.Up) { interfaceHandler.Enable(); } else { interfaceHandler.Disable(); } handlers.Remove(interfaceHandler); } foreach (NetworkInterfaceHandler handler in handlers) { _interfaceHandlers.Remove(handler.Index); handler.Disable(); OnNetworkInterfaceRemoved(handler.NetworkInterface); } } }
public ServiceHandler(NetworkInterfaceHandler networkInterfaceHandler, Name name) { Name = name; NetworkInterfaceHandler = networkInterfaceHandler; ServiceInfos = new List <ServiceInfo>(); }
public ServiceHandler(NetworkInterfaceHandler networkInterfaceHandler, Name name) { Name = name; NetworkInterfaceHandler = networkInterfaceHandler; ServiceInfos = new List<ServiceInfo>(); }