diff --git a/.gitignore b/.gitignore index bc6c934..4495b22 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +appsettings.json + + # ---> VisualStudioCode .vscode/* !.vscode/settings.json diff --git a/Configuration.cs b/Configuration.cs new file mode 100644 index 0000000..3751fbf --- /dev/null +++ b/Configuration.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; +namespace newsletter +{ + public class Configuration + { + public string ExportPath { get; set; } + public List Reporters { get; set; } + public class Reporter + { + public string Type { get; set; } + public string Url { get; set; } + public string Username { get; set; } + public string Password { get; set; } + } + } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs index 818d7ab..ef48af7 100644 --- a/Program.cs +++ b/Program.cs @@ -1,4 +1,6 @@ -using System; +#pragma warning disable CS8618 +using System; +using System.Linq; using System.Net.Http.Json; using Ical.Net; using System.Collections.Generic; @@ -13,6 +15,7 @@ using System.Threading.Tasks; using System.Xml; using HtmlAgilityPack; using System.Diagnostics; +using Newtonsoft.Json; namespace newsletter { @@ -20,7 +23,66 @@ namespace newsletter { static async Task Main(string[] args) { - + 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; + } + + var conf = JsonConvert.DeserializeObject(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; + } + + static List> CollectReporters(Configuration conf) + { + //TODO + throw new NotImplementedException(); + } + + static async Task> CollectReports(List> tasks) + { + var results = new List(); + foreach(var task in tasks) + { + var rep = await task; + results.Add(rep); + } + return results; + } + + static HtmlDocument AssembleHTML(IEnumerable reportSections) + { + //TODO + throw new NotImplementedException(); + } + } } diff --git a/Report.cs b/Report.cs new file mode 100644 index 0000000..7b59e49 --- /dev/null +++ b/Report.cs @@ -0,0 +1,17 @@ +#pragma warning disable CS8618 +using HtmlAgilityPack; + +namespace newsletter +{ + public class Report + { + /// + ///gets embedded in the web page. reporter should have this be a div, and assembler will add classes and attributes or whatever + /// + public HtmlNode ReportContent { get; set; } + /// + ///if I ever hook this up to TTS, this is the text that will be spoken + /// + public string TextSummary { get; set; } + } +} \ No newline at end of file diff --git a/Reporters/Dummy.cs b/Reporters/Dummy.cs new file mode 100644 index 0000000..a68588a --- /dev/null +++ b/Reporters/Dummy.cs @@ -0,0 +1,19 @@ +using HtmlAgilityPack; +using System.Threading.Tasks; + +namespace newsletter.Reporters +{ + public class Dummy : Reporter + { + #pragma warning disable CS1998 + public async Task Report(Configuration.Reporter config) + { + return new Report() + { + ReportContent = HtmlNode.CreateNode($"
dummy node for testing purposes. Url: {config.Url}, Username: {config.Username}, Password: {config.Password}.
"), + TextSummary = "dummy text for testing purposes" + }; + } + #pragma warning restore CS1998 + } +} \ No newline at end of file diff --git a/Reporters/Reporter.cs b/Reporters/Reporter.cs new file mode 100644 index 0000000..412ca4b --- /dev/null +++ b/Reporters/Reporter.cs @@ -0,0 +1,9 @@ +using System.Threading.Tasks; + +namespace newsletter.Reporters +{ + public interface Reporter + { + Task Report(Configuration.Reporter config); + } +} \ No newline at end of file diff --git a/newsletter.csproj b/newsletter.csproj index 0e069c8..cbdffdd 100644 --- a/newsletter.csproj +++ b/newsletter.csproj @@ -4,7 +4,7 @@ Exe net7.0 enable - enable + disable diff --git a/sample-appsettings.json b/sample-appsettings.json new file mode 100644 index 0000000..97df911 --- /dev/null +++ b/sample-appsettings.json @@ -0,0 +1,11 @@ +{ + "exportPath": "./newsletter.html", + "reporters": [ + { + "type":"dummy", + "url": "localhost:8080", + "username": "guy who didn't configure", + "password": "sordph1sh" + } + ] +} \ No newline at end of file diff --git a/template.html b/template.html new file mode 100644 index 0000000..dca527d --- /dev/null +++ b/template.html @@ -0,0 +1,23 @@ + + + + + + +
sample report
+
sample report
+ + \ No newline at end of file