private void UpdatePingStatus(object state) { using (PingBotEntities context = new PingBotEntities()) { NetTools nt = new NetTools(); foreach (var client in context.Clients) { // Run Ping bool result = nt.IsUp(client.IpAddress); // if something changed if (result != client.IsUp) { if (result == false) { string subject = string.Format("PingBot says {0} is down", client.Name); string body = string.Format("PingBot says {0} {1} {2} is now down", client.Name, client.Provider, client.IpAddress); nt.SendMail(subject, body); } else { string subject = string.Format("PingBot says {0} is up", client.Name); string body = string.Format("PingBot says {0} {1} {2} is now up", client.Name, client.Provider, client.IpAddress); nt.SendMail(subject, body); } client.IsUp = result; Clients.All.updatePingStatus(client); // brodcast changes to ui } } context.SaveChanges(); // save changes to database } }
public IEnumerable <Client> GetAllClients() { using (PingBotEntities context = new PingBotEntities()) { return(context.Clients.ToList()); } }