2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-27 05:23:13 +00:00

ASPNet Support

This commit is contained in:
2024-09-10 21:51:31 +03:00
parent 7d9751501e
commit 5745887b48
3 changed files with 99 additions and 39 deletions

View File

@ -1,48 +1,75 @@
using Esiur.ASPNet;
using Esiur.Core;
using Esiur.Net.IIP;
using Esiur.Net.Sockets;
using Esiur.Resource;
using Esiur.Stores;
using Microsoft.AspNetCore.Hosting.Server;
using System.Net.WebSockets;
using System.Reflection;
using System.Text;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
//builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
//builder.Services.AddEndpointsApiExplorer();
//builder.Services.AddSwaggerGen();
builder.WebHost.UseUrls("http://localhost:8080");
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
var webSocketOptions = new WebSocketOptions()
{
app.UseSwagger();
app.UseSwaggerUI();
}
KeepAliveInterval = TimeSpan.FromSeconds(120),
};
app.UseHttpsRedirection();
app.UseWebSockets(webSocketOptions);
app.UseAuthorization();
app.MapControllers();
// Configure the HTTP request pipeline.
//if (app.Environment.IsDevelopment())
//{
// app.UseSwagger();
// app.UseSwaggerUI();
//}
app.UseWebSockets();
//app.UseHttpsRedirection();
//app.UseAuthorization();
//app.MapControllers();
await Warehouse.Put("sys", new MemoryStore());
await Warehouse.Put("sys/service", new MyResource());
var server = await Warehouse.Put("sys/server", new DistributedServer());
await Warehouse.Open();
app.Use(async (context, next) =>
{
if (context.Request.Path == "/esiur")
var buffer = new ArraySegment<byte>(new byte[10240]);
if (context.WebSockets.IsWebSocketRequest)
{
if (context.WebSockets.IsWebSocketRequest)
{
using var webSocket = await context.WebSockets.AcceptWebSocketAsync();
}
else
{
context.Response.StatusCode = StatusCodes.Status400BadRequest;
}
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);
}
});
app.Run();
await app.RunAsync();