Ejemplo n.º 1
0
 private MachineHealth GetMachineHealthFromFile(MachineId macid)
 {
     using (var fileStream = new FileStream(GetMachineHealthFileName(macid), FileMode.Open))
     {
         var xs = new XmlSerializer(typeof(MachineHealth));
         return (MachineHealth)xs.Deserialize(fileStream);
     }
 }
Ejemplo n.º 2
0
 private String GetMachineDir(MachineId macid)
 {
     return Path.Combine(EnvConfiguration.ConfigurationRoot, macid.EnvName, "Machines", macid.MachineName);
 }
Ejemplo n.º 3
0
 private String GetMachineHealthFileName(MachineId macid)
 {
     return Path.Combine(GetMachineDir(macid), Machinexml);
 }
Ejemplo n.º 4
0
        public MachineHealth GetMachineHealth(MachineId macid)
        {
            var curcache = HttpContext.Current.Cache;
            String cacheid = macid.ToString();

            if (curcache[cacheid] == null)
            {
                var obj = GetMachineHealthFromFile(macid);

                if (obj.Health.TimeStamp.AddMinutes(5) < DateTime.Now) {
                    obj.Message = String.Format("At {0} : Machine's Last Time Stamp was at {1}", DateTime.Now, obj.Health.TimeStamp);
                    obj.Health.SetStatusDOWN();
                }
                else {

                    if (obj.Probes.Any(probe => !probe.Health.isUP()))
                    {
                        obj.Health.SetStatusDOWN();
                    }
                }

                using (var dep = new CacheDependency(GetMachineHealthFileName(macid)))
                {
                    curcache.Insert(cacheid, obj, dep, DateTime.UtcNow.AddMinutes(5.0), Cache.NoSlidingExpiration);
                }
            }

            return (MachineHealth) curcache[cacheid];
        }