generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple server for aspire sessions
- Loading branch information
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System.Net.WebSockets; | ||
using System.Text.Json; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
builder.Services.ConfigureHttpJsonOptions(it => | ||
{ | ||
it.SerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower; | ||
}); | ||
|
||
var app = builder.Build(); | ||
|
||
app.UseWebSockets(); | ||
|
||
app.MapPut("/run_session", (Session session) => | ||
{ | ||
app.Logger.LogInformation("Session request {session}", session); | ||
return TypedResults.Created(); | ||
}); | ||
|
||
app.MapDelete("/run_session/{sessionId:guid}", (Guid sessionId) => | ||
{ | ||
return TypedResults.Ok(); | ||
}); | ||
|
||
app.MapGet("/run_session/notify", async context => | ||
{ | ||
if (context.WebSockets.IsWebSocketRequest) | ||
{ | ||
using var ws = await context.WebSockets.AcceptWebSocketAsync(); | ||
await Receive(ws); | ||
} | ||
else | ||
{ | ||
context.Response.StatusCode = StatusCodes.Status400BadRequest; | ||
} | ||
}); | ||
|
||
app.Run(); | ||
|
||
static async Task Receive(WebSocket webSocket) | ||
{ | ||
var buffer = new byte[1024 * 4]; | ||
var receiveResult = await webSocket.ReceiveAsync( | ||
new ArraySegment<byte>(buffer), CancellationToken.None); | ||
|
||
while (!receiveResult.CloseStatus.HasValue) | ||
{ | ||
receiveResult = await webSocket.ReceiveAsync( | ||
new ArraySegment<byte>(buffer), CancellationToken.None); | ||
} | ||
|
||
await webSocket.CloseAsync( | ||
receiveResult.CloseStatus.Value, | ||
receiveResult.CloseStatusDescription, | ||
CancellationToken.None); | ||
} | ||
|
||
record Session( | ||
string ProjectPath, | ||
bool Debug, | ||
EnvironmentVariable[] Env, | ||
string[] Args | ||
); | ||
|
||
record EnvironmentVariable(string Name, string Value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<RootNamespace>AspireSessionHost</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="JetBrains.RdFramework" Version="2023.3.3" /> | ||
</ItemGroup> | ||
|
||
</Project> |