public ActionResult Create([Bind(Include = "ClientID,Name,Provider,IpAddress,IsUp")] Client client)
        {
            if (ModelState.IsValid)
            {
                db.Clients.Add(client);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(client));
        }
示例#2
0
        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
            }
        }