refactor (networking)

This commit is contained in:
Kevin Kai Berthold 2023-09-21 22:10:55 +02:00
parent febc4d9488
commit 450a6f2796
153 changed files with 7834 additions and 8004 deletions

View file

@ -20,7 +20,7 @@ public static class Navigation
public const string Logout = "account/logout";
public const string Lockout = "account/lockout";
public const string Profile = "account/profile";
public const string ChangePassword = "account/changepassword";
public const string ChangePassword = "account/changepassword";
public static string LoginHref(string redirect)
{
@ -106,7 +106,7 @@ public static class Navigation
{
public const string Index = "management/accounts";
public const string Details = "management/accounts/{accountId}";
public static string DetailsHref(string? accountId)
{
return Details.Replace("{accountId}", accountId);

View file

@ -4,7 +4,7 @@
<TargetFramework>net7.0</TargetFramework>
<Product>Insight</Product>
<AssemblyName>web</AssemblyName>
<AssemblyVersion>2023.9.18.0</AssemblyVersion>
<AssemblyVersion>2023.9.21.1</AssemblyVersion>
<RootNamespace>Insight.Web</RootNamespace>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
@ -42,9 +42,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Agent\Insight.Agent.Assets\Insight.Agent.Assets.csproj" />
<ProjectReference Include="..\..\Core\Insight.Infrastructure\Insight.Infrastructure.csproj" />
<ProjectReference Include="..\Insight.Web.Assets\Insight.Web.Assets.csproj" />
</ItemGroup>
<ItemGroup>

View file

@ -1,6 +1,4 @@
using System.ComponentModel.DataAnnotations;
namespace Insight.Web.Models.Account;
namespace Insight.Web.Models.Account;
public class LoginModel
{

View file

@ -1,24 +1,24 @@
using Insight.Web.Interfaces;
using Insight.Web.Messages;
using Insight.Domain.Interfaces;
using Insight.Domain.Messages;
using Insight.Domain.Messages.Web;
using Vaitr.Bus;
namespace Insight.Web.Network.Handlers
namespace Insight.Web.Network.Handlers;
public class ConsoleHandler : IMessageHandler<WebSession>
{
public class ConsoleHandler : IWebMessageHandler<WebSession>
private readonly Bus _bus;
public ConsoleHandler(Bus bus)
{
private readonly Bus _bus;
_bus = bus;
}
public ConsoleHandler(Bus bus)
public async ValueTask HandleAsync<TMessage>(WebSession sender, TMessage message, CancellationToken cancellationToken) where TMessage : IMessage
{
if (message is ConsoleQueryProxy consoleQuery)
{
_bus = bus;
}
public async ValueTask HandleAsync<TMessage>(WebSession sender, TMessage message, CancellationToken cancellationToken) where TMessage : IWebMessage
{
if (message is ConsoleQueryProxy consoleQuery)
{
await _bus.PublishAsync(consoleQuery, cancellationToken);
}
await _bus.PublishAsync(consoleQuery, cancellationToken);
}
}
}

View file

@ -1,56 +1,55 @@
using Insight.Web.Interfaces;
using Insight.Web.Messages;
using Insight.Domain.Interfaces;
using Insight.Domain.Messages;
using Vaitr.Network;
namespace Insight.Web.Network
namespace Insight.Web.Network;
public class WebSession : TcpSession<IMessage>
{
public class WebSession : TcpSession<IWebMessage>
private readonly IEnumerable<IMessageHandler<WebSession>> _handlers;
public WebSession(IEnumerable<IMessageHandler<WebSession>> handlers, ISerializer<IMessage> serializer, ILogger<WebSession> logger) : base(serializer, logger)
{
private readonly IEnumerable<IWebMessageHandler<WebSession>> _handlers;
_handlers = handlers;
}
public WebSession(IEnumerable<IWebMessageHandler<WebSession>> handlers, ISerializer<IWebMessage> serializer, ILogger<WebSession> logger) : base(serializer, logger)
protected override ValueTask OnConnectedAsync(CancellationToken cancellationToken)
{
_logger.LogInformation("Web ({ep?}) connected", RemoteEndPoint);
return default;
}
protected override ValueTask OnDisconnectedAsync(CancellationToken cancellationToken)
{
_logger.LogInformation("Web ({ep?}) disconnected", RemoteEndPoint);
return default;
}
protected override ValueTask OnSentAsync(IPacketContext<IMessage> context, CancellationToken cancellationToken)
{
return base.OnSentAsync(context, cancellationToken);
}
protected override async ValueTask OnReceivedAsync(IPacketContext<IMessage> context, CancellationToken cancellationToken)
{
await base.OnReceivedAsync(context, cancellationToken);
foreach (var handler in _handlers)
{
_handlers = handlers;
}
protected override ValueTask OnConnectedAsync(CancellationToken cancellationToken)
{
_logger.LogInformation("Web ({ep?}) connected", RemoteEndPoint);
return default;
}
protected override ValueTask OnDisconnectedAsync(CancellationToken cancellationToken)
{
_logger.LogInformation("Web ({ep?}) disconnected", RemoteEndPoint);
return default;
}
protected override ValueTask OnSentAsync(IPacketContext<IWebMessage> context, CancellationToken cancellationToken)
{
return base.OnSentAsync(context, cancellationToken);
}
protected override async ValueTask OnReceivedAsync(IPacketContext<IWebMessage> context, CancellationToken cancellationToken)
{
await base.OnReceivedAsync(context, cancellationToken);
foreach (var handler in _handlers)
try
{
try
{
await handler.HandleAsync(this, context.Packet, cancellationToken);
}
catch (Exception ex)
{
_logger.LogWarning("Web ({ep?}) {ex}", RemoteEndPoint, ex.ToString());
}
await handler.HandleAsync(this, context.Packet, cancellationToken);
}
catch (Exception ex)
{
_logger.LogWarning("Web ({ep?}) {ex}", RemoteEndPoint, ex.ToString());
}
}
}
protected override ValueTask OnHeartbeatAsync(CancellationToken cancellationToken)
{
_logger.LogInformation("Web ({ep?}) Heartbeat", RemoteEndPoint);
return default;
}
protected override ValueTask OnHeartbeatAsync(CancellationToken cancellationToken)
{
_logger.LogInformation("Web ({ep?}) Heartbeat", RemoteEndPoint);
return default;
}
}

View file

@ -1,4 +1,4 @@
@using static Insight.Agent.Messages.StoragePool;
@using static Insight.Domain.Messages.Agent.StoragePool;
@inherits ComponentBase
<TableContainer T="ViewModel"

View file

@ -1,4 +1,4 @@
@using static Insight.Agent.Messages.Update;
@using static Insight.Domain.Messages.Agent.Update;
@inherits ComponentBase
<TableContainer T="ViewModel"

View file

@ -1,4 +1,4 @@
@using static Insight.Agent.Messages.VirtualMaschine;
@using static Insight.Domain.Messages.Agent.VirtualMaschine;
@inherits ComponentBase
<TableContainer T="ViewModel"

View file

@ -1,5 +1,5 @@
@inherits ComponentBase
@using Insight.Agent.Enums;
@using Insight.Domain.Enums;
<TableContainer T="AgentLogEntity"
@ref="Container"
@ -48,11 +48,11 @@
if (context?.Status is not null)
{
color = Enum.Parse<Insight.Agent.Enums.StatusEnum>(context.Status, true) switch
color = Enum.Parse<Insight.Domain.Enums.StatusEnum>(context.Status, true) switch
{
Insight.Agent.Enums.StatusEnum.Information => Color.Success,
Insight.Agent.Enums.StatusEnum.Warning => Color.Warning,
Insight.Agent.Enums.StatusEnum.Error => Color.Error,
Insight.Domain.Enums.StatusEnum.Information => Color.Success,
Insight.Domain.Enums.StatusEnum.Warning => Color.Warning,
Insight.Domain.Enums.StatusEnum.Error => Color.Error,
_ => Color.Inherit
};
}

View file

@ -1,4 +1,4 @@
using Insight.Agent.Enums;
using Insight.Domain.Enums;
using Insight.Infrastructure;
using Insight.Infrastructure.Entities;
using Insight.Web.Components.Containers;

View file

@ -1,7 +1,8 @@
using Insight.Infrastructure;
using Insight.Domain.Messages;
using Insight.Domain.Messages.Web;
using Insight.Infrastructure;
using Insight.Infrastructure.Entities;
using Insight.Web.Constants;
using Insight.Web.Messages;
using Insight.Web.Network;
using Microsoft.AspNetCore.Components;
using MongoDB.Bson;
@ -17,7 +18,7 @@ public partial class Index
{
[Parameter] public string? HostId { get; set; }
[Inject] private ISessionPool<WebSession, IWebMessage> WebPool { get; init; } = default!;
[Inject] private ISessionPool<WebSession, IMessage> WebPool { get; init; } = default!;
[Inject] private IMongoDatabase Database { get; init; } = default!;
[Inject] private ISnackbar Snackbar { get; init; } = default!;
[Inject] private Bus Bus { get; init; } = default!;

View file

@ -1,5 +1,5 @@
@inherits ComponentBase
@using Insight.Agent.Enums;
@using Insight.Domain.Enums;
<TableContainer T="HostLogEntity"
@ref="Container"
@ -55,11 +55,11 @@
if (context?.Status is not null)
{
color = Enum.Parse<Insight.Agent.Enums.StatusEnum>(context.Status, true) switch
color = Enum.Parse<Insight.Domain.Enums.StatusEnum>(context.Status, true) switch
{
Insight.Agent.Enums.StatusEnum.Information => Color.Success,
Insight.Agent.Enums.StatusEnum.Warning => Color.Warning,
Insight.Agent.Enums.StatusEnum.Error => Color.Error,
Insight.Domain.Enums.StatusEnum.Information => Color.Success,
Insight.Domain.Enums.StatusEnum.Warning => Color.Warning,
Insight.Domain.Enums.StatusEnum.Error => Color.Error,
_ => Color.Inherit
};
}

View file

@ -1,4 +1,4 @@
using Insight.Agent.Enums;
using Insight.Domain.Enums;
using Insight.Infrastructure;
using Insight.Infrastructure.Entities;
using Insight.Web.Components.Containers;

View file

@ -1,4 +1,4 @@
@using static Insight.Agent.Messages.StoragePool;
@using static Insight.Domain.Messages.Agent.StoragePool;
@inherits ComponentBase
<BaseContainer Title="@Title" Breadcrumbs="@Breadcrumbs" LoadData="LoadDataAsync">

View file

@ -1,4 +1,4 @@
@using static Insight.Agent.Messages.StoragePool;
@using static Insight.Domain.Messages.Agent.StoragePool;
@inherits ComponentBase
<TableContainer T="HostStoragePoolEntity"

View file

@ -1,4 +1,4 @@
@using static Insight.Agent.Messages.PhysicalDisk;
@using static Insight.Domain.Messages.Agent.PhysicalDisk;
@inherits ComponentBase
<BaseContainer Title="@Title" Breadcrumbs="@Breadcrumbs" LoadData="LoadDataAsync">

View file

@ -1,4 +1,4 @@
@using static Insight.Agent.Messages.PhysicalDisk;
@using static Insight.Domain.Messages.Agent.PhysicalDisk;
@inherits ComponentBase
<TableContainer T="HostStoragePoolPhysicalDiskEntity"

View file

@ -1,4 +1,4 @@
@using static Insight.Agent.Messages.VirtualDisk;
@using static Insight.Domain.Messages.Agent.VirtualDisk;
@inherits ComponentBase
<BaseContainer Title="@Title" Breadcrumbs="@Breadcrumbs" LoadData="LoadDataAsync">

View file

@ -1,4 +1,4 @@
@using static Insight.Agent.Messages.VirtualDisk;
@using static Insight.Domain.Messages.Agent.VirtualDisk;
@inherits ComponentBase
<TableContainer T="HostStoragePoolVirtualDiskEntity"

View file

@ -1,4 +1,4 @@
@using static Insight.Agent.Messages.Update;
@using static Insight.Domain.Messages.Agent.Update;
@inherits ComponentBase
<TableContainer T="HostUpdateEntity"

View file

@ -1,7 +1,7 @@
@inherits ComponentBase
@using Insight.Web.Pages.Management.Hosts.Systems.VirtualMaschines.Snapshots
@using Microsoft.AspNetCore.Components.Rendering
@using static Insight.Agent.Messages.VirtualMaschine;
@using static Insight.Domain.Messages.Agent.VirtualMaschine;
<BaseContainer Title="@Title" Breadcrumbs="@Breadcrumbs" LoadData="LoadDataAsync">
<Content>

View file

@ -1,4 +1,4 @@
@using static Insight.Agent.Messages.VirtualMaschine;
@using static Insight.Domain.Messages.Agent.VirtualMaschine;
@inherits ComponentBase
<TableContainer T="ViewModel"

View file

@ -1,5 +1,4 @@
using Insight.Agent.Messages;
using Insight.Infrastructure;
using Insight.Infrastructure;
using Insight.Infrastructure.Entities;
using Insight.Web.Constants;
using Microsoft.AspNetCore.Components;

View file

@ -1,4 +1,4 @@
@using static Insight.Agent.Messages.VirtualMaschine;
@using static Insight.Domain.Messages.Agent.VirtualMaschine;
@inherits ComponentBase
<TableContainer T="ViewModel"

View file

@ -1,8 +1,8 @@
using Insight.Domain.Constants;
using Insight.Domain.Interfaces;
using Insight.Domain.Messages;
using Insight.Infrastructure;
using Insight.Web.Hosting;
using Insight.Web.Interfaces;
using Insight.Web.Messages;
using Insight.Web.Middleware;
using Insight.Web.Network;
using Insight.Web.Network.Handlers;
@ -60,7 +60,7 @@ public class Program
});
// NETWORKING
builder.Services.UseHostedClient<WebSession, IWebMessage>(options =>
builder.Services.UseHostedClient<WebSession, IMessage>(options =>
{
options.Host = builder.Configuration.GetValue<string?>(Appsettings.ServerHost) ?? throw new Exception($"{Appsettings.ServerHost} value not set (appsettings)");
options.Port = builder.Configuration.GetValue<int?>(Appsettings.ServerPort) ?? throw new Exception($"{Appsettings.ServerPort} value not set (appsettings)");
@ -68,10 +68,10 @@ public class Program
options.Timeout = 30000;
options.Encryption = Encryption.Tls12;
options.UseSerializer<MemPackSerializer<IWebMessage>, IWebMessage>();
options.UseSerializer<MemPackSerializer<IMessage>, IMessage>();
});
builder.Services.AddSingleton<IWebMessageHandler<WebSession>, ConsoleHandler>();
builder.Services.AddSingleton<IMessageHandler<WebSession>, ConsoleHandler>();
// WEB:APP
var app = builder.Build();

View file

@ -25,6 +25,6 @@ public class ServiceHost : IHostedService
public async Task StopAsync(CancellationToken cancellationToken)
{
}
}

View file

@ -9,7 +9,7 @@ namespace Insight.Web.Services;
public class SessionHandler : CircuitHandler
{
public SessionState State { get; } = new();
private readonly ChatService _chatService;
private readonly SessionPool _sessionPool;
private readonly AuthenticationStateProvider _authenticationState;