2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-05-06 11:32:59 +00:00

ASP.Net Support

This commit is contained in:
Ahmed Zamil 2024-09-08 22:37:54 +03:00
parent c8c291fe61
commit 7d9751501e
9 changed files with 176 additions and 1 deletions

View File

@ -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<MainController> _logger;
public MainController(ILogger<MainController> logger)
{
_logger = logger;
}
[HttpGet(Name = "Get")]
public async AsyncReply<MyResource> Get()
{
return await Warehouse.Get<MyResource>("/sys/demo");
}
}
}

View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Esiur\Esiur.csproj" OutputItemType="Analyzer"/>
</ItemGroup>
</Project>

View File

@ -0,0 +1,6 @@
@Esiur.ASPNet_HostAddress = http://localhost:5141
GET {{Esiur.ASPNet_HostAddress}}/weatherforecast/
Accept: application/json
###

View File

@ -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 };
}
}

48
Esiur.ASPNet/Program.cs Normal file
View File

@ -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();

View File

@ -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"
}
}
}
}

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

View File

@ -14,7 +14,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Esiur.Security.Cryptography
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Esiur.Examples.StandaloneWebServerDemo", "Esiur.Examples.StandaloneWebServerDemo\Esiur.Examples.StandaloneWebServerDemo.csproj", "{A00BBD34-601D-4803-94AE-B807DC75D53A}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Esiur.Examples.StandaloneWebServerDemo", "Esiur.Examples.StandaloneWebServerDemo\Esiur.Examples.StandaloneWebServerDemo.csproj", "{A00BBD34-601D-4803-94AE-B807DC75D53A}"
EndProject 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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution 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}.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.ActiveCfg = Release|Any CPU
{5C193127-20D1-4709-90C4-DF714D7E6700}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE