Compare commits

..

No commits in common. "19be02798cb34803863b07af1bdd13fbb20b8814" and "56a4bcbcb577777de38ab87dac50074c52af6e10" have entirely different histories.

6 changed files with 11 additions and 105 deletions

View File

@ -8,7 +8,9 @@ namespace newsletter
public class Reporter
{
public string ReporterClass { get; set; }
public IEnumerable<KeyValuePair<string, string>> Misc { get; set; }
public string Url { get; set; }
public string Username { get; set; }
public string Password { get; set; }
}
}
}

View File

@ -79,7 +79,7 @@ namespace newsletter
foreach (var reporterType in reporterTypes)
{
Console.WriteLine($"{reporterType.ToString().Substring(skipPortionInName).ToLower()} reporter class discovered");
Func<Configuration.Reporter, bool> predicate = r => r.ReporterClass?.ToLower() == reporterType.ToString().Substring(skipPortionInName).ToLower();
Func<Configuration.Reporter, bool> predicate = r => r.ReporterClass == reporterType.ToString().Substring(skipPortionInName).ToLower();
if (!conf.Reporters.Any(predicate))
{
Console.WriteLine($"no configurations for it");

View File

@ -1,5 +1,4 @@
using HtmlAgilityPack;
using System.Text;
using System.Threading.Tasks;
namespace newsletter.Reporters
@ -9,16 +8,9 @@ namespace newsletter.Reporters
#pragma warning disable CS1998
public override async Task<Report> Report(Configuration.Reporter config)
{
var sb = new StringBuilder();
sb.AppendLine("dummy node for testing purposes.");
if(config.Misc?.Any() == true)
foreach (var miscConfig in config.Misc)
{
sb.AppendLine($"{miscConfig.Key}: {miscConfig.Value}");
}
return new Report()
{
ReportContent = HtmlNode.CreateNode($"<div>{sb.ToString()}</div>"),
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"
};
}

View File

@ -1,85 +0,0 @@
using HtmlAgilityPack;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using CalDAV.NET;//https://github.com/markatk/CalDAV.NET
namespace newsletter.Reporters
{
public class NextcloudCalendars : Reporter
{
public Uri url { get; set; }
public string username_bot { get; set; }
public string password_bot { get; set; }
public string username_self { get; set; }
public string password_self { get; set; }
#pragma warning disable CS1998
public override async Task<Report> Report(Configuration.Reporter config)
{
url = new Uri(config.Misc.FirstOrDefault(kvp => kvp.Key == "url").Value);
username_bot = config.Misc.FirstOrDefault(kvp => kvp.Key == "username_bot").Value;
password_bot = config.Misc.FirstOrDefault(kvp => kvp.Key == "password_bot").Value;
username_self = config.Misc.FirstOrDefault(kvp => kvp.Key == "username_self").Value;
password_self = config.Misc.FirstOrDefault(kvp => kvp.Key == "password_self").Value;
var sb = new StringBuilder();
sb.AppendLine("nextcloud calendars");
var client = new CalDAV.NET.Client(url, username_bot, password_bot);
var cals = await client.GetCalendarsAsync();
if(cals != null && cals.Any())
{
foreach(var cal in cals)
{
sb.AppendLine($"{cal.DisplayName}<br />");
}
}
else
{
sb.AppendLine("no cals found");
}
// var clientParams = new WebDavClientParams
// {
// BaseAddress = url,
// Credentials = new NetworkCredential(username_bot, password_bot)
// };
// using (var client = new WebDavClient(clientParams))
// {
// var result = await client.Propfind(url);
// sb.AppendLine($"{result.StatusCode} - {result.Resources?.Count() ?? 0} items<br />");
// if (result.Resources.Any())
// {
// foreach (var resource in result.Resources)
// {
// if (resource.Uri.EndsWith("/calendars/"))
// {
// sb.AppendLine($"calendars: {resource.Uri}");
// var resutl2 = await client.GetFileResponse if (resutl2.IsSuccessful && resutl2.Resources?.Any() == true)
// {
// foreach (var resource2 in result.Resources)
// {
// sb.AppendLine($"<br />{resource2.DisplayName} - {resource2.Uri} - is collection? {resource2.IsCollection} - {resource2}");
// }
// }
// }
// }
// }
// }
if (config.Misc?.Any() == true)
foreach (var miscConfig in config.Misc)
{
sb.AppendLine($"{miscConfig.Key}: {miscConfig.Value}");
}
return new Report()
{
ReportContent = HtmlNode.CreateNode($"<div>{sb.ToString()}</div>"),
TextSummary = "dummy text for testing purposes"
};
}
#pragma warning restore CS1998
}
}

View File

@ -9,11 +9,10 @@
<ItemGroup>
<PackageReference Include="CalDAV.NET" Version="0.1.0-alpha2" />
<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="2.8.0" />
<PackageReference Include="WebDav-Client" Version="1.1.2" />
<PackageReference Include="Ical.Net" Version="4.2.0" />
</ItemGroup>

View File

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