-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
132 lines (106 loc) · 2.81 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using LoadScript;
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using YamlDotNet.Serialization;
const string ProgressFilename = "LastMonthDone.txt";
const string ConfigFile = "Config.yaml";
Config config;
if(!File.Exists(ConfigFile))
{
try
{
Console.WriteLine($"{ConfigFile} not found, you will be prompted for settings now");
config = Config.MakeUserType();
Console.WriteLine($"Storing the settings you entered into {ConfigFile}");
var serializer = new Serializer();
File.WriteAllText(ConfigFile, serializer.Serialize(config));
}
catch (Exception ex)
{
Console.WriteLine($"Failed to get or store {ConfigFile} settings from user: {ex}");
return;
}
}
else
{
try
{
var deserialize = new Deserializer();
config = deserialize.Deserialize<Config>(File.ReadAllText(ConfigFile));
Console.WriteLine($"Loaded settings in {ConfigFile}");
}
catch (Exception ex)
{
Console.WriteLine($"Failed to deserialize {ConfigFile}: {ex}");
return;
}
}
string startAtMonth;
if (!File.Exists(ProgressFilename))
{
startAtMonth = "01";
}
else
{
var progress = int.Parse(File.ReadAllText(ProgressFilename).Trim());
progress++;
startAtMonth = progress.ToString("D2");
}
int year = int.Parse(new DirectoryInfo(config.YearDir).Name);
int month = int.Parse(startAtMonth);
GoGo:
if (month > 12)
{
Console.WriteLine("Year is finished");
return;
}
StringBuilder sb = new StringBuilder();
for(int i=1;i<= DateTime.DaysInMonth(year, month); i++)
{
sb.AppendLine(Path.Combine(config.YearDir, month.ToString("D2"), i.ToString("D2")));
}
File.WriteAllText(Path.Combine(config.ForLoading, "LoadMe.txt"), sb.ToString());
int retryIdx = 0;
Retry:
var pCheck = Process.Start(config.RdmpCli, $"dle -l {config.LoadMetadataID} --command check");
pCheck.WaitForExit();
if(pCheck.ExitCode != 0)
{
Console.WriteLine("Checking failed");
if(config.ShouldTry(retryIdx))
{
config.RetrySleep(retryIdx);
retryIdx++;
Console.WriteLine("Retrying checks");
goto Retry;
}
else
{
Console.WriteLine("Giving up, failed too often");
return;
}
}
var pRun = Process.Start(config.RdmpCli, $"dle -l {config.LoadMetadataID} --command run");
pRun.WaitForExit();
if (pRun.ExitCode != 0)
{
Console.WriteLine("Running failed");
if (config.ShouldTry(retryIdx))
{
config.RetrySleep(retryIdx);
retryIdx++;
Console.WriteLine("Retrying (starting with rechecking)");
goto Retry;
}
else
{
Console.WriteLine("Giving up, failed too often");
return;
}
}
// we finished this month succesfully
File.WriteAllText(ProgressFilename, month.ToString("D2"));
month++;
goto GoGo;