Jelajahi Sumber

Add NetCoreServer framework (C#) (#6272)

* Add NetCoreServer framework

* Remove no longer needed extensions
Andreas Nägeli 4 tahun lalu
induk
melakukan
9a3dfa8712

+ 38 - 0
frameworks/CSharp/netcoreserver/.gitignore

@@ -0,0 +1,38 @@
+[Oo]bj/
+[Bb]in/
+TestResults/
+.nuget/
+*.sln
+*.sln.ide/
+_ReSharper.*/
+.idea/
+packages/
+artifacts/
+PublishProfiles/
+.vs/
+*.user
+*.suo
+*.cache
+*.docstates
+_ReSharper.*
+nuget.exe
+*net45.csproj
+*net451.csproj
+*k10.csproj
+*.psess
+*.vsp
+*.pidb
+*.userprefs
+*DS_Store
+*.ncrunchsolution
+*.*sdf
+*.ipch
+*.swp
+*~
+.build/
+.testPublish/
+launchSettings.json
+BenchmarkDotNet.Artifacts/
+BDN.Generated/
+binaries/
+global.json

+ 24 - 0
frameworks/CSharp/netcoreserver/Benchmarks/Benchmarks.csproj

@@ -0,0 +1,24 @@
+<Project Sdk="Microsoft.NET.Sdk">
+  
+  <PropertyGroup>
+    
+    <TargetFramework>net5.0</TargetFramework>
+    <LangVersion>9.0</LangVersion>
+    
+    <AssemblyTitle>EmbedIO Benchmarks</AssemblyTitle>
+    <Description>Test suite to be executed with TechEmpower FrameworkBenchmarks.</Description>
+    
+    <StartupObject>Benchmarks.Program</StartupObject>    
+    <OutputType>Exe</OutputType>
+    
+    <ServerGarbageCollection>true</ServerGarbageCollection>
+    <TieredCompilation>false</TieredCompilation>
+    
+  </PropertyGroup>
+  
+  <ItemGroup>
+    <PackageReference Include="NetCoreServer" Version="5.0.7" />
+    <PackageReference Include="System.Text.Json" Version="5.0.0" />
+  </ItemGroup>
+  
+</Project>

+ 24 - 0
frameworks/CSharp/netcoreserver/Benchmarks/HttpBenchmarkServer.cs

@@ -0,0 +1,24 @@
+using System;
+using System.Net;
+using System.Net.Sockets;
+
+using NetCoreServer;
+
+namespace Benchmarks
+{
+
+    public class HttpBenchmarkServer : HttpServer
+    {
+
+        public HttpBenchmarkServer(IPAddress address, int port) : base(address, port) { }
+
+        protected override TcpSession CreateSession() { return new HttpBenchmarkSession(this); }
+
+        protected override void OnError(SocketError error)
+        {
+            Console.WriteLine($"HTTP session caught an error: {error}");
+        }
+
+    }
+
+}

+ 59 - 0
frameworks/CSharp/netcoreserver/Benchmarks/HttpBenchmarkSession.cs

@@ -0,0 +1,59 @@
+using System;
+using System.Net.Sockets;
+using System.Text.Json;
+
+using NetCoreServer;
+
+namespace Benchmarks
+{
+
+    public class HttpBenchmarkSession : HttpSession
+    {
+
+        public HttpBenchmarkSession(HttpServer server) : base(server) { }
+
+        protected override void OnReceivedRequest(HttpRequest request)
+        {
+            if (request.Url.StartsWith("/plaintext"))
+            {
+                SendResponseAsync(MakeResponse("Hello, World!", "text/plain; charset=UTF-8"));
+            }
+            else if (request.Url.StartsWith("/json"))
+            {
+                var value = new JsonResult() { Message = "Hello, World!" };
+                var serialized = JsonSerializer.Serialize(value);
+
+                SendResponseAsync(MakeResponse(serialized, "application/json; charset=UTF-8"));
+            }
+            else
+            {
+                SendResponseAsync(Response.MakeErrorResponse("Not found", 404));
+            }
+        }
+
+        protected override void OnReceivedRequestError(HttpRequest request, string error)
+        {
+            Console.WriteLine($"Request error: {error}");
+        }
+
+        protected override void OnError(SocketError error)
+        {
+            Console.WriteLine($"HTTP session caught an error: {error}");
+        }
+
+        private static HttpResponse MakeResponse(string value, string contentType)
+        {
+            var response = new HttpResponse(200, "OK", "HTTP/1.1");
+
+            response.SetHeader("Server", "NetCoreServer");
+            response.SetHeader("Date", DateTime.UtcNow.ToString("r"));
+            response.SetHeader("Content-Type", contentType);
+
+            response.SetBody(value);
+
+            return response;
+        }
+
+    }
+
+}

+ 11 - 0
frameworks/CSharp/netcoreserver/Benchmarks/JsonResult.cs

@@ -0,0 +1,11 @@
+namespace Benchmarks
+{
+
+    public sealed class JsonResult
+    {
+
+        public string Message { get; set; }
+
+    }
+
+}

+ 44 - 0
frameworks/CSharp/netcoreserver/Benchmarks/Program.cs

@@ -0,0 +1,44 @@
+using System;
+using System.Net;
+using System.Threading;
+
+namespace Benchmarks
+{
+
+    public static class Program
+    {
+
+        private static readonly ManualResetEvent _WaitEvent = new ManualResetEvent(false);
+
+        public static int Main(string[] args)
+        {
+            var server = new HttpBenchmarkServer(IPAddress.Any, 8080);
+
+            try
+            {
+                AppDomain.CurrentDomain.ProcessExit += (_, __) =>
+                {
+                    _WaitEvent.Set();
+                };
+
+                server.Start();
+
+                _WaitEvent.WaitOne();
+
+                return 0;
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine(e);
+
+                return -1;
+            }
+            finally
+            {
+                server.Stop();
+            }
+        }
+
+    }
+
+}

+ 22 - 0
frameworks/CSharp/netcoreserver/README.md

@@ -0,0 +1,22 @@
+# NetCoreServer Tests on Linux
+
+See the [project website](https://github.com/chronoxor/NetCoreServer) for more information.
+
+## Infrastructure Software Versions
+
+**Language**
+
+* C# 9.0
+
+**Platforms**
+
+* .NET 5
+
+**Web Servers**
+
+* [NetCoreServer](https://github.com/chronoxor/NetCoreServer)
+
+## Paths & Source for Tests
+
+* [Plaintext](Benchmarks/HttpBenchmarkSession.cs): "/plaintext"
+* [JSON](Benchmarks/HttpBenchmarkSession.cs): "/json"

+ 22 - 0
frameworks/CSharp/netcoreserver/benchmark_config.json

@@ -0,0 +1,22 @@
+{
+  "framework": "netcoreserver",
+  "tests": [{
+    "default": {
+      "plaintext_url": "/plaintext",
+      "json_url": "/json",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Fullstack",
+      "database": "None",
+      "framework": "NetCoreServer",
+      "language": "C#",
+      "orm": "Raw",
+      "platform": ".NET",
+      "webserver": "NetCoreServer",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "NetCoreServer",
+      "notes": ""
+    }
+  }]
+}

+ 15 - 0
frameworks/CSharp/netcoreserver/config.toml

@@ -0,0 +1,15 @@
+[framework]
+name = "netcoreserver"
+
+[main]
+urls.plaintext = "/plaintext"
+urls.json = "/json"
+approach = "Realistic"
+classification = "Fullstack"
+database = "None"
+database_os = "Linux"
+os = "Linux"
+orm = "Raw"
+platform = ".NET"
+webserver = "NetCoreServer"
+versus = "None"

+ 19 - 0
frameworks/CSharp/netcoreserver/netcoreserver.dockerfile

@@ -0,0 +1,19 @@
+FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine AS build
+WORKDIR /source
+
+# copy csproj and restore as distinct layers
+COPY Benchmarks/*.csproj .
+RUN dotnet restore -r linux-musl-x64
+
+# copy and publish app and libraries
+COPY Benchmarks/ .
+RUN dotnet publish -c release -o /app -r linux-musl-x64
+
+# final stage/image
+FROM mcr.microsoft.com/dotnet/runtime-deps:5.0-alpine
+WORKDIR /app
+COPY --from=build /app .
+
+ENTRYPOINT ["./Benchmarks"]
+
+EXPOSE 8080