more work on api & rename to Pilz.Net

This commit is contained in:
Pilzinsel64
2024-08-16 06:59:39 +02:00
parent f57aef5f4f
commit 2efb4f141c
91 changed files with 299 additions and 241 deletions

View File

@@ -1,6 +1,8 @@
using Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model; using Pilz.Net.CloudProviders.Nextcloud;
using Pilz.Net.CloudProviders.Nextcloud.Client;
using Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention; namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention;
public class FilesRetentionClient : ClientBase public class FilesRetentionClient : ClientBase
{ {

View File

@@ -1,6 +1,6 @@
using Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs; using Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model; namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model;
public class RetentionRule : RetentionRuleInfo public class RetentionRule : RetentionRuleInfo
{ {

View File

@@ -1,6 +1,6 @@
using Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs; using Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model; namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model;
public class RetentionRuleInfo public class RetentionRuleInfo
{ {

View File

@@ -0,0 +1,7 @@
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model;
public enum RetentionTimeAfter
{
CreationDate,
LastAccess
}

View File

@@ -0,0 +1,9 @@
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model;
public enum RetentionTimeUnit
{
Day,
Week,
Month,
Year
}

View File

@@ -1,7 +1,7 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using Pilz.Networking.CloudProviders.Nextcloud.Ocs; using Pilz.Net.CloudProviders.Nextcloud.OCS;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs; namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs;
public class OcsDataRetentionRule : OcsData public class OcsDataRetentionRule : OcsData
{ {

View File

@@ -1,7 +1,7 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses; using Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs; namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs;
public class OcsResponseDataEntryRetention : OcsResponseDataEntry public class OcsResponseDataEntryRetention : OcsResponseDataEntry
{ {

View File

@@ -0,0 +1,7 @@
using Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs;
public class OcsResponseRetention : OcsResponse<OcsResponseDataArray<OcsResponseDataEntryRetention>>
{
}

View File

@@ -1,7 +1,8 @@
using Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs; using Pilz.Net.CloudProviders.Nextcloud;
using Pilz.Networking.CloudProviders.Nextcloud.Ocs; using Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs;
using Pilz.Net.CloudProviders.Nextcloud.OCS;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention; namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention;
public class OcsApiFilesRetention : OcsApiBase public class OcsApiFilesRetention : OcsApiBase
{ {

View File

@@ -1,6 +1,6 @@
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model; namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public class Column public class Column
{ {

View File

@@ -1,6 +1,6 @@
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model; namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public class ColumnSelectionOption public class ColumnSelectionOption
{ {

View File

@@ -0,0 +1,8 @@
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public enum ColumnSubtype
{
None,
Unknown,
Line
}

View File

@@ -0,0 +1,9 @@
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public enum ColumnType
{
Unknown,
Text,
Selection,
DateTime
}

View File

@@ -0,0 +1,5 @@
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public class Columns : List<Column>
{
}

View File

@@ -1,6 +1,6 @@
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model; namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public class Row public class Row
{ {

View File

@@ -1,6 +1,6 @@
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model; namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public class RowData public class RowData
{ {

View File

@@ -0,0 +1,5 @@
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public class RowSimple : List<object>
{
}

View File

@@ -1,6 +1,6 @@
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model; namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public class RowUpdate public class RowUpdate
{ {

View File

@@ -0,0 +1,5 @@
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public class Rows : List<Row>
{
}

View File

@@ -0,0 +1,5 @@
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public class RowsSimple : List<RowSimple>
{
}

View File

@@ -1,7 +1,8 @@
using Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model; using Pilz.Net.CloudProviders.Nextcloud;
using Pilz.Networking.CloudProviders.Nextcloud.Ocs; using Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
using Pilz.Net.CloudProviders.Nextcloud.OCS;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables; namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables;
public class OcsApiTables : OcsApiBase public class OcsApiTables : OcsApiBase
{ {

View File

@@ -1,6 +1,8 @@
using Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model; using Pilz.Net.CloudProviders.Nextcloud;
using Pilz.Net.CloudProviders.Nextcloud.Client;
using Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables; namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables;
public class TablesClient : ClientBase public class TablesClient : ClientBase
{ {

View File

@@ -1,4 +1,4 @@
namespace Pilz.Networking.CloudProviders.Nextcloud.Client; namespace Pilz.Net.CloudProviders.Nextcloud.Client;
/* Nicht gemergte Änderung aus Projekt "Pilz.Networking.CloudProviders.Nextcloud (net6.0)" /* Nicht gemergte Änderung aus Projekt "Pilz.Networking.CloudProviders.Nextcloud (net6.0)"

View File

@@ -1,6 +1,7 @@
using Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model; using Pilz.Net.CloudProviders.Nextcloud.Client;
using Pilz.Net.CloudProviders.Nextcloud.Client.Cloud.Model;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud; namespace Pilz.Net.CloudProviders.Nextcloud.Client.Cloud;
public class CloudClient : ClientBase public class CloudClient : ClientBase
{ {

View File

@@ -1,4 +1,4 @@
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model; namespace Pilz.Net.CloudProviders.Nextcloud.Client.Cloud.Model;
public class UserBackendCapabilities public class UserBackendCapabilities
{ {

View File

@@ -1,6 +1,7 @@
using Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Ocs; using Pilz.Net.CloudProviders.Nextcloud;
using Pilz.Net.CloudProviders.Nextcloud.Client.Cloud.Ocs;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model; namespace Pilz.Net.CloudProviders.Nextcloud.Client.Cloud.Model;
public class UserInfo public class UserInfo
{ {

View File

@@ -1,4 +1,4 @@
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model; namespace Pilz.Net.CloudProviders.Nextcloud.Client.Cloud.Model;
public class UserQuota public class UserQuota
{ {

View File

@@ -1,7 +1,7 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses; using Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Ocs; namespace Pilz.Net.CloudProviders.Nextcloud.Client.Cloud.Ocs;
public class OcsResponseDataUser : OcsResponseData public class OcsResponseDataUser : OcsResponseData
{ {

View File

@@ -0,0 +1,7 @@
using Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Cloud.Ocs;
public class OcsResponseUser : OcsResponse<OcsResponseDataUser>
{
}

View File

@@ -1,7 +1,8 @@
using Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Ocs; using Pilz.Net.CloudProviders.Nextcloud;
using Pilz.Networking.CloudProviders.Nextcloud.Ocs; using Pilz.Net.CloudProviders.Nextcloud.Client.Cloud.Ocs;
using Pilz.Net.CloudProviders.Nextcloud.OCS;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud; namespace Pilz.Net.CloudProviders.Nextcloud.Client.Cloud;
public class OcsApiCloud : OcsApiBase public class OcsApiCloud : OcsApiBase
{ {

View File

@@ -6,17 +6,9 @@ Nach:
using Pilz.Networking.CloudProviders.Nextcloud.Ocs; using Pilz.Networking.CloudProviders.Nextcloud.Ocs;
using System; using System;
*/ */
using using Pilz.Net.CloudProviders.Nextcloud.OCS;
/* Nicht gemergte Änderung aus Projekt "Pilz.Networking.CloudProviders.Nextcloud (net6.0)"
Vor:
using System.Threading.Tasks;
using Pilz.Networking.CloudProviders.Nextcloud.Ocs;
Nach:
using System.Threading.Tasks;
*/
Pilz.Networking.CloudProviders.Nextcloud.Ocs;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Core; namespace Pilz.Net.CloudProviders.Nextcloud.Client.Core;
public class OcsApiCore : OcsApiBase public class OcsApiCore : OcsApiBase
{ {

View File

@@ -1,6 +1,6 @@
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs; namespace Pilz.Net.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs;
public class OcsResponseLoginFlowV2 public class OcsResponseLoginFlowV2
{ {

View File

@@ -1,6 +1,6 @@
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs; namespace Pilz.Net.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs;
public class OcsResponseLoginFlowV2Credentials public class OcsResponseLoginFlowV2Credentials
{ {

View File

@@ -1,7 +1,7 @@
using Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs; using Pilz.Net.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs;
using Pilz.Networking.CloudProviders.Nextcloud.Ocs; using Pilz.Net.CloudProviders.Nextcloud.OCS;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2; namespace Pilz.Net.CloudProviders.Nextcloud.Client.LoginFlowV2;
public class OcsApiLoginFlowV2 : OcsApiBase public class OcsApiLoginFlowV2 : OcsApiBase
{ {

View File

@@ -1,7 +1,7 @@
using Pilz.Networking.CloudProviders.Nextcloud.Ocs; using Pilz.Net.CloudProviders.Nextcloud.OCS;
using System.Text; using System.Text;
namespace Pilz.Networking.CloudProviders.Nextcloud; namespace Pilz.Net.CloudProviders.Nextcloud;
public static class Extensions public static class Extensions
{ {

View File

@@ -1,7 +1,8 @@
using Pilz.Networking.CloudProviders.Nextcloud.Client; using Pilz.Net.CloudProviders.Nextcloud.Client;
using Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud; using Pilz.Net.CloudProviders.Nextcloud.Client.Cloud;
using Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model; using Pilz.Net.CloudProviders.Nextcloud.Client.Cloud.Model;
using Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs; using Pilz.Net.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs;
using Pilz.Net.CloudProviders.Nextcloud.OCS;
/* Nicht gemergte Änderung aus Projekt "Pilz.Networking.CloudProviders.Nextcloud (net6.0)" /* Nicht gemergte Änderung aus Projekt "Pilz.Networking.CloudProviders.Nextcloud (net6.0)"
Vor: Vor:
@@ -17,10 +18,9 @@ using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
*/ */
using Pilz.Networking.CloudProviders.Nextcloud.Ocs;
using System.Diagnostics; using System.Diagnostics;
namespace Pilz.Networking.CloudProviders.Nextcloud; namespace Pilz.Net.CloudProviders.Nextcloud;
public class NextcloudClient : IDisposable public class NextcloudClient : IDisposable
{ {

View File

@@ -1,6 +1,6 @@
using Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs; using Pilz.Net.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs;
namespace Pilz.Networking.CloudProviders.Nextcloud; namespace Pilz.Net.CloudProviders.Nextcloud;
public class NextcloudLogin public class NextcloudLogin
{ {

View File

@@ -1,4 +1,4 @@
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs; namespace Pilz.Net.CloudProviders.Nextcloud.OCS;
public delegate void GetOcsApiAuthCredentailsEventHandler(object sender, GetOcsApiAuthCredentailsEventArgs eventArgs); public delegate void GetOcsApiAuthCredentailsEventHandler(object sender, GetOcsApiAuthCredentailsEventArgs eventArgs);

View File

@@ -23,7 +23,9 @@ using
Nach: Nach:
using using
*/ */
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs; using Pilz.Net.CloudProviders.Nextcloud;
namespace Pilz.Net.CloudProviders.Nextcloud.OCS;
public class OcsApi : IDisposable public class OcsApi : IDisposable
{ {

View File

@@ -1,4 +1,4 @@
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs; namespace Pilz.Net.CloudProviders.Nextcloud.OCS;
public struct OcsApiAuthCredentials public struct OcsApiAuthCredentials
{ {

View File

@@ -1,4 +1,4 @@
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs; namespace Pilz.Net.CloudProviders.Nextcloud.OCS;
public abstract class OcsApiBase public abstract class OcsApiBase
{ {

View File

@@ -1,7 +1,7 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses; using Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs; namespace Pilz.Net.CloudProviders.Nextcloud.OCS;
public class OcsApiResponse<TOcsResponse> where TOcsResponse : IOcsResponse public class OcsApiResponse<TOcsResponse> where TOcsResponse : IOcsResponse
{ {

View File

@@ -1,4 +1,4 @@
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs; namespace Pilz.Net.CloudProviders.Nextcloud.OCS;
public readonly struct OcsApiUrlPath public readonly struct OcsApiUrlPath
{ {

View File

@@ -0,0 +1,5 @@
namespace Pilz.Net.CloudProviders.Nextcloud.OCS;
public class OcsData
{
}

View File

@@ -0,0 +1,5 @@
namespace Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
public interface IOcsResponse
{
}

View File

@@ -0,0 +1,5 @@
namespace Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
public interface IOcsResponseData
{
}

View File

@@ -0,0 +1,5 @@
namespace Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
public interface IOcsResponseMeta
{
}

View File

@@ -1,6 +1,6 @@
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses; namespace Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
public class OcsResponse<TMeta, TData> : IOcsResponse where TMeta : IOcsResponseMeta where TData : IOcsResponseData public class OcsResponse<TMeta, TData> : IOcsResponse where TMeta : IOcsResponseMeta where TData : IOcsResponseData
{ {

View File

@@ -0,0 +1,5 @@
namespace Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
public class OcsResponseData : IOcsResponseData
{
}

View File

@@ -1,4 +1,4 @@
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses; namespace Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
public class OcsResponseDataArray<TEntry> : List<TEntry>, IOcsResponseData where TEntry : OcsResponseDataEntry public class OcsResponseDataArray<TEntry> : List<TEntry>, IOcsResponseData where TEntry : OcsResponseDataEntry
{ {

View File

@@ -0,0 +1,5 @@
namespace Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
public class OcsResponseDataEntry
{
}

View File

@@ -1,6 +1,6 @@
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses; namespace Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
public class OcsResponseMeta : IOcsResponseMeta public class OcsResponseMeta : IOcsResponseMeta
{ {

View File

@@ -0,0 +1,20 @@
namespace Pilz.Net.Api;
public record class ApiAuthCheckEventArgs(string AuthKey)
{
private bool hasDenyed;
public bool Valid { get; set; }
public void Deny()
{
Valid = false;
hasDenyed = true;
}
public void Permit()
{
if (!hasDenyed)
Valid = true;
}
}

View File

@@ -1,17 +1,18 @@
namespace Pilz.Networking.Api; namespace Pilz.Net.Api;
public class ApiClient(string apiUrl) : IApiClient public class ApiClient(string apiUrl) : IApiClient
{ {
protected readonly HttpClient httpClient = new(); protected readonly HttpClient httpClient = new();
public string ApiUrl { get; } = apiUrl; public virtual string ApiUrl { get; } = apiUrl;
public IMessageSerializer Serializer { get; set; } = new DefaultMessageSerializer(); public string? AuthKey { get; set; }
public virtual IMessageSerializer Serializer { get; set; } = new DefaultMessageSerializer();
public virtual async Task<ApiResponse> SendMessage<TResponse>(string url, ApiMessage message, IMessageSerializer? serializer) public virtual async Task<ApiResponse> SendMessage<TResponse>(string url, ApiMessage message, IMessageSerializer? serializer)
{ {
serializer ??= Serializer; serializer ??= Serializer;
//message.AuthSecret = AuthSecret;
var res = await Send(url, message, serializer); var res = await Send(url, message, serializer);
@@ -21,7 +22,6 @@ public class ApiClient(string apiUrl) : IApiClient
public virtual async Task<ApiResponse<TResponse>> SendRequest<TResponse>(string url, ApiMessage message, IMessageSerializer? serializer) where TResponse : ApiMessage public virtual async Task<ApiResponse<TResponse>> SendRequest<TResponse>(string url, ApiMessage message, IMessageSerializer? serializer) where TResponse : ApiMessage
{ {
serializer ??= Serializer; serializer ??= Serializer;
//message.AuthSecret = AuthSecret;
var res = await Send(url, message, serializer); var res = await Send(url, message, serializer);
TResponse? result = null; TResponse? result = null;
@@ -36,6 +36,7 @@ public class ApiClient(string apiUrl) : IApiClient
{ {
var fullRequestUrl = ApiUrl + url; var fullRequestUrl = ApiUrl + url;
var content = new StringContent(serializer.Serialize(message)!, null, "application/json"); var content = new StringContent(serializer.Serialize(message)!, null, "application/json");
content.Headers.Add("API-AUTH-KEY", AuthKey);
return await httpClient.PostAsync(fullRequestUrl, content); return await httpClient.PostAsync(fullRequestUrl, content);
} }
} }

View File

@@ -0,0 +1,5 @@
namespace Pilz.Net.Api;
public abstract class ApiMessage
{
}

View File

@@ -1,6 +1,6 @@
using System.Net; using System.Net;
namespace Pilz.Networking.Api; namespace Pilz.Net.Api;
public record class ApiResponse( public record class ApiResponse(
HttpStatusCode StatusCode) HttpStatusCode StatusCode)

View File

@@ -1,6 +1,6 @@
using System.Net; using System.Net;
namespace Pilz.Networking.Api; namespace Pilz.Net.Api;
public record class ApiResponse<T>( public record class ApiResponse<T>(
HttpStatusCode StatusCode, HttpStatusCode StatusCode,

View File

@@ -1,6 +1,6 @@
using System.Net; using System.Net;
namespace Pilz.Networking.Api; namespace Pilz.Net.Api;
public record class ApiResult( public record class ApiResult(
HttpStatusCode StatusCode, HttpStatusCode StatusCode,

View File

@@ -1,19 +1,24 @@
using Pilz.Extensions.Reflection; using Pilz.Extensions.Reflection;
using System.Net; using System.Net;
using System.Reflection; using System.Reflection;
using static Pilz.Net.Api.IApiServer;
namespace Pilz.Networking.Api; namespace Pilz.Net.Api;
public class ApiServer(string apiUrl) : ApiClient, IApiServer public class ApiServer(string apiUrl) : IApiServer
{ {
protected readonly Dictionary<string, Delegate> handlers = []; protected readonly Dictionary<string, Delegate> handlers = [];
protected readonly Dictionary<Type, IMessageSerializer> serializers = []; protected readonly Dictionary<Type, IMessageSerializer> serializers = [];
protected readonly HttpListener httpListener = new(); protected readonly HttpListener httpListener = new();
public event OnCheckAuthenticationEventHandler? OnCheckAuthentication;
protected record PrivateApiResult(ApiResult Original, string? ResultJson); protected record PrivateApiResult(ApiResult Original, string? ResultJson);
public string ApiUrl { get; } = apiUrl; public string ApiUrl { get; } = apiUrl;
public virtual bool EnableAuth { get; set; }
public IMessageSerializer Serializer { get; set; } = new DefaultMessageSerializer(); public IMessageSerializer Serializer { get; set; } = new DefaultMessageSerializer();
public virtual void Start() public virtual void Start()
@@ -22,6 +27,11 @@ public class ApiServer(string apiUrl) : ApiClient, IApiServer
Listen(); Listen();
} }
public virtual void Stop()
{
httpListener.Stop();
}
public virtual void RegisterHandler<T>(T instance) where T : class public virtual void RegisterHandler<T>(T instance) where T : class
{ {
// Get all public instance methods // Get all public instance methods
@@ -44,7 +54,7 @@ public class ApiServer(string apiUrl) : ApiClient, IApiServer
throw new NotSupportedException("The first parameter needs to be of type ApiMessage and must return an ApiResult object and the method must have the MessageHandlerAttribute."); throw new NotSupportedException("The first parameter needs to be of type ApiMessage and must return an ApiResult object and the method must have the MessageHandlerAttribute.");
// Add handler // Add handler
handlers.Add(ApiUrl + attribute.Url, handler); handlers.Add(ApiUrl + attribute.Route, handler);
} }
protected virtual void Listen() protected virtual void Listen()
@@ -78,8 +88,12 @@ public class ApiServer(string apiUrl) : ApiClient, IApiServer
using StreamReader input = new(context.Request.InputStream); using StreamReader input = new(context.Request.InputStream);
var contentJson = input.ReadToEnd(); var contentJson = input.ReadToEnd();
// Get auth key
if (context.Request.Headers.Get("API-AUTH-KEY") is not string authKey)
authKey = null!;
// Handle message // Handle message
if (HandleMessage(path, contentJson) is not PrivateApiResult result) if (HandleMessage(path, contentJson, authKey) is not PrivateApiResult result)
{ {
close(); close();
return; return;
@@ -87,8 +101,6 @@ public class ApiServer(string apiUrl) : ApiClient, IApiServer
// Set response parameters // Set response parameters
context.Response.StatusCode = (int)result.Original.StatusCode; context.Response.StatusCode = (int)result.Original.StatusCode;
if (result.Original.StatusDescription is not null)
context.Response.StatusDescription = result.Original.StatusDescription;
// Write response content // Write response content
if (result.ResultJson is not null) if (result.ResultJson is not null)
@@ -101,13 +113,17 @@ public class ApiServer(string apiUrl) : ApiClient, IApiServer
close(); close();
} }
protected virtual PrivateApiResult? HandleMessage(string url, string json) protected virtual PrivateApiResult? HandleMessage(string url, string json, string? authKey)
{ {
// Get handler // Get handler
if (!handlers.TryGetValue(url, out var handler) if (!handlers.TryGetValue(url, out var handler)
|| handler.Method.GetCustomAttribute<MessageHandlerAttribute>() is not MessageHandlerAttribute attribute) || handler.Method.GetCustomAttribute<MessageHandlerAttribute>() is not MessageHandlerAttribute attribute)
return null; return null;
// Check authentication
if (attribute.RequiesAuth && (string.IsNullOrWhiteSpace(authKey) || !CheckAuthentication(authKey)))
return null;
// Get required infos // Get required infos
var targetType = handler.Method.GetParameters().First().ParameterType; var targetType = handler.Method.GetParameters().First().ParameterType;
var serializer = GetSerializer(attribute.Serializer); var serializer = GetSerializer(attribute.Serializer);
@@ -146,4 +162,15 @@ public class ApiServer(string apiUrl) : ApiClient, IApiServer
} }
return Serializer; return Serializer;
} }
protected virtual bool CheckAuthentication(string authKey)
{
if (OnCheckAuthentication != null)
{
var args = new ApiAuthCheckEventArgs(authKey);
OnCheckAuthentication?.Invoke(this, args);
return args.Valid;
}
return false;
}
} }

View File

@@ -1,6 +1,6 @@
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Pilz.Networking.Api; namespace Pilz.Net.Api;
public class DefaultMessageSerializer : IMessageSerializer public class DefaultMessageSerializer : IMessageSerializer
{ {

View File

@@ -1,7 +1,14 @@
namespace Pilz.Networking.Api; namespace Pilz.Net.Api;
public interface IApiClient public interface IApiClient
{ {
string ApiUrl { get; }
string? AuthKey { get; set; }
IMessageSerializer Serializer { get; }
Task<ApiResponse> SendMessage<TResponse>(string url, ApiMessage message, IMessageSerializer? serializer = null); Task<ApiResponse> SendMessage<TResponse>(string url, ApiMessage message, IMessageSerializer? serializer = null);
Task<ApiResponse<TResponse>> SendRequest<TResponse>(string url, ApiMessage message, IMessageSerializer? serializer = null) where TResponse : ApiMessage; Task<ApiResponse<TResponse>> SendRequest<TResponse>(string url, ApiMessage message, IMessageSerializer? serializer = null) where TResponse : ApiMessage;
} }

View File

@@ -0,0 +1,22 @@
namespace Pilz.Net.Api;
public interface IApiServer
{
public delegate void OnCheckAuthenticationEventHandler(object sender, ApiAuthCheckEventArgs e);
event OnCheckAuthenticationEventHandler? OnCheckAuthentication;
string ApiUrl { get; }
bool EnableAuth { get; set; }
IMessageSerializer Serializer { get; }
void Start();
void Stop();
void RegisterHandler<T>(T instance) where T : class;
void RegisterHandler(Delegate handler);
}

View File

@@ -1,4 +1,4 @@
namespace Pilz.Networking.Api; namespace Pilz.Net.Api;
public interface IMessageSerializer public interface IMessageSerializer
{ {

View File

@@ -0,0 +1,9 @@
namespace Pilz.Net.Api;
[AttributeUsage(AttributeTargets.Method)]
public class MessageHandlerAttribute(string route) : Attribute
{
public string Route { get; set; } = route;
public Type? Serializer { get; set; }
public bool RequiesAuth { get; set; }
}

View File

@@ -2,7 +2,7 @@
using System.Data; using System.Data;
using System.Net; using System.Net;
namespace Pilz.Networking; namespace Pilz.Net;
public abstract class ConnectionManagerBase(int port) public abstract class ConnectionManagerBase(int port)
{ {
@@ -14,7 +14,7 @@ public abstract class ConnectionManagerBase(int port)
public int Port { get; private set; } = port; public int Port { get; private set; } = port;
public bool UseAssemblyQualifiedName { get; set; } = false; public bool UseAssemblyQualifiedName { get; set; } = false;
public event RetriveDataEventHandler RetriveData; public event RetriveDataEventHandler? RetriveData;
public delegate void RetriveDataEventHandler(ConnectionManagerBase manager, string senderIP, string cmd, object content); public delegate void RetriveDataEventHandler(ConnectionManagerBase manager, string senderIP, string cmd, object content);

View File

@@ -2,23 +2,23 @@
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using System.Net.Sockets; using System.Net.Sockets;
namespace Pilz.Networking; namespace Pilz.Net;
public static class NetworkFeatures public static class NetworkFeatures
{ {
public static IPAddress GetIPFromHost(string hostName) public static IPAddress? GetIPFromHost(string hostName)
{ {
return Dns.GetHostAddresses(hostName).FirstOrDefault(n => n.AddressFamily == AddressFamily.InterNetwork); return Dns.GetHostAddresses(hostName).FirstOrDefault(n => n.AddressFamily == AddressFamily.InterNetwork);
} }
public static object GetHostFromIP(string ip) public static object? GetHostFromIP(string ip)
{ {
return Dns.GetHostEntry(ip)?.HostName; return Dns.GetHostEntry(ip)?.HostName;
} }
public static UnicastIPAddressInformation GetLocalIPInformations() public static UnicastIPAddressInformation? GetLocalIPInformations()
{ {
UnicastIPAddressInformation addr = null; UnicastIPAddressInformation? addr = null;
foreach (NetworkInterface adapter in NetworkInterface.GetAllNetworkInterfaces()) foreach (NetworkInterface adapter in NetworkInterface.GetAllNetworkInterfaces())
{ {
@@ -35,19 +35,19 @@ public static class NetworkFeatures
return addr; return addr;
} }
public static IPAddress GetLocalIPAddress() public static IPAddress? GetLocalIPAddress()
{ {
return GetLocalIPInformations()?.Address; return GetLocalIPInformations()?.Address;
} }
public static IPAddress GetLocalIPv4Mask() public static IPAddress? GetLocalIPv4Mask()
{ {
return GetLocalIPInformations()?.IPv4Mask; return GetLocalIPInformations()?.IPv4Mask;
} }
public static IPAddress GetLocalBoradcastIP(UnicastIPAddressInformation ipInfo) public static IPAddress GetLocalBoradcastIP(UnicastIPAddressInformation ipInfo)
{ {
IPAddress ip = null; IPAddress? ip = null;
byte[] myIPBytes = ipInfo.Address.GetAddressBytes(); byte[] myIPBytes = ipInfo.Address.GetAddressBytes();
byte[] subnetBytes = ipInfo.IPv4Mask.GetAddressBytes(); byte[] subnetBytes = ipInfo.IPv4Mask.GetAddressBytes();
byte[] broadcastBytes = new byte[myIPBytes.Length]; byte[] broadcastBytes = new byte[myIPBytes.Length];

View File

@@ -1,9 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<MyType>Windows</MyType> <TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net8.0-windows</TargetFrameworks>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>

View File

@@ -1,18 +1,13 @@
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
namespace Pilz.Networking; namespace Pilz.Net;
public class TCPManager : ConnectionManagerBase public class TCPManager(int port) : ConnectionManagerBase(port)
{ {
private readonly TcpListener listener; private readonly TcpListener listener = new TcpListener(IPAddress.Any, port);
public int BufferSize { get; set; } = 10240; public int BufferSize { get; set; } = 10240;
public TCPManager(int port) : base(port)
{
listener = new TcpListener(IPAddress.Any, port);
}
public override void Start() public override void Start()
{ {
if (!IsListening) if (!IsListening)
@@ -44,7 +39,7 @@ public class TCPManager : ConnectionManagerBase
if (listener.Pending()) if (listener.Pending())
{ {
var tcp = listener.AcceptTcpClient(); var tcp = listener.AcceptTcpClient();
string ip = ((IPEndPoint)tcp.Client.RemoteEndPoint).Address.ToString(); string ip = ((IPEndPoint)tcp.Client.RemoteEndPoint!).Address.ToString();
var Stream = tcp.GetStream(); var Stream = tcp.GetStream();
byte[] buf = new byte[BufferSize]; byte[] buf = new byte[BufferSize];

View File

@@ -1,12 +1,12 @@
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
namespace Pilz.Networking; namespace Pilz.Net;
public class UDPManager : ConnectionManagerBase public class UDPManager : ConnectionManagerBase
{ {
private readonly UdpClient client; private readonly UdpClient client;
private Task listenTask = null; private Task? listenTask = null;
private readonly CancellationTokenSource cancelTokenSource = new(); private readonly CancellationTokenSource cancelTokenSource = new();
private readonly CancellationToken cancelToken; private readonly CancellationToken cancelToken;
public int MaxBufferSize { get; private set; } = 8192; public int MaxBufferSize { get; private set; } = 8192;
@@ -43,7 +43,7 @@ public class UDPManager : ConnectionManagerBase
{ {
IsListening = false; IsListening = false;
cancelTokenSource.Cancel(); cancelTokenSource.Cancel();
listenTask.Wait(); listenTask?.Wait();
} }
} }

View File

@@ -1,7 +0,0 @@
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model;
public enum RetentionTimeAfter
{
CreationDate,
LastAccess
}

View File

@@ -1,9 +0,0 @@
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model;
public enum RetentionTimeUnit
{
Day,
Week,
Month,
Year
}

View File

@@ -1,7 +0,0 @@
using Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs;
public class OcsResponseRetention : OcsResponse<OcsResponseDataArray<OcsResponseDataEntryRetention>>
{
}

View File

@@ -1,8 +0,0 @@
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public enum ColumnSubtype
{
None,
Unknown,
Line
}

View File

@@ -1,9 +0,0 @@
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public enum ColumnType
{
Unknown,
Text,
Selection,
DateTime
}

View File

@@ -1,5 +0,0 @@
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public class Columns : List<Column>
{
}

View File

@@ -1,5 +0,0 @@
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public class RowSimple : List<object>
{
}

View File

@@ -1,5 +0,0 @@
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public class Rows : List<Row>
{
}

View File

@@ -1,5 +0,0 @@
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public class RowsSimple : List<RowSimple>
{
}

View File

@@ -1,7 +0,0 @@
using Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Ocs;
public class OcsResponseUser : OcsResponse<OcsResponseDataUser>
{
}

View File

@@ -1,5 +0,0 @@
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs;
public class OcsData
{
}

View File

@@ -1,5 +0,0 @@
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
public interface IOcsResponse
{
}

View File

@@ -1,5 +0,0 @@
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
public interface IOcsResponseData
{
}

View File

@@ -1,5 +0,0 @@
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
public interface IOcsResponseMeta
{
}

View File

@@ -1,5 +0,0 @@
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
public class OcsResponseData : IOcsResponseData
{
}

View File

@@ -1,5 +0,0 @@
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
public class OcsResponseDataEntry
{
}

View File

@@ -1,14 +0,0 @@
namespace Pilz.Networking.Api;
public abstract class ApiMessage
{
internal protected virtual string? Serialize(ApiMessage message)
{
}
internal protected virtual ApiMessage? Deserialize(string json)
{
}
}

View File

@@ -1,7 +0,0 @@
namespace Pilz.Networking.Api;
public interface IApiServer : IApiClient
{
void RegisterHandler<T>(T instance) where T : class;
void RegisterHandler(Delegate handler);
}

View File

@@ -1,8 +0,0 @@
namespace Pilz.Networking.Api;
[AttributeUsage(AttributeTargets.Method)]
public class MessageHandlerAttribute(string url) : Attribute
{
public string Url { get; set; } = url;
public Type? Serializer { get; set; }
}

View File

@@ -25,13 +25,13 @@ Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "Pilz.Simple3DFileParser", "
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.LicenseHelper", "Pilz.LicenseHelper\Pilz.LicenseHelper.csproj", "{67593FF7-C1D1-4529-98C4-61CBD0615F08}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.LicenseHelper", "Pilz.LicenseHelper\Pilz.LicenseHelper.csproj", "{67593FF7-C1D1-4529-98C4-61CBD0615F08}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Networking", "Pilz.Networking\Pilz.Networking.csproj", "{F7A0304A-C59E-0F5D-06C3-B43F63B2DBC6}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Net", "Pilz.Net\Pilz.Net.csproj", "{F7A0304A-C59E-0F5D-06C3-B43F63B2DBC6}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Cryptography", "Pilz.Cryptography\Pilz.Cryptography.csproj", "{3F5988E6-439E-4A9D-B2C6-47EFFB161AC6}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Cryptography", "Pilz.Cryptography\Pilz.Cryptography.csproj", "{3F5988E6-439E-4A9D-B2C6-47EFFB161AC6}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.UI.Telerik", "Pilz.UI.Telerik\Pilz.UI.Telerik.csproj", "{DF674119-CC28-40AA-968F-1E23D184A491}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.UI.Telerik", "Pilz.UI.Telerik\Pilz.UI.Telerik.csproj", "{DF674119-CC28-40AA-968F-1E23D184A491}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Networking.CloudProviders.Nextcloud", "Pilz.Networking.CloudProviders.Nextcloud\Pilz.Networking.CloudProviders.Nextcloud.csproj", "{A91E966B-3A82-4F32-A703-2FC1C7654FD1}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Net.CloudProviders.Nextcloud", "Pilz.Net.CloudProviders.Nextcloud\Pilz.Net.CloudProviders.Nextcloud.csproj", "{A91E966B-3A82-4F32-A703-2FC1C7654FD1}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Plugins", "Pilz.Plugins\Pilz.Plugins.csproj", "{1170FCA6-192D-42FE-A79F-49EE03035554}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Plugins", "Pilz.Plugins\Pilz.Plugins.csproj", "{1170FCA6-192D-42FE-A79F-49EE03035554}"
EndProject EndProject