-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
59 lines (49 loc) · 1.52 KB
/
Program.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
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.IO;
using System.Threading;
using CheckSaturday;
using CheckSaturday.ScheduleProcessors;
if (args.Length != 1) throw new Exception("Не указан токен для бота.");
SetUpdateScheduleTimer();
while (ScheduleStaticCover.Couples is null) Thread.Sleep(100);
_ = TelegramBot.Start(args[0]);
Console.WriteLine("Press 'q' to stop program and exit...");
while (true)
{
var key = Console.ReadKey();
if (key.Key == ConsoleKey.Q)
{
try
{
Directory.Delete(ScheduleFromTelegram.CachePath, true);
}
catch
{
Console.WriteLine("Main >> дирректория не была создана");
}
return;
}
}
static async void SetUpdateScheduleTimer()
{
await ScheduleDownloader.CheckUpdate();
ScheduleStaticCover.Update(ScheduleDownloader.CacheDir);
var updateInterval = new TimeSpan(hours: ScheduleDownloader.HoursCacheIsActual, minutes: 5, seconds: 0);
var updateTimer = new System.Timers.Timer(updateInterval);
updateTimer.Elapsed += (_, _) => FullUpdate();
updateTimer.AutoReset = true;
updateTimer.Enabled = true;
updateTimer.Start();
}
static async void FullUpdate()
{
try
{
if (await ScheduleDownloader.CheckUpdate())
ScheduleStaticCover.Update(ScheduleDownloader.CacheDir);
}
catch
{
Console.WriteLine("Error >> Не удалось обновить расписание.");
}
}