caldav problems
how did this work back in the silver meddlists days?
This commit is contained in:
parent
36c8805ce9
commit
19be02798c
@ -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");
|
||||||
|
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>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user