Compare commits

..

8 Commits

Author SHA1 Message Date
Developer 02
39e78821cf feat: Dokumenterstellungs-Methoden zu DocumentsRouteService hinzugefügt und Modelle aktualisiert
- Zwei `Create`-Methoden in `DocumentsRouteService` hinzugefügt, um die Dokumentenerstellung über HTTP-POST-Anfragen zu ermöglichen.
- `int`-Felder im `DocCreateBody`-Modell in `int?` umgewandelt, um mögliche Nullwerte vom Server zu berücksichtigen.
- Die neue Dokumenterstellungsfunktion in WindreamClientService integriert.
2024-09-13 00:40:06 +02:00
Developer 02
152b4f7cff feat: Modelle für die Antwort auf die Dokumentenerstellung in DocumentsRouteService hinzugefügt 2024-09-12 22:05:59 +02:00
Developer 02
987cecba4c feat: Modelle für Dokumentenerstellungsanfragen in DocumentsRouteService hinzugefügt
- `Attribute`, `DocumentCreationBody`, `Item` und `ObjectType` Modelle für die Dokumentenerstellungsanfrage hinzugefügt.
- Diese Modelle werden zur Erstellung von Dokumentenanfragen mit spezifischen Attributen und Details verwendet.
2024-09-12 21:38:41 +02:00
Developer 02
dcaf510bd3 refactor: SystemDetails-Response-Modelle in den SystemDetails-Ordner verschoben 2024-09-12 21:08:45 +02:00
Developer 02
71f0919bce feat: DocumentsRouteService initialisiert und in WindreamClientService integriert
- `DocumentsRouteService`-Klasse hinzugefügt, um dokumentbezogene Routen zu verwalten, basierend auf `BaseRouteService`.
- `DocumentsRouteService` in `WindreamClientService` für Dokumentoperationen integriert.
- `DocumentsRouteService` als Singleton im Service-Container registriert mit `AddSingleton`.
2024-09-12 20:59:55 +02:00
Developer 02
5062930d5b feat: Benutzer-Authentifizierungsmethoden und Validierungslogik hinzugefügt
- `IsValidUser`-Methode in `AuthenticationRouteService` hinzugefügt, um Benutzer über die `/IsValidUser`-Route zu validieren.
- Drei neue `AuthenticateAsync`-Methoden in `WindreamClientService` implementiert, um verschiedene Benutzerauthentifizierungen zu unterstützen (ICredential, Domain/Name/Passwort und Base64-Authorization-Header).
- HttpClient aktualisiert, um Authorization-Header für die Authentifizierung hinzuzufügen.
2024-09-12 20:20:49 +02:00
Developer 02
c233ab0ed7 feat: AuthenticationRouteService zum WindreamHub-Client hinzugefügt
- `AuthenticationRouteService`-Klasse zur Verwaltung von Authentifizierungsrouten erstellt.
- `AuthenticationRouteService` im DI-Container mit `AddSingleton<AuthenticationRouteService>()` registriert.
- `AuthenticationRouteService` zum `WindreamClientService` hinzugefügt, um die Authentifizierung im Hauptdienst zu verwalten.
2024-09-12 02:09:13 +02:00
Developer 02
0346af5b29 feat: Füge UserCredential-Klasse für die Windream-API-Integration hinzu
- UserCredential-Klasse erstellt, um Benutzerdaten für die Windream-API zu verwalten.
- Konstruktor implementiert, um Domain, Name und Passwort zu initialisieren.
- ConvertToBase64-Methode hinzugefügt, um Anmeldeinformationen für den Autorisierungsheader zu kodieren.
2024-09-11 16:43:57 +02:00
32 changed files with 345 additions and 19 deletions

View File

@@ -1,6 +1,7 @@
using DigitalData.Core.Legacy.Client;
using Microsoft.Extensions.DependencyInjection;
using WindreamHub.Legacy.Client.Route;
using WindreamHub.Legacy.Client.Routes;
namespace WindreamHub.Legacy.Client
{
@@ -15,7 +16,9 @@ namespace WindreamHub.Legacy.Client
})
.AddSingleton<WindreamClientService>()
.AddSingleton<SubscriptionsRouteService>()
.AddSingleton<SystemDetailsRouteService>();
.AddSingleton<SystemDetailsRouteService>()
.AddSingleton<AuthenticationRouteService>()
.AddSingleton<DocumentsRouteService>();
return services;
}

View File

@@ -0,0 +1,9 @@
namespace WindreamHub.Legacy.Client.Models.Authentication
{
public class Base64Credential : ICredential
{
public Base64Credential(string authorizationHeader) => AuthorizationHeader = authorizationHeader;
public string AuthorizationHeader { get; }
}
}

View File

@@ -0,0 +1,11 @@
using WindreamHub.Legacy.Client.Models.Shared;
namespace WindreamHub.Legacy.Client.Models.Authentication
{
public class ErrorDetails
{
public ErrorItem Item { get; set; }
public string Message { get; set; }
public int? ErrorCode { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
namespace WindreamHub.Legacy.Client.Models.Authentication
{
public interface ICredential
{
string AuthorizationHeader { get; }
}
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Text;
using WindreamHub.Legacy.Client.Models.Authentication;
namespace WindreamHub.Legacy.Client.Models
{
public class UserCredential : ICredential
{
public readonly string Domain;
public readonly string Name;
public string AuthorizationHeader { get; }
public UserCredential(string domain, string name, string password)
{
Domain = domain;
Name = name;
AuthorizationHeader = ConvertToBase64(domain, name, password);
}
private static string ConvertToBase64(string domain, string username, string password)
{
var credentials = $"{domain}\\{username}:{password}";
var base64Credentials = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(credentials));
return base64Credentials;
}
}
}

View File

@@ -0,0 +1,15 @@
using System.Collections.Generic;
namespace WindreamHub.Legacy.Client.Models.Authentication
{
public class ValidationResponse
{
public int? UserID { get; set; }
public string UserName { get; set; }
public string FullUserName { get; set; }
public bool IsValidUser { get; set; }
public ErrorDetails Error { get; set; }
public List<ErrorDetails> Errors { get; set; }
public bool HasErrors { get; set; }
}
}

View File

@@ -0,0 +1,8 @@
namespace WindreamHub.Legacy.Client.Models.Documents.Request
{
public class Attribute
{
public string Name { get; set; }
public object Value { get; set; }
}
}

View File

@@ -0,0 +1,9 @@
namespace WindreamHub.Legacy.Client.Models.Documents.Request
{
public class DocCreateBody
{
public Item Item { get; set; }
public bool CreateFolder { get; set; }
public int? ResponseDetails { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
namespace WindreamHub.Legacy.Client.Models.Documents.Request
{
public class Item
{
public ObjectType ObjectType { get; set; }
public List<Attribute> Attributes { get; set; }
public string Location { get; set; }
public string Name { get; set; }
}
}

View File

@@ -0,0 +1,8 @@
namespace WindreamHub.Legacy.Client.Models.Documents.Request
{
public class ObjectType
{
public int? Id { get; set; }
public string Name { get; set; }
}
}

View File

@@ -0,0 +1,21 @@
namespace WindreamHub.Legacy.Client.Models.Documents.Response
{
public class Attribute
{
public string Name { get; set; }
public string DisplayName { get; set; }
public object Value { get; set; }
public int? Type { get; set; }
public int? UnderlyingType { get; set; }
public string Column { get; set; }
public bool IsSystem { get; set; }
public bool IsSortable { get; set; }
public VectorDetails VectorDetails { get; set; }
public TypeSpecificDetails TypeSpecificDetails { get; set; }
public int? MaxSize { get; set; }
public bool AlwaysModifiable { get; set; }
public int? PreDigits { get; set; }
public int? PostDigits { get; set; }
public bool IsFulltext { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using System.Collections.Generic;
namespace WindreamHub.Legacy.Client.Models.Documents.Response
{
public class DocCreatResponse
{
public Item Item { get; set; }
public IndexingDetails IndexingDetails { get; set; }
public Error Error { get; set; }
public List<Error> Errors { get; set; }
public bool HasErrors { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
using WindreamHub.Legacy.Client.Models.Shared;
namespace WindreamHub.Legacy.Client.Models.Documents.Response
{
public class Error
{
public ErrorItem Item { get; set; }
public string Message { get; set; }
public int? ErrorCode { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
namespace WindreamHub.Legacy.Client.Models.Documents.Response
{
public class IndexingDetails
{
public bool IndexEventRequired { get; set; }
}
}

View File

@@ -0,0 +1,16 @@
using System.Collections.Generic;
namespace WindreamHub.Legacy.Client.Models.Documents.Response
{
public class Item
{
public List<Attribute> Attributes { get; set; }
public ObjectType ObjectType { get; set; }
public ParentWindreamObject ParentWindreamObject { get; set; }
public int? Entity { get; set; }
public string LocationComplete { get; set; }
public int? Id { get; set; }
public string Location { get; set; }
public string Name { get; set; }
}
}

View File

@@ -0,0 +1,8 @@
namespace WindreamHub.Legacy.Client.Models.Documents.Response
{
public class ObjectType
{
public int? Id { get; set; }
public string Name { get; set; }
}
}

View File

@@ -0,0 +1,10 @@
namespace WindreamHub.Legacy.Client.Models.Documents.Response
{
public class ParentWindreamObject
{
public string LocationComplete { get; set; }
public int? Id { get; set; }
public string Location { get; set; }
public string Name { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
namespace WindreamHub.Legacy.Client.Models.Documents.Response
{
public class TypeSpecificDetails
{
public bool OnceEditable { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
namespace WindreamHub.Legacy.Client.Models.Documents.Response
{
public class VectorDetails
{
public int? EntriesLimit { get; set; }
}
}

View File

@@ -3,6 +3,8 @@ using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Text;
namespace WindreamHub.Legacy.Client.Models
{
@@ -89,5 +91,13 @@ namespace WindreamHub.Legacy.Client.Models
error?.Invoke(res.Error);
});
}
public static string Serialize(this object model) => JsonConvert.SerializeObject(model);
public static HttpContent ToContent(this string json, Encoding encoding = null, string mediaType = "application/json")
=> new StringContent(json, encoding ?? Encoding.UTF8, mediaType);
public static HttpContent Stringify(this object model, Encoding encoding = null, string mediaType = "application/json")
=> model.Serialize().ToContent(encoding ?? Encoding.UTF8, mediaType);
}
}

View File

@@ -0,0 +1,10 @@
namespace WindreamHub.Legacy.Client.Models.Shared
{
public class ErrorItem
{
public int? Entity { get; set; }
public int? Id { get; set; }
public string Location { get; set; }
public string Name { get; set; }
}
}

View File

@@ -1,4 +1,4 @@
namespace WindreamHub.Legacy.Client.Models
namespace WindreamHub.Legacy.Client.Models.SystemDetails
{
public class SystemDetails
{
@@ -8,6 +8,6 @@
public string DefaultDomain { get; set; }
public int AuthenticationModes { get; set; }
public int? AuthenticationModes { get; set; }
}
}

View File

@@ -1,4 +1,4 @@
namespace WindreamHub.Legacy.Client.Models
namespace WindreamHub.Legacy.Client.Models.SystemDetails
{
public class SystemDetailsResponse
{

View File

@@ -0,0 +1,22 @@
using DigitalData.Core.Legacy.Client;
using Microsoft.Extensions.Options;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using WindreamHub.Legacy.Client.Models;
using WindreamHub.Legacy.Client.Models.Authentication;
namespace WindreamHub.Legacy.Client.Routes
{
public class AuthenticationRouteService : BaseRouteService
{
public AuthenticationRouteService(HttpClient client, CookieContainer cookieContainer, IOptions<WindreamClientOptions> clientOptions) : base(client, cookieContainer, clientOptions)
{
}
public async Task<SimplifiedResponse<ValidationResponse, object>> IsValidUser()
{
return await FetchAsync(route: "/IsValidUser", HttpMethod.Get).ThenAsync(res => res.Simplify<ValidationResponse, object>());
}
}
}

View File

@@ -1,6 +1,5 @@
using DigitalData.Core.Legacy.Client;
using Microsoft.Extensions.Options;
using System;
using System.Net;
using System.Net.Http;
@@ -15,8 +14,8 @@ namespace WindreamHub.Legacy.Client.Routes
clientOptions.Value.Routes.TryGetValue(route_name, out string route);
if(route is null)
throw new InvalidOperationException($"Route not found for the route name: {route_name}.");
if (route is null)
Uri += $"/{route_name.ToLower()}";
Uri += route;
}

View File

@@ -0,0 +1,26 @@
using Microsoft.Extensions.Options;
using System.Net;
using System.Net.Http;
using DigitalData.Core.Legacy.Client;
using System.Threading.Tasks;
using WindreamHub.Legacy.Client.Models;
using WindreamHub.Legacy.Client.Models.Documents.Response;
using WindreamHub.Legacy.Client.Models.Documents.Request;
namespace WindreamHub.Legacy.Client.Routes
{
public class DocumentsRouteService : BaseRouteService
{
public DocumentsRouteService(HttpClient client, CookieContainer cookieContainer, IOptions<WindreamClientOptions> clientOptions) : base(client, cookieContainer, clientOptions)
{
}
public async Task<SimplifiedResponse<DocCreatResponse, object>> Create(HttpContent docCreateBody)
=> await FetchAsync(route: "/Create", method: HttpMethod.Post, body: docCreateBody)
.ThenAsync(res => res.Simplify<DocCreatResponse, object>());
public async Task<SimplifiedResponse<DocCreatResponse, object>> Create(DocCreateBody docCreateBody)
=> await FetchAsync(route: "/Create", method: HttpMethod.Post, body: docCreateBody.Stringify())
.ThenAsync(res => res.Simplify<DocCreatResponse, object>());
}
}

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WindreamHub.Legacy.Client.Routes
{

View File

@@ -1,6 +1,4 @@
using DigitalData.Core.Legacy.Client;
using Microsoft.Extensions.Options;
using System;
using Microsoft.Extensions.Options;
using System.Net;
using System.Net.Http;
using WindreamHub.Legacy.Client.Routes;

View File

@@ -4,6 +4,7 @@ using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using WindreamHub.Legacy.Client.Models;
using WindreamHub.Legacy.Client.Models.SystemDetails;
using WindreamHub.Legacy.Client.Routes;
namespace WindreamHub.Legacy.Client.Route

View File

@@ -8,7 +8,8 @@ namespace WindreamHub.Legacy.Client
public Dictionary<string, string> Routes = new Dictionary<string, string>()
{
{ "Subscriptions", "/subscriptions" },
{ "SystemDetails", "/systemDetails" }
{ "SystemDetails", "/systemDetails" },
{ "Authentication", "/authentication" }
};
}
}

View File

@@ -2,22 +2,51 @@
using Microsoft.Extensions.Options;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using WindreamHub.Legacy.Client.Models.Authentication;
using WindreamHub.Legacy.Client.Models;
using WindreamHub.Legacy.Client.Route;
using WindreamHub.Legacy.Client.Routes;
namespace WindreamHub.Legacy.Client
{
public class WindreamClientService : HttpClientService<WindreamClientOptions>
{
public WindreamClientService(SubscriptionsRouteService subscriptions, SystemDetailsRouteService systemDetails,
HttpClient client, CookieContainer cookieContainer, IOptions<WindreamClientOptions> clientOptions) :
public WindreamClientService(SubscriptionsRouteService subscriptions, SystemDetailsRouteService systemDetails, AuthenticationRouteService authentication, DocumentsRouteService documents, HttpClient client, CookieContainer cookieContainer, IOptions<WindreamClientOptions> clientOptions) :
base(client, cookieContainer, clientOptions)
{
Subscriptions = subscriptions;
SystemDetails = systemDetails;
Authentication = authentication;
Documents = documents;
}
public SubscriptionsRouteService Subscriptions { get; }
public SystemDetailsRouteService SystemDetails { get; }
public AuthenticationRouteService Authentication { get; }
public DocumentsRouteService Documents { get; }
public async Task<bool> AuthenticateAsync(ICredential credential)
{
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credential.AuthorizationHeader);
var res = await Authentication.IsValidUser();
return res.Ok && res.Data.IsValidUser;
}
public async Task<bool> AuthenticateAsync(string domain, string name, string password)
{
var uCredential = new UserCredential(domain, name, password);
return await AuthenticateAsync(uCredential);
}
public async Task<bool> AuthenticateAsync(string authorizationHeader)
{
var uCredential = new Base64Credential(authorizationHeader);
return await AuthenticateAsync(uCredential);
}
}
}

View File

@@ -83,11 +83,32 @@
</ItemGroup>
<ItemGroup>
<Compile Include="DIExtensions.cs" />
<Compile Include="Models\Authentication\ErrorDetails.cs" />
<Compile Include="Models\Documents\Response\Error.cs" />
<Compile Include="Models\Shared\ErrorItem.cs" />
<Compile Include="Models\Authentication\ICredential.cs" />
<Compile Include="Models\Authentication\ValidationResponse.cs" />
<Compile Include="Models\Authentication\Base64Credential.cs" />
<Compile Include="Models\Documents\Request\Attribute.cs" />
<Compile Include="Models\Documents\Request\Item.cs" />
<Compile Include="Models\Documents\Request\ObjectType.cs" />
<Compile Include="Models\Documents\Request\DocCreateBody.cs" />
<Compile Include="Models\Documents\Response\Attribute.cs" />
<Compile Include="Models\Documents\Response\DocCreatResponse.cs" />
<Compile Include="Models\Documents\Response\IndexingDetails.cs" />
<Compile Include="Models\Documents\Response\Item.cs" />
<Compile Include="Models\Documents\Response\ObjectType.cs" />
<Compile Include="Models\Documents\Response\ParentWindreamObject.cs" />
<Compile Include="Models\Documents\Response\TypeSpecificDetails.cs" />
<Compile Include="Models\Documents\Response\VectorDetails.cs" />
<Compile Include="Models\ModelExtensions.cs" />
<Compile Include="Models\SimplifiedResponse.cs" />
<Compile Include="Models\SystemDetails.cs" />
<Compile Include="Models\SystemDetailsResponse.cs" />
<Compile Include="Models\SystemDetails\SystemDetails.cs" />
<Compile Include="Models\SystemDetails\SystemDetailsResponse.cs" />
<Compile Include="Models\Authentication\UserCredential.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Routes\DocumentsRouteService.cs" />
<Compile Include="Routes\AuthenticationRouteService.cs" />
<Compile Include="Routes\BaseRouteService.cs" />
<Compile Include="Routes\RouteExtensions.cs" />
<Compile Include="Routes\SystemDetailsRouteService.cs" />
@@ -104,5 +125,6 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>