Compare commits
2 Commits
56a4bcbcb5
...
19be02798c
Author | SHA1 | Date | |
---|---|---|---|
19be02798c | |||
36c8805ce9 |
@ -8,9 +8,7 @@ namespace newsletter
|
|||||||
public class Reporter
|
public class Reporter
|
||||||
{
|
{
|
||||||
public string ReporterClass { get; set; }
|
public string ReporterClass { get; set; }
|
||||||
public string Url { get; set; }
|
public IEnumerable<KeyValuePair<string, string>> Misc { get; set; }
|
||||||
public string Username { get; set; }
|
|
||||||
public string Password { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -79,7 +79,7 @@ namespace newsletter
|
|||||||
foreach (var reporterType in reporterTypes)
|
foreach (var reporterType in reporterTypes)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"{reporterType.ToString().Substring(skipPortionInName).ToLower()} reporter class discovered");
|
Console.WriteLine($"{reporterType.ToString().Substring(skipPortionInName).ToLower()} reporter class discovered");
|
||||||
Func<Configuration.Reporter, bool> predicate = r => r.ReporterClass == reporterType.ToString().Substring(skipPortionInName).ToLower();
|
Func<Configuration.Reporter, bool> predicate = r => r.ReporterClass?.ToLower() == reporterType.ToString().Substring(skipPortionInName).ToLower();
|
||||||
if (!conf.Reporters.Any(predicate))
|
if (!conf.Reporters.Any(predicate))
|
||||||
{
|
{
|
||||||
Console.WriteLine($"no configurations for it");
|
Console.WriteLine($"no configurations for it");
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using HtmlAgilityPack;
|
using HtmlAgilityPack;
|
||||||
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace newsletter.Reporters
|
namespace newsletter.Reporters
|
||||||
@ -8,9 +9,16 @@ namespace newsletter.Reporters
|
|||||||
#pragma warning disable CS1998
|
#pragma warning disable CS1998
|
||||||
public override async Task<Report> Report(Configuration.Reporter config)
|
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()
|
return new Report()
|
||||||
{
|
{
|
||||||
ReportContent = HtmlNode.CreateNode($"<div>dummy node for testing purposes. Url: {config.Url}, Username: {config.Username}, Password: {config.Password}.</div>"),
|
ReportContent = HtmlNode.CreateNode($"<div>{sb.ToString()}</div>"),
|
||||||
TextSummary = "dummy text for testing purposes"
|
TextSummary = "dummy text for testing purposes"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
85
Reporters/NextcloudCalendars.cs
Normal file
85
Reporters/NextcloudCalendars.cs
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
@ -9,10 +9,11 @@
|
|||||||
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="CalDAV.NET" Version="0.1.0-alpha2" />
|
||||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.40" />
|
<PackageReference Include="HtmlAgilityPack" Version="1.11.40" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||||
<PackageReference Include="puppeteersharp" Version="5.0.0" />
|
<PackageReference Include="puppeteersharp" Version="5.0.0" />
|
||||||
<PackageReference Include="WebDav-Client" Version="1.1.2" />
|
<PackageReference Include="webDav.client" Version="2.8.0" />
|
||||||
<PackageReference Include="Ical.Net" Version="4.2.0" />
|
<PackageReference Include="Ical.Net" Version="4.2.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
{
|
{
|
||||||
"exportPath": "./newsletter.html",
|
"exportPath": "../newsletter.html",
|
||||||
"reporters": [
|
"reporters": [
|
||||||
{
|
{
|
||||||
"type":"dummy",
|
"reporterClass":"dummy",
|
||||||
"url": "localhost:8080",
|
"misc":[
|
||||||
"username": "guy who didn't configure",
|
{"key": "url", "value": "localhost:8080"},
|
||||||
"password": "sordph1sh"
|
{"key": "username", "value": "guy who didn't configure"},
|
||||||
|
{"key": "password", "value": "sordph1sh"}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user