From 7d9751501eb407cf84133ce37ae536bdead962d7 Mon Sep 17 00:00:00 2001 From: Ahmed Zamil Date: Sun, 8 Sep 2024 22:37:54 +0300 Subject: [PATCH] ASP.Net Support --- Esiur.ASPNet/Controllers/MainController.cs | 25 +++++++++++ Esiur.ASPNet/Esiur.ASPNet.csproj | 17 ++++++++ Esiur.ASPNet/Esiur.ASPNet.http | 6 +++ Esiur.ASPNet/MyResource.cs | 15 +++++++ Esiur.ASPNet/Program.cs | 48 +++++++++++++++++++++ Esiur.ASPNet/Properties/launchSettings.json | 41 ++++++++++++++++++ Esiur.ASPNet/appsettings.Development.json | 8 ++++ Esiur.ASPNet/appsettings.json | 9 ++++ Esiur.sln | 8 +++- 9 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 Esiur.ASPNet/Controllers/MainController.cs create mode 100644 Esiur.ASPNet/Esiur.ASPNet.csproj create mode 100644 Esiur.ASPNet/Esiur.ASPNet.http create mode 100644 Esiur.ASPNet/MyResource.cs create mode 100644 Esiur.ASPNet/Program.cs create mode 100644 Esiur.ASPNet/Properties/launchSettings.json create mode 100644 Esiur.ASPNet/appsettings.Development.json create mode 100644 Esiur.ASPNet/appsettings.json diff --git a/Esiur.ASPNet/Controllers/MainController.cs b/Esiur.ASPNet/Controllers/MainController.cs new file mode 100644 index 0000000..87b0015 --- /dev/null +++ b/Esiur.ASPNet/Controllers/MainController.cs @@ -0,0 +1,25 @@ +using Esiur.Core; +using Esiur.Resource; +using Microsoft.AspNetCore.Mvc; + +namespace Esiur.ASPNet.Controllers +{ + [ApiController] + [Route("[controller]")] + public class MainController : ControllerBase + { + + private readonly ILogger _logger; + + public MainController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "Get")] + public async AsyncReply Get() + { + return await Warehouse.Get("/sys/demo"); + } + } +} diff --git a/Esiur.ASPNet/Esiur.ASPNet.csproj b/Esiur.ASPNet/Esiur.ASPNet.csproj new file mode 100644 index 0000000..bdd2ea1 --- /dev/null +++ b/Esiur.ASPNet/Esiur.ASPNet.csproj @@ -0,0 +1,17 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + diff --git a/Esiur.ASPNet/Esiur.ASPNet.http b/Esiur.ASPNet/Esiur.ASPNet.http new file mode 100644 index 0000000..a934301 --- /dev/null +++ b/Esiur.ASPNet/Esiur.ASPNet.http @@ -0,0 +1,6 @@ +@Esiur.ASPNet_HostAddress = http://localhost:5141 + +GET {{Esiur.ASPNet_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/Esiur.ASPNet/MyResource.cs b/Esiur.ASPNet/MyResource.cs new file mode 100644 index 0000000..ad022b4 --- /dev/null +++ b/Esiur.ASPNet/MyResource.cs @@ -0,0 +1,15 @@ +using Esiur.Resource; + +namespace Esiur.ASPNet +{ + [Resource] + public partial class MyResource + { + [Export] int number; + + [Export] + public string[] GetInfo() => new string[] { Environment.MachineName, Environment.UserName, Environment.CurrentDirectory, + Environment.CommandLine, Environment.OSVersion.ToString(), Environment.ProcessPath }; + + } +} diff --git a/Esiur.ASPNet/Program.cs b/Esiur.ASPNet/Program.cs new file mode 100644 index 0000000..8801f77 --- /dev/null +++ b/Esiur.ASPNet/Program.cs @@ -0,0 +1,48 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.UseWebSockets(); + +app.Use(async (context, next) => +{ + if (context.Request.Path == "/esiur") + { + if (context.WebSockets.IsWebSocketRequest) + { + using var webSocket = await context.WebSockets.AcceptWebSocketAsync(); + } + else + { + context.Response.StatusCode = StatusCodes.Status400BadRequest; + } + } + else + { + await next(context); + } + +}); + + +app.Run(); diff --git a/Esiur.ASPNet/Properties/launchSettings.json b/Esiur.ASPNet/Properties/launchSettings.json new file mode 100644 index 0000000..678b351 --- /dev/null +++ b/Esiur.ASPNet/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:24282", + "sslPort": 44358 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5141", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7282;http://localhost:5141", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Esiur.ASPNet/appsettings.Development.json b/Esiur.ASPNet/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Esiur.ASPNet/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Esiur.ASPNet/appsettings.json b/Esiur.ASPNet/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Esiur.ASPNet/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Esiur.sln b/Esiur.sln index 3104510..3319d6c 100644 --- a/Esiur.sln +++ b/Esiur.sln @@ -14,7 +14,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Esiur.Security.Cryptography EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Esiur.Examples.StandaloneWebServerDemo", "Esiur.Examples.StandaloneWebServerDemo\Esiur.Examples.StandaloneWebServerDemo.csproj", "{A00BBD34-601D-4803-94AE-B807DC75D53A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "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 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Esiur.ASPNet", "Esiur.ASPNet\Esiur.ASPNet.csproj", "{7C65CC4D-0DE6-4E2A-8DCF-113E1AB85D8A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -50,6 +52,10 @@ Global {5C193127-20D1-4709-90C4-DF714D7E6700}.Debug|Any CPU.Build.0 = Debug|Any CPU {5C193127-20D1-4709-90C4-DF714D7E6700}.Release|Any CPU.ActiveCfg = Release|Any CPU {5C193127-20D1-4709-90C4-DF714D7E6700}.Release|Any CPU.Build.0 = Release|Any CPU + {7C65CC4D-0DE6-4E2A-8DCF-113E1AB85D8A}.Debug|Any CPU.ActiveCfg = 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.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE