2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-05-06 03:32:57 +00:00
This commit is contained in:
Ahmed Zamil 2024-10-09 05:26:51 +03:00
parent 5745887b48
commit c477a11f4b
10 changed files with 107 additions and 26 deletions

View File

@ -2,7 +2,7 @@ using Esiur.Core;
using Esiur.Resource; using Esiur.Resource;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace Esiur.ASPNet.Controllers namespace Esiur.AspNetCore.Example
{ {
[ApiController] [ApiController]
[Route("[controller]")] [Route("[controller]")]

View File

@ -11,6 +11,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Esiur.AspNetCore\Esiur.AspNetCore.csproj" />
<ProjectReference Include="..\Esiur\Esiur.csproj" OutputItemType="Analyzer" /> <ProjectReference Include="..\Esiur\Esiur.csproj" OutputItemType="Analyzer" />
</ItemGroup> </ItemGroup>

View File

@ -1,6 +1,6 @@
using Esiur.Resource; using Esiur.Resource;
namespace Esiur.ASPNet namespace Esiur.AspNetCore.Example
{ {
[Resource] [Resource]
public partial class MyResource public partial class MyResource

View File

@ -1,4 +1,5 @@
using Esiur.ASPNet; using Esiur.AspNetCore;
using Esiur.AspNetCore.Example;
using Esiur.Core; using Esiur.Core;
using Esiur.Net.IIP; using Esiur.Net.IIP;
using Esiur.Net.Sockets; using Esiur.Net.Sockets;
@ -50,26 +51,7 @@ var server = await Warehouse.Put("sys/server", new DistributedServer());
await Warehouse.Open(); await Warehouse.Open();
app.Use(async (context, next) => app.UseEsiur(new EsiurOptions() { Server = server });
{
var buffer = new ArraySegment<byte>(new byte[10240]);
if (context.WebSockets.IsWebSocketRequest)
{
var webSocket = await context.WebSockets.AcceptWebSocketAsync("iip");
var socket = new FrameworkWebSocket(webSocket);
var iipConnection = new DistributedConnection();
server.Add(iipConnection);
iipConnection.Assign(socket);
socket.Begin();
while (webSocket.State == WebSocketState.Open) ;
}
else
{
await next(context);
}
});
await app.RunAsync(); await app.RunAsync();

View File

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Esiur\Esiur.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,47 @@

using Esiur.Net.IIP;
using Esiur.Net.Sockets;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System.Net.WebSockets;
namespace Esiur.AspNetCore
{
public class EsiurMiddleware
{
readonly DistributedServer server;
readonly RequestDelegate next;
readonly ILoggerFactory loggerFactory;
public async Task InvokeAsync(HttpContext context)
{
var buffer = new ArraySegment<byte>(new byte[10240]);
if (context.WebSockets.IsWebSocketRequest)
{
var webSocket = await context.WebSockets.AcceptWebSocketAsync("iip");
var socket = new FrameworkWebSocket(webSocket);
var iipConnection = new DistributedConnection();
server.Add(iipConnection);
iipConnection.Assign(socket);
socket.Begin();
while (webSocket.State == WebSocketState.Open) ;
}
else
{
await next(context);
}
}
public EsiurMiddleware(RequestDelegate next, IOptions<EsiurOptions> options, ILoggerFactory loggerFactory)
{
this.server = options.Value.Server;
this.loggerFactory = loggerFactory;
this.next = next;
}
}
}

View File

@ -0,0 +1,17 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Options;
namespace Esiur.AspNetCore
{
public static class EsiurMiddlewareExtensions
{
public static IApplicationBuilder UseEsiur(this IApplicationBuilder app, EsiurOptions options)
{
ArgumentNullException.ThrowIfNull(app);
ArgumentNullException.ThrowIfNull(options);
return app.UseMiddleware<EsiurMiddleware>(Options.Create(options));
}
}
}

View File

@ -0,0 +1,9 @@
using Esiur.Net.IIP;
namespace Esiur.AspNetCore
{
public class EsiurOptions
{
public DistributedServer Server { get; set; }
}
}

View File

@ -16,7 +16,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Esiur.Examples.StandaloneWe
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Esiur.CLI", "Esiur.CLI\Esiur.CLI.csproj", "{5C193127-20D1-4709-90C4-DF714D7E6700}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Esiur.CLI", "Esiur.CLI\Esiur.CLI.csproj", "{5C193127-20D1-4709-90C4-DF714D7E6700}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Esiur.ASPNet", "Esiur.ASPNet\Esiur.ASPNet.csproj", "{7C65CC4D-0DE6-4E2A-8DCF-113E1AB85D8A}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Esiur.AspNetCore.Example", "Esiur.ASPNet\Esiur.AspNetCore.Example.csproj", "{7C65CC4D-0DE6-4E2A-8DCF-113E1AB85D8A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Esiur.AspNetCore", "Esiur.AspNetCore\Esiur.AspNetCore.csproj", "{7B0C521F-8B13-4F2A-BD78-7C692620C831}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -56,6 +58,10 @@ Global
{7C65CC4D-0DE6-4E2A-8DCF-113E1AB85D8A}.Debug|Any CPU.Build.0 = Debug|Any CPU {7C65CC4D-0DE6-4E2A-8DCF-113E1AB85D8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C65CC4D-0DE6-4E2A-8DCF-113E1AB85D8A}.Release|Any CPU.ActiveCfg = Release|Any CPU {7C65CC4D-0DE6-4E2A-8DCF-113E1AB85D8A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7C65CC4D-0DE6-4E2A-8DCF-113E1AB85D8A}.Release|Any CPU.Build.0 = Release|Any CPU {7C65CC4D-0DE6-4E2A-8DCF-113E1AB85D8A}.Release|Any CPU.Build.0 = Release|Any CPU
{7B0C521F-8B13-4F2A-BD78-7C692620C831}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B0C521F-8B13-4F2A-BD78-7C692620C831}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B0C521F-8B13-4F2A-BD78-7C692620C831}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B0C521F-8B13-4F2A-BD78-7C692620C831}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE