public async Task<IQueryable<InterruptionInfo>> GetInteruptionData() { var doc = new HtmlDocument(); var html = await LoadPage().ConfigureAwait(false); doc.LoadHtml(html); var details = doc.DocumentNode.SelectNodes("//table/tbody/tr"); var locationList = new List<InterruptionInfo>(); if (details != null && details.Count > 0) { foreach (var interuptionInfoItem in details) { var resultLine = interuptionInfoItem.Descendants().Where(n => n.Name.Equals("td")).ToList(); var locationString = resultLine[0].InnerHtml; var location = new InterruptionInfo() { Name = locationString.Substring(0, locationString.IndexOf("(") - 1), PostCode = locationString.Substring(locationString.IndexOf("(") + 1, 4), Details = resultLine[1].InnerHtml, }; locationList.Add(location); } } return locationList.AsQueryable(); }
public List<InterruptionInfo> FetchCurrentIntteruptions(string currentInterruptionsInfoFilePath) { var interruptionInfo = File.ReadAllText(currentInterruptionsInfoFilePath); var locationsJson = (JArray)JsonConvert.DeserializeObject(interruptionInfo); var list = new List<InterruptionInfo>(); foreach (var token in locationsJson) { var instance = new InterruptionInfo(); instance.Name = token.Value<string>("Name"); instance.PostCode = token.Value<string>("PostCode"); instance.Details = token.Value<string>("Details"); list.Add(instance); } return list; }