private void L_ConnectionChanged(string connectionState, DataReceivedObject rObject) { string[] split = connectionState.Split(' '); string mac = split[0]; switch (split.Last()) { case "connected": Manager.UpdateDeviceStatus(mac, true, Config.GetDisplay(), rObject.IPAddress); break; case "disconnected": Manager.UpdateDeviceStatus(mac, false, Config.GetDisplay(), rObject.IPAddress); break; default: throw new Exception("Did not understand connection state."); } //Manager.PrintAllDevices(); }
/// <summary> /// Listens to the specified ip address for incoming UDP messages, and pushes those to a buffer /// Also Raises the SSHConsoleSyslog.SyslogListener.DataReceived Event /// </summary> /// <returns>Task completion information</returns> public Task Start() { byte[] bytes = new byte[256]; CalledStop = false; try { BConsole.WriteLine($"Syslog Listener started..."); while (!CalledStop) { byte[] bits = Server.Receive(ref UdpEndpoint); string response = Encoding.ASCII.GetString(bits, 0, bits.Length); DataReceivedObject receiv = new DataReceivedObject { Data = response.Replace("\n", ""), IPAddress = UdpEndpoint.Address.ToString(), ReceivedDateTime = DateTime.Now }; var validRule = SyslogFilters.CheckConnectionState(receiv.Data); //this item is a connection log if (validRule.Item1) { ConnectionChanged?.Invoke(validRule.Item2, receiv); } LastReceiveTime = DateTime.Now; } } catch (SocketException e) { BConsole.WriteLine($"Exception: {e.Message}"); } catch (Exception e) { BConsole.WriteLine($"Exception: {e.Message}"); } BConsole.WriteLine("Service stopped!"); return(Task.CompletedTask); }