basic structure

This commit is contained in:
Adam R Grey 2023-03-22 11:03:06 -04:00
parent 0b7bca27f7
commit b64edf8f8a
9 changed files with 163 additions and 3 deletions

3
.gitignore vendored
View File

@ -1,3 +1,6 @@
appsettings.json
# ---> VisualStudioCode # ---> VisualStudioCode
.vscode/* .vscode/*
!.vscode/settings.json !.vscode/settings.json

16
Configuration.cs Normal file
View File

@ -0,0 +1,16 @@
using System.Collections.Generic;
namespace newsletter
{
public class Configuration
{
public string ExportPath { get; set; }
public List<Reporter> 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; }
}
}
}

View File

@ -1,4 +1,6 @@
using System; #pragma warning disable CS8618
using System;
using System.Linq;
using System.Net.Http.Json; using System.Net.Http.Json;
using Ical.Net; using Ical.Net;
using System.Collections.Generic; using System.Collections.Generic;
@ -13,6 +15,7 @@ using System.Threading.Tasks;
using System.Xml; using System.Xml;
using HtmlAgilityPack; using HtmlAgilityPack;
using System.Diagnostics; using System.Diagnostics;
using Newtonsoft.Json;
namespace newsletter namespace newsletter
{ {
@ -20,7 +23,66 @@ namespace newsletter
{ {
static async Task Main(string[] args) 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<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;
}
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();
}
} }
} }

17
Report.cs Normal file
View File

@ -0,0 +1,17 @@
#pragma warning disable CS8618
using HtmlAgilityPack;
namespace newsletter
{
public class Report
{
///<summary>
///gets embedded in the web page. reporter should have this be a div, and assembler will add classes and attributes or whatever
///</summary>
public HtmlNode ReportContent { get; set; }
///<summary>
///if I ever hook this up to TTS, this is the text that will be spoken
///</summary>
public string TextSummary { get; set; }
}
}

19
Reporters/Dummy.cs Normal file
View File

@ -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> Report(Configuration.Reporter config)
{
return new Report()
{
ReportContent = HtmlNode.CreateNode($"<div>dummy node for testing purposes. Url: {config.Url}, Username: {config.Username}, Password: {config.Password}.</div>"),
TextSummary = "dummy text for testing purposes"
};
}
#pragma warning restore CS1998
}
}

9
Reporters/Reporter.cs Normal file
View File

@ -0,0 +1,9 @@
using System.Threading.Tasks;
namespace newsletter.Reporters
{
public interface Reporter
{
Task<Report> Report(Configuration.Reporter config);
}
}

View File

@ -4,7 +4,7 @@
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>disable</Nullable>
</PropertyGroup> </PropertyGroup>

11
sample-appsettings.json Normal file
View File

@ -0,0 +1,11 @@
{
"exportPath": "./newsletter.html",
"reporters": [
{
"type":"dummy",
"url": "localhost:8080",
"username": "guy who didn't configure",
"password": "sordph1sh"
}
]
}

23
template.html Normal file
View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body{
background-color: #202020;
color:white;
}
.report-content{
display:block;
border-radius: 1em;
border: 0.125em solid white;
padding: 0.25em 0.5em;
margin-top: 1em;
}
</style>
</head>
<body>
<div class="report-content">sample report</div>
<div class="report-content">sample report</div>
</body>
</html>