From 531236a0a702139f5badac716e3e33253f2d272f Mon Sep 17 00:00:00 2001 From: James Schafer Date: Sat, 10 Jun 2017 18:50:23 -0400 Subject: [PATCH] Implemented the CurrentTheaterScheduleWebRequestManager --- ...CurrentTheaterScheduleWebRequestManager.cs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Melody49Notifier/DataAbstraction/CurrentTheaterScheduleWebRequestManager.cs diff --git a/Melody49Notifier/DataAbstraction/CurrentTheaterScheduleWebRequestManager.cs b/Melody49Notifier/DataAbstraction/CurrentTheaterScheduleWebRequestManager.cs new file mode 100644 index 0000000..2a5ecb5 --- /dev/null +++ b/Melody49Notifier/DataAbstraction/CurrentTheaterScheduleWebRequestManager.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Melody49Notifier.Models; +using System.Net; +using System.IO; +using Microsoft.Azure.WebJobs.Host; + +namespace Melody49Notifier.DataAbstraction +{ + public class CurrentTheaterScheduleWebRequestManager : ICurrentTheaterScheduleWebRequestManager + { + private readonly TraceWriter log; + private readonly ITheaterScheduleHTMLParser theaterScheduleHTMLParser; + + public CurrentTheaterScheduleWebRequestManager(TraceWriter log, ITheaterScheduleHTMLParser theaterScheduleHTMLParser) + { + this.log = log; + this.theaterScheduleHTMLParser = theaterScheduleHTMLParser; + } + + public string TheaterUrl => "http://www.chakerestheatres.com/melody49di.php"; + + public TheaterSchedule GetCurrentTheaterSchedule() + { + string currentTheaterHTML = GetCurrentTheaterScheduleHTML(); + + log.Verbose($"Received Current Theater Schedule HTML. ({currentTheaterHTML.Length} Characters)"); + + return theaterScheduleHTMLParser.ParseTheaterScheduleHTML(currentTheaterHTML); + } + + private string GetCurrentTheaterScheduleHTML() + { + string currentTheaterHTML; + WebRequest webRequest = WebRequest.Create(TheaterUrl); + WebResponse webResponse = webRequest.GetResponse(); + + using (StreamReader streamReader = new StreamReader(webResponse.GetResponseStream())) + { + currentTheaterHTML = streamReader.ReadToEnd(); + } + + return currentTheaterHTML; + } + } +}