-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
95 lines (67 loc) · 2.71 KB
/
Program.cs
File metadata and controls
95 lines (67 loc) · 2.71 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Configuration;
using System.Net;
using System.Net.Mail;
using System.Threading;
using System.Timers;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace ConsoleApp2
{
class Program
{
private static readonly IWebDriver driver = new ChromeDriver();
static void Main(string[] args)
{
Console.WriteLine(DateTime.Now.ToString() + " Started");
int timers = Int32.Parse(ConfigurationManager.AppSettings["TimerS"]);
CheckWebPage();
var aTimer = new System.Timers.Timer(timers*1000);
aTimer.Elapsed += OnTimedEvent;
aTimer.Start();
Console.WriteLine(DateTime.Now.ToString() + " Click enter to escape ...");
Console.ReadLine();
driver.Close();
driver.Quit();
}
private static void OnTimedEvent(Object source, ElapsedEventArgs e)
{
Console.WriteLine(DateTime.Now.ToString() + " timer start");
CheckWebPage();
Console.WriteLine(DateTime.Now.ToString() + " timer finished");
}
private static void CheckWebPage()
{
int sleepAfterRequestMS = Int32.Parse(ConfigurationManager.AppSettings["SleepAfterRequestMS"]);
string checkValue = ConfigurationManager.AppSettings["CheckPhrase"];
string url = ConfigurationManager.AppSettings["Address"];
driver.Navigate().GoToUrl(url);
Thread.Sleep(sleepAfterRequestMS);
String html = driver.PageSource;
if (!html.Contains(checkValue))
{
SendEmailWithErro(driver.Url, html, checkValue);
}
else
{
Console.WriteLine(DateTime.Now + " PASS");
}
}
private static void SendEmailWithErro(string url, string result, string phrase)
{
string destinationEmail = ConfigurationManager.AppSettings["DestinationEmail"];
string fromEmail = ConfigurationManager.AppSettings["FromEmail"];
string fromEmailPassword = ConfigurationManager.AppSettings["FromEmailPassword"];
var client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential(fromEmail, fromEmailPassword),
EnableSsl = true
};
string message = "Link Address Was Not Found in:\r\n" + url + "\r\n \r\n"
+ "Phrase: \r\n" + phrase + " \r\n" + " \r\n"
+ "HTML: \r\n" + result;
client.Send(fromEmail, destinationEmail, url, message );
Console.WriteLine(DateTime.Now + " Email Sent");
}
}
}