-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
43 lines (36 loc) · 1.58 KB
/
Copy pathProgram.cs
File metadata and controls
43 lines (36 loc) · 1.58 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
using Microsoft.Extensions.Configuration;
namespace Calio;
public class Program
{
public static void Main(string[] args)
{
var workingFolder = ReadConfig("config.json").GetValue<string>("WorkingFolder")
?? throw new InvalidOperationException("WorkingFolder not found in config file.");
var calendarFilePaths = Directory.GetFiles(workingFolder, "*.ics").ToList();
var eventLists = new List<CalendarEventModel>[calendarFilePaths.Count];
for (int i = 0; i < calendarFilePaths.Count; i++)
{
eventLists[i] = CalendarService.GetUpcomingEvents(calendarFilePaths[i]);
}
CreateAllMonthlyCalendars(eventLists, workingFolder);
}
static IConfiguration ReadConfig(string configFileName)
{
var configBuilder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(configFileName, optional: false);
return configBuilder.Build();
}
static void CreateAllMonthlyCalendars(List<CalendarEventModel>[] eventLists, string workingFolder)
{
int year = DateTime.Now.Year;
int startMonth = DateTime.Now.Month;
for (int m = 0; m < 6; m++)
{
int month = ((startMonth - 1 + m) % 12) + 1;
int thisYear = year + ((startMonth - 1 + m) / 12);
string fileName = Path.Combine(workingFolder, $"Calendar_{thisYear}_{month:D2}.html");
CalendarHtmlGenerator.CreateMonthlyCalendarHtml(fileName, eventLists, thisYear, month);
}
}
}