/// <summary> /// ListenSCP /// </summary> private static void ListenSCP() { ListenerService _listenerService = new ListenerService(); _listenerService.StartService("SCP", userName: "******", password: "", address: "192.168.100.3", path: "pms", port: 22); _listenerService.ListenService(); }
/// <summary> /// ListenUDP /// </summary> private static void ListenUDP() { bool done = false; //Hardcoding Controllers ControllerService _controllerService = new ControllerService(); _controllerService.Controllers = new List <string> { "Controller-1", "Controller-2" }; //Listening UDP Server ListenerService _listenerService = new ListenerService(); _listenerService.StartService("UDP", port: 8888); StringBuilder sb = new StringBuilder(); long ticks = 10 * 1000; Stopwatch sw = new Stopwatch(); sw.Start(); while (!done) { string content = _listenerService.ListenService(); sb.Append(content); if (sw.ElapsedMilliseconds >= ticks) { foreach (string controller in _controllerService.Controllers) { if (!sb.ToString().Contains(controller)) { Console.WriteLine(controller + " Dead\n"); } } sb.Clear(); sw.Restart(); } Console.WriteLine(content); } sw.Stop(); _listenerService.StopService(); }
/// <summary> /// ListenUDP /// </summary> private void ListenUDP() { try { bool done = false; //Hardcoding Controllers ControllerService _controllerService = new ControllerService(); _controllerService.Controllers = controllerList; //Listening UDP Server ListenerService _listenerService = new ListenerService(); _listenerService.StartService("UDP", port: 8888); string sb = string.Empty; long ticks = 10 * 1000; Stopwatch sw = new Stopwatch(); sw.Start(); while (!done) { string content = _listenerService.ListenService(); if (content.Contains("Exception")) { for (int i = 0; i < controllerList.Count; i++) { Publish(i, Brushes.Red); } } else { if (content.LastIndexOf('-') == content.Length - 3) { string[] data = content.Split('-'); if (data.Length == 3) { //Level based statistics UpdateLevelStatistics(Convert.ToInt32(data[0]), Convert.ToInt32(data[1])); } else { //Zone based statistics UpdateZoneStatistics(Convert.ToInt32(data[0]), Convert.ToInt32(data[1]), Convert.ToInt32(data[2])); } } else { sb += content; if (sw.ElapsedMilliseconds >= ticks) { for (int i = 0; i < _controllerService.Controllers.Count; i++) { if (!sb.ToString().Contains(_controllerService.Controllers[i])) { Publish(i, Brushes.Red); } else { Publish(i, Brushes.LightGreen); } } sb = string.Empty; sw.Restart(); } } } } sw.Stop(); _listenerService.StopService(); } catch (Exception ex) { } }