public ServiceStatus CheckTCPService(TCPService Service) { var serviceStatus = new ServiceStatus() { Name = Service.Name, Type = Service.Type, }; try { var client = new TcpClient(Service.Host, Convert.ToInt32(Service.Port)); serviceStatus.Status = client.Connected ? "ON" : "OFF"; } catch (Exception) { serviceStatus.Status = "OFF"; } return serviceStatus; }
public List<ServiceStatus> CheckHTTPServices(List<HTTPService> httpServices) { var servicesStatus = new List<ServiceStatus>(); foreach (var httpService in httpServices) { string status = null; string serviceError = null; try { var serviceResult = HTTPRequest.RequestString(httpService.Url, "GET", null); if (serviceResult.Contains("\"error\"")) { status = "OFF"; serviceError = serviceResult; } else { status = "ON"; } } catch (Exception e) { status = "OFF"; serviceError = e.Message; } var serviceStatus = new ServiceStatus() { Name = httpService.Name, Type = httpService.Type, Status = status, Error = serviceError }; servicesStatus.Add(serviceStatus); } return servicesStatus; }