Compare commits

..

No commits in common. "72d6e1e25469b0b29ac89e895073ef3abebfe18b" and "a387032b1ca4d8a8e78a759ea0e7f42665edcc79" have entirely different histories.

11 changed files with 0 additions and 307 deletions

3
.gitignore vendored
View File

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

27
.vscode/launch.json vendored
View File

@ -1,27 +0,0 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net7.0/newsletter.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false,
"requireExactSource": true
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}

41
.vscode/tasks.json vendored
View File

@ -1,41 +0,0 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/newsletter.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/newsletter.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/newsletter.csproj"
],
"problemMatcher": "$msCompile"
}
]
}

View File

@ -1,16 +0,0 @@
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 ReporterClass { get; set; }
public string Url { get; set; }
public string Username { get; set; }
public string Password { get; set; }
}
}
}

View File

@ -1,122 +0,0 @@
#pragma warning disable CS8618
using System;
using System.Linq;
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;
using Newtonsoft.Json;
namespace newsletter
{
class Program
{
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)
{
var toReturn = new List<Task<Report>>();
var reporterTypes = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(domainAssembly => domainAssembly.GetTypes())
.Where(type => type.IsSubclassOf(typeof(newsletter.Reporters.Reporter)) && !type.IsAbstract)
.ToList();
var skipPortionInName = "newsletter.Reporters.".Length;
foreach(var discoveredConfType in conf.Reporters.Select(r => r.ReporterClass))
{
Console.WriteLine($"{discoveredConfType} configuration type discovered");
}
foreach (var reporterType in reporterTypes)
{
Console.WriteLine($"{reporterType.ToString().Substring(skipPortionInName).ToLower()} reporter class discovered");
Func<Configuration.Reporter, bool> predicate = r => r.ReporterClass == reporterType.ToString().Substring(skipPortionInName).ToLower();
if (!conf.Reporters.Any(predicate))
{
Console.WriteLine($"no configurations for it");
}
else
{
var configurationsFor = conf.Reporters.Where(predicate);
Console.WriteLine($"{configurationsFor.Count()} configurations for it");
foreach (var confFor in configurationsFor)
{
var instance = (newsletter.Reporters.Reporter) Activator.CreateInstance(reporterType);
toReturn.Add(instance.Report(confFor));
}
}
}
return toReturn;
}
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
Console.WriteLine($"assembling {reportSections.Count()} sections");
throw new NotImplementedException();
}
}
}

View File

@ -1,17 +0,0 @@
#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; }
}
}

View File

@ -1,19 +0,0 @@
using HtmlAgilityPack;
using System.Threading.Tasks;
namespace newsletter.Reporters
{
public class Dummy : Reporter
{
#pragma warning disable CS1998
public override 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
}
}

View File

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

View File

@ -1,19 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.11.40" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="puppeteersharp" Version="5.0.0" />
<PackageReference Include="WebDav-Client" Version="1.1.2" />
<PackageReference Include="Ical.Net" Version="4.2.0" />
</ItemGroup>
</Project>

View File

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

View File

@ -1,23 +0,0 @@
<!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>