示例#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");
        }
 public DateTime LastUpdatedTimeStamp()
 {
     var f = new PowerInterruptionFetcher();
     return f.FetchLastUpdatedTimeStamp(HttpContext.Current.Server.MapPath(CurrentInterruptionInfoFile));
 }
 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);
 }