示例#1
0
        public ActionResult LoadAllInterruptionInfo()
        {
            var fetcher = new PowerInterruptionFetcher();
            var postCodeFilePath = HttpContext.Server.MapPath("~/App_Data/" + AppConstants.PostCodeFile);
            var interruptionFilePath = HttpContext.Server.MapPath("~/App_Data/" + AppConstants.InterruptionInfoFile);
            var currentInterruptionsInfoFilePath = HttpContext.Server.MapPath("~/App_Data/" + AppConstants.CurrentInterruptionInfoFile);

            var lastUpdateTime = fetcher.FetchLastUpdatedTimeStamp(interruptionFilePath);

            if (lastUpdateTime.AddMinutes(10) > DateTime.Now)
            {
                logger.Info("Interruption update not triggered because it's been triggered during last 10 minutes");
                ViewBag.Message = "Interruption update not triggered because it's been triggered during last 10 minutes";
                return View("Index");
            }

            ThreadPool.QueueUserWorkItem(s =>
            {
                var interruptionDataAsJson = fetcher.FetchInterruptions(postCodeFilePath).Result;
                fetcher.UpdateInterruptionInfo(interruptionDataAsJson, interruptionFilePath,currentInterruptionsInfoFilePath);
                logger.Info("COMPLETED: Interruption information finished loading from Western Power");
            });
            logger.Info("START: Interruption information started loading from Western Power");
            ViewBag.Message = "Interruption update triggered";
            return View("Index");
        }
示例#2
0
        public string Demo()
        {
            var pf = new PowerInterruptionFetcher();
            var interruptionFilePath = HttpContext.Server.MapPath("~/App_Data/" + AppConstants.InterruptionInfoFile);
            var currentInterruptionsInfoFilePath = HttpContext.Server.MapPath("~/App_Data/" + AppConstants.CurrentInterruptionInfoFile);

            var currInterruptions = pf.FetchCurrentIntteruptions(interruptionFilePath);
            if (currInterruptions.Count > 1) return "No need to demo";

            pf.CreateCurrentInterruptionsForDemo(currentInterruptionsInfoFilePath,interruptionFilePath);

            return "Demo mode initiated";
        }
 private IEnumerable<InterruptionInfo> GetInterruptions(string location)
 {
     var pf = new PowerInterruptionFetcher();
     var result = pf.GetInterruptionFromWp(location).Result;
     logger.Info("COMPLETED: Interruption information finished loading from Western Power");
     return result;
 }
 public DateTime LastUpdatedTimeStamp()
 {
     var f = new PowerInterruptionFetcher();
     return f.FetchLastUpdatedTimeStamp(HttpContext.Current.Server.MapPath(CurrentInterruptionInfoFile));
 }
        private void UpdateInterruptionsWithLatest(IEnumerable<InterruptionInfo> newList, string interruptionFilePath, string currInterruptionFilePath)
        {
            var interruptionContent = File.ReadAllText(interruptionFilePath);
            var list = JsonConvert.DeserializeObject<List<InterruptionInfo>>(interruptionContent);

            foreach (var item in newList)
            {
                var existing = list.Find(i => i.Name.Equals(item.Name));
                existing.Details = item.Details;
            }

            var interruptionDataAsJson = JsonConvert.SerializeObject(list);
            JArray interruptionList = JArray.Parse(interruptionDataAsJson);
            var fetcher = new PowerInterruptionFetcher();

            fetcher.UpdateInterruptionInfo(interruptionList, interruptionFilePath, currInterruptionFilePath);
        }
 private bool IsDataStale()
 {
     var pf = new PowerInterruptionFetcher();
     var lastUpdateTime = pf.FetchLastUpdatedTimeStamp(HttpContext.Current.Server.MapPath(CurrentInterruptionInfoFile));
     int updateWindow = 10;
     int.TryParse(ConfigurationManager.AppSettings["InterruptionUpdateWindowInMinutes"], out updateWindow);
     return (lastUpdateTime.AddMinutes(updateWindow) < DateTime.Now);
 }