2023-03-22 11:03:06 -04:00
|
|
|
|
#pragma warning disable CS8618
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2023-03-22 09:32:33 -04:00
|
|
|
|
using System.Net.Http.Json;
|
|
|
|
|
using Ical.Net;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Net.Http.Headers;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
using HtmlAgilityPack;
|
|
|
|
|
using System.Diagnostics;
|
2023-03-22 11:03:06 -04:00
|
|
|
|
using Newtonsoft.Json;
|
2023-03-22 09:32:33 -04:00
|
|
|
|
|
|
|
|
|
namespace newsletter
|
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
|
|
|
|
static async Task Main(string[] args)
|
|
|
|
|
{
|
2023-03-22 11:03:06 -04:00
|
|
|
|
var conf = Configure();
|
|
|
|
|
if(conf == null) return;
|
|
|
|
|
|
|
|
|
|
var reports = await CollectReports(CollectReporters(conf));
|
|
|
|
|
|
|
|
|
|
var fullHtml = AssembleHTML(reports.Select(r => r.ReportContent));
|
|
|
|
|
|
|
|
|
|
fullHtml.Save(conf.ExportPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Configuration Configure(string configurationPath = "appsettings.json")
|
|
|
|
|
{
|
|
|
|
|
if(!File.Exists(configurationPath))
|
|
|
|
|
{
|
|
|
|
|
Console.Error.WriteLine($"could not find configuration at {configurationPath}! copying sample to that spot.");
|
|
|
|
|
File.Copy("sample-appsettings.json", configurationPath); //and you know what, if that explodes at the OS level, the OS should give you an error
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
var fileContents = File.ReadAllText(configurationPath);
|
|
|
|
|
if(string.IsNullOrWhiteSpace(fileContents))
|
|
|
|
|
{
|
|
|
|
|
Console.Error.WriteLine($"configuration file at {configurationPath} was empty! overwriting with sample settings.");
|
|
|
|
|
File.Copy("sample-appsettings.json", configurationPath, true);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2023-03-22 09:32:33 -04:00
|
|
|
|
|
2023-03-22 11:03:06 -04:00
|
|
|
|
var conf = JsonConvert.DeserializeObject<Configuration>(fileContents);
|
|
|
|
|
|
|
|
|
|
if(conf == null)
|
|
|
|
|
{
|
|
|
|
|
Console.Error.WriteLine($"configuration file at {configurationPath} was empty! overwriting with sample settings.");
|
|
|
|
|
File.Copy("sample-appsettings.json", configurationPath, true);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return conf;
|
2023-03-22 09:32:33 -04:00
|
|
|
|
}
|
2023-03-22 11:03:06 -04:00
|
|
|
|
|
|
|
|
|
static List<Task<Report>> CollectReporters(Configuration conf)
|
|
|
|
|
{
|
|
|
|
|
//TODO
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static async Task<List<Report>> CollectReports(List<Task<Report>> tasks)
|
|
|
|
|
{
|
|
|
|
|
var results = new List<Report>();
|
|
|
|
|
foreach(var task in tasks)
|
|
|
|
|
{
|
|
|
|
|
var rep = await task;
|
|
|
|
|
results.Add(rep);
|
|
|
|
|
}
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HtmlDocument AssembleHTML(IEnumerable<HtmlNode> reportSections)
|
|
|
|
|
{
|
|
|
|
|
//TODO
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-22 09:32:33 -04:00
|
|
|
|
}
|
|
|
|
|
}
|