Create project files

This commit is contained in:
Dmitri Shimanski
2025-03-29 02:34:08 +03:00
commit abab2be4f4
32 changed files with 1057 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
using yawaflua.WebSockets.Attributes;
using yawaflua.WebSockets.Models.Abstracts;
using WebSocket = yawaflua.WebSockets.Core.WebSocket;
namespace Examples;
[WebSocket("/chat")]
public class ChatController : WebSocketController
{
public override async Task OnMessageAsync(
WebSocket webSocket,
HttpContext httpContext)
{
await WebSocketManager.Broadcast(k => k.Path == "/chat", $"{webSocket.Client.Id}: {webSocket.Message}");
}
}

21
Examples/Dockerfile Normal file
View File

@@ -0,0 +1,21 @@
FROM mcr.microsoft.com/dotnet/runtime:9.0 AS base
USER $APP_UID
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Examples/Examples.csproj", "Examples/"]
RUN dotnet restore "Examples/Examples.csproj"
COPY . .
WORKDIR "/src/Examples"
RUN dotnet build "Examples.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "Examples.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Examples.dll"]

22
Examples/Examples.csproj Normal file
View File

@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<Content Include="..\.dockerignore">
<Link>.dockerignore</Link>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\yawaflua.WebSockets\yawaflua.WebSockets.csproj" />
</ItemGroup>
</Project>

42
Examples/Program.cs Normal file
View File

@@ -0,0 +1,42 @@
using yawaflua.WebSockets;
namespace Examples;
class Program
{
static async Task Main(string[] args)
{
await Host.CreateDefaultBuilder(args)
.ConfigureLogging(k => k.AddConsole().AddDebug())
.ConfigureWebHost(k =>
{
k.UseKestrel(l => l.ListenAnyIP(80));
k.UseStartup<Startup>();
})
.RunConsoleAsync();
}
}
internal class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.SettingUpWebSockets();
services.AddRouting();
services.AddHttpLogging();
services.AddSingleton<TestWebSocketServer>();
services.AddSingleton<ChatController>();
services.AddScoped<IConfiguration>(k => new ConfigurationBuilder()
.AddJsonFile("appsettings.json", true)
.Build());
}
public void Configure(IApplicationBuilder app)
{
app.ConnectWebSockets();
app.UseRouting();
app.UseHttpLogging();
app.UseWelcomePage();
}
}

View File

@@ -0,0 +1,18 @@
using System.Text.Json;
using Microsoft.AspNetCore.Mvc;
using yawaflua.WebSockets.Attributes;
using yawaflua.WebSockets.Core;
using yawaflua.WebSockets.Models.Abstracts;
namespace Examples;
[WebSocket("/test")]
public class TestWebSocketServer : WebSocketController
{
[WebSocket("/sub-test")]
public override async Task OnMessageAsync(WebSocket webSocket, HttpContext httpContext)
{
await webSocket.SendAsync("Test! Now on it endpoint: " + WebSocketManager.GetAllClients().Count(k => k.Path == webSocket.Client.Path));
}
}

View File

@@ -0,0 +1 @@
{}