/
TankstellenUsecaseController.cs
47 lines (43 loc) · 1.65 KB
/
TankstellenUsecaseController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Linq.Expressions;
using System.Linq;
namespace TSPTest
{
public class TankstellenUsecaseController
{
private readonly Downloader downloader;
private readonly HTMLParser htmlParser;
private TankstellenEntry oldEntry;
private readonly EntryAuditor entryAuditor;
private const string Url =
@"http://auto.freenet.de/freenet/servlet/external?url=http%3A%2F%2Fnn3.freenet.de%2Fclevertanken%2Fmain.php%3Fcm%3D1%26sprit%3DSuper%26ort%3D";
private string downloadUrl;
public TankstellenUsecaseController(Downloader downloader, HTMLParser htmlParser, string ort, EntryAuditor entryAuditor)
{
this.downloader = downloader;
this.htmlParser = htmlParser;
downloadUrl = Url + ort;
this.entryAuditor = entryAuditor;
}
public void NotificateIfNew(Action<string> notification)
{
TankstellenEntry entry = htmlParser.parse(downloader.download(downloadUrl)).First(x => x.IsPmOrStar());
if (entry.IsNewerThan(oldEntry))
{
string tendenz;
if (oldEntry == null)
{
oldEntry = entry;
}
var old = float.Parse(oldEntry.Price());
var neu = float.Parse(entry.Price());
if (old < neu) { tendenz = " + "; }
else if (neu < old) { tendenz = " - "; }
else { tendenz = " = "; }
notification(entry + tendenz);
entryAuditor.WriteEntry(entry);
oldEntry = entry;
}
}
}
}