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); } }
private String GetMachineDir(MachineId macid) { return Path.Combine(EnvConfiguration.ConfigurationRoot, macid.EnvName, "Machines", macid.MachineName); }
private String GetMachineHealthFileName(MachineId macid) { return Path.Combine(GetMachineDir(macid), Machinexml); }
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]; }