예제 #1
0
 public void ReCreateDB()
 {
     using (var ctx = new Context())
     {
         ctx.Database.CreateIfNotExists();
     }
 }
예제 #2
0
파일: Program.cs 프로젝트: Anuchap/IS
        private static void Run()
        {
            Log("Scaning...");

            List<Site> sites;

            using (var db = new Context())
            {
                sites = db.Sites.ToList();
            }

            var now = DateTime.Now;

            foreach (var site in sites)
            {
                var site1 = site;
                switch (site1.Type)
                {
                    case Type.Ping:
                        new Thread(() =>
                        {
                            using (var db = new Context())
                            {
                                var s = db.Sites.Include(p => p.PatternTimes).Include(d => d.Downtimes).Single(x => x.Id == site1.Id);

                                var office = s.PatternTimes.Any( x => x.Days.Contains(now.DayOfWeek.ToString()) && x.TimeOpen <= now.Hour && now.Hour < x.TimeClose) ? Office.Open : Office.Closed;

                                var tr = new Transaction { Office = office, ResponseTime = DateTime.Now, Type = Type.Ping };

                                try
                                {
                                    var reply = new Ping().Send(IPAddress.Parse(site1.Ip), 10 * 1000); // 1 minute time out (in ms)

                                    tr.Status = (reply != null && reply.Status == IPStatus.Success) ? Status.Up : Status.Dn;
                                }
                                catch (Exception)
                                {
                                    tr.Status = Status.Dn;
                                }

                                UpdateStatus(s, tr);
                                db.SaveChanges();
                            }
                        }).Start();
                        break;

                    case Type.Snmp:
                        new Thread(() =>
                        {
                            using (var db = new Context())
                            {
                                var s = db.Sites.Include(p => p.PatternTimes).Include(d => d.Downtimes).Single(x => x.Id == site1.Id);

                                var office = s.PatternTimes.Any( x => x.Days.Contains(now.DayOfWeek.ToString()) && x.TimeOpen <= now.Hour && now.Hour < x.TimeClose) ? Office.Open : Office.Closed;

                                var tr = new Transaction { Office = office, ResponseTime = DateTime.Now, Type = Type.Snmp };

                                try
                                {
                                    Messenger.Get(VersionCode.V1, new IPEndPoint(IPAddress.Parse(site1.Ip), 161), new OctetString(site1.Community), new List<Variable> { new Variable(new ObjectIdentifier("1.3.6.1.2.1.1.1.0")) }, 10 * 1000); // 1 minute time out (in ms)

                                    tr.Status = Status.Up;
                                }
                                catch (Exception)
                                {
                                    tr.Status = Status.Dn;
                                }

                                UpdateStatus(s, tr);
                                db.SaveChanges();
                            }
                        }).Start();
                        break;
                }
            }
        }
예제 #3
0
파일: UnitOfWork.cs 프로젝트: Anuchap/IS
 public UnitOfWork(Context context)
 {
     _context = context;
 }