public async Task Start() { BConsole.WriteLine("NetworkMonitor v1.0"); await Manager.Init(); new Thread(delegate() { int minutes = 10; int interval = 1000; int IntervalMax = minutes * 1000 * 60; int timer = IntervalMax; while (!StopCalled) { if (timer % interval != 0 || timer > IntervalMax) { break; } if (timer < IntervalMax) { Thread.Sleep(interval); timer += interval; } else { timer = 0; var devices = NetworkScanner.GetDevices(Config.GetDisplay()); Manager.AddDevices(devices); } } }).Start(); await Listener.Start(); }
/// <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); }
/// <summary> /// Function that stops the listner from listining on the port /// </summary> public void Stop() { CalledStop = true; Server.Close(); BConsole.WriteLine("Telling service to stop..."); }