This repository has been archived by the owner on Jul 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented the CurrentTheaterScheduleWebRequestManager
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
Melody49Notifier/DataAbstraction/CurrentTheaterScheduleWebRequestManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |