Beispiel #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");
        }
        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);
        }