-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
73 lines (61 loc) · 2.22 KB
/
Program.cs
File metadata and controls
73 lines (61 loc) · 2.22 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using Newtonsoft.Json;
using System;
using System.IO;
namespace BlueStacksAssignment
{
class Program
{
public static void Main(string[] args)
{
Log log = null;
JsonInputData items = null;
try
{
log = new Log("Logs.txt", false);
using (StreamReader sr = new StreamReader("input.json"))
{
string json = sr.ReadToEnd();
items = JsonConvert.DeserializeObject<JsonInputData>(json);
}
ApiClient.InitializeApiClient();
foreach (string item in items.City)
{
log.WriteLine($"Checking weather conditions for {item}", LogType.INFO);
WeatherModel itemWM = WeatherProcessor.GetWeatherDetails(item, Units.Metric, log);
float tempAPI = 0;
if (itemWM != null)
{
tempAPI = itemWM.main.Temp;
SeleniumHelper seleniumHelper = new SeleniumHelper(log);
float tempUI;
if (!seleniumHelper.GetCurrentCityTemperature(item, out tempUI))
{
log.WriteLine("Failed to Initialize Selenium Web Driver", LogType.ERROR);
}
if (Math.Abs(tempAPI - tempUI) > items.Variance)
{
throw new MatcherException($"Temperature variance has been found to be more than {items.Variance} for {item}");
}
}
}
}
finally
{
ApiClient.Dispose();
if(log != null)
log.Dispose();
}
}
}
public class JsonInputData
{
public string[] City { get; set; }
public int Variance { get; set; }
}
public class MatcherException : Exception
{
public MatcherException(string message) : base($"Matcher Exception: {message}")
{
}
}
}