Skip to content

Commit abab2be

Browse files
committed
Create project files
0 parents  commit abab2be

32 files changed

Lines changed: 1057 additions & 0 deletions

.dockerignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
**/.dockerignore
2+
**/.env
3+
**/.git
4+
**/.gitignore
5+
**/.project
6+
**/.settings
7+
**/.toolstarget
8+
**/.vs
9+
**/.vscode
10+
**/.idea
11+
**/*.*proj.user
12+
**/*.dbmdl
13+
**/*.jfm
14+
**/azds.yaml
15+
**/bin
16+
**/charts
17+
**/docker-compose*
18+
**/Dockerfile*
19+
**/node_modules
20+
**/npm-debug.log
21+
**/obj
22+
**/secrets.dev.yaml
23+
**/values.dev.yaml
24+
LICENSE
25+
README.md

.github/workflows/dotnet.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: .NET Tests
2+
3+
on:
4+
push:
5+
branches: [ "*" ]
6+
pull_request:
7+
branches: [ "*" ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Setup .NET
15+
uses: actions/setup-dotnet@v4
16+
with:
17+
dotnet-version: [6.0.x, 7.0.x, 8.0.x, 9.0.x]
18+
- name: Restore dependencies
19+
run: dotnet restore
20+
- name: Build
21+
run: dotnet build --no-restore /p:TreatWarningsAsErrors=false
22+
- name: Test
23+
run: dotnet test --no-build --verbosity normal

.github/workflows/nuget.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: CI/CD NuGet Package
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
env:
8+
NUGET_SOURCE: https://api.nuget.org/v3/index.json
9+
GITHUB_SOURCE: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
10+
11+
jobs:
12+
build-and-publish:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Setup .NET
19+
uses: actions/setup-dotnet@v3
20+
with:
21+
dotnet-version: 7.0.x
22+
23+
- name: Extract Package Version
24+
id: get_version
25+
run: |
26+
VERSION=${GITHUB_REF#refs/tags/v}
27+
echo "PACKAGE_VERSION=$VERSION" >> $GITHUB_ENV
28+
echo "Using version: $VERSION"
29+
30+
- name: Restore dependencies
31+
run: dotnet restore
32+
33+
- name: Build
34+
run: dotnet build --no-restore --configuration Release
35+
36+
- name: Test
37+
run: dotnet test --no-build --verbosity normal --configuration Release
38+
39+
- name: Pack
40+
run: dotnet pack --no-build --configuration Release -p:PackageVersion=${{ env.PACKAGE_VERSION }}
41+
- name: Add GitHub source
42+
run: dotnet nuget add source --username ${{ github.repository_owner }} --password ${{ secrets.GHCR_TOKEN }} --store-password-in-clear-text --name github ${{ env.GITHUB_SOURCE }}
43+
44+
- name: Publish to GitHub Packages
45+
run: dotnet nuget push "**/*.nupkg" --source "github"
46+
47+
- name: Publish to NuGet
48+
run: dotnet nuget push "**/*.nupkg" --source ${{ env.NUGET_SOURCE }} --api-key ${{ secrets.NUGET_API_KEY }}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bin/
2+
obj/
3+
/packages/
4+
riderModule.iml
5+
/_ReSharper.Caches/

.idea/.idea.yawaflua.WebSockets/.idea/.gitignore

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.yawaflua.WebSockets/.idea/encodings.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Examples/ChatController.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using yawaflua.WebSockets.Attributes;
2+
using yawaflua.WebSockets.Models.Abstracts;
3+
using WebSocket = yawaflua.WebSockets.Core.WebSocket;
4+
5+
namespace Examples;
6+
7+
[WebSocket("/chat")]
8+
public class ChatController : WebSocketController
9+
{
10+
11+
public override async Task OnMessageAsync(
12+
WebSocket webSocket,
13+
HttpContext httpContext)
14+
{
15+
await WebSocketManager.Broadcast(k => k.Path == "/chat", $"{webSocket.Client.Id}: {webSocket.Message}");
16+
}
17+
}

Examples/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM mcr.microsoft.com/dotnet/runtime:9.0 AS base
2+
USER $APP_UID
3+
WORKDIR /app
4+
5+
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
6+
ARG BUILD_CONFIGURATION=Release
7+
WORKDIR /src
8+
COPY ["Examples/Examples.csproj", "Examples/"]
9+
RUN dotnet restore "Examples/Examples.csproj"
10+
COPY . .
11+
WORKDIR "/src/Examples"
12+
RUN dotnet build "Examples.csproj" -c $BUILD_CONFIGURATION -o /app/build
13+
14+
FROM build AS publish
15+
ARG BUILD_CONFIGURATION=Release
16+
RUN dotnet publish "Examples.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
17+
18+
FROM base AS final
19+
WORKDIR /app
20+
COPY --from=publish /app/publish .
21+
ENTRYPOINT ["dotnet", "Examples.dll"]

Examples/Examples.csproj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
9+
<IsPackable>false</IsPackable>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<Content Include="..\.dockerignore">
14+
<Link>.dockerignore</Link>
15+
</Content>
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\yawaflua.WebSockets\yawaflua.WebSockets.csproj" />
20+
</ItemGroup>
21+
22+
</Project>

Examples/Program.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using yawaflua.WebSockets;
2+
3+
namespace Examples;
4+
5+
class Program
6+
{
7+
static async Task Main(string[] args)
8+
{
9+
await Host.CreateDefaultBuilder(args)
10+
.ConfigureLogging(k => k.AddConsole().AddDebug())
11+
.ConfigureWebHost(k =>
12+
{
13+
k.UseKestrel(l => l.ListenAnyIP(80));
14+
k.UseStartup<Startup>();
15+
})
16+
.RunConsoleAsync();
17+
}
18+
}
19+
20+
internal class Startup
21+
{
22+
public void ConfigureServices(IServiceCollection services)
23+
{
24+
services.SettingUpWebSockets();
25+
services.AddRouting();
26+
services.AddHttpLogging();
27+
services.AddSingleton<TestWebSocketServer>();
28+
services.AddSingleton<ChatController>();
29+
services.AddScoped<IConfiguration>(k => new ConfigurationBuilder()
30+
.AddJsonFile("appsettings.json", true)
31+
.Build());
32+
}
33+
34+
public void Configure(IApplicationBuilder app)
35+
{
36+
app.ConnectWebSockets();
37+
app.UseRouting();
38+
app.UseHttpLogging();
39+
app.UseWelcomePage();
40+
41+
}
42+
}

0 commit comments

Comments
 (0)