Skip to content

Commit 3322534

Browse files
committed
New (Project Configuration): Add TouchSocketHttp31 and TouchSocketWebAni31
Add TouchSocketHttp31 and TouchSocketWebAni31 projects to the solution -Update Benchmarks.sln to support new projects and upgrade VS version to 18 -Add new configuration items to benchmark∝json and config. toml -Add Dockerfiles for TouchSocketHttp31 and TouchSocketWebApp i31 -TouchSocketHttp project adds HTTP service program, supporting/plaintext and/json routing -TouchSocketWebApi project adds Web API service program, supporting/plaintext and/json routing -Add the configuration files' appsets.json 'and' appsettings. Development. json ' -The target frameworks for TouchSocketHttp31 and TouchSocketWebApp i31 projects are NET 8.0 -Add NuGet. Config to specify the unique package source as the official source of VNet
1 parent ea28bb2 commit 3322534

File tree

14 files changed

+353
-3
lines changed

14 files changed

+353
-3
lines changed

frameworks/CSharp/touchsocket/Benchmarks.sln

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 17
4-
VisualStudioVersion = 17.0.31717.71
3+
# Visual Studio Version 18
4+
VisualStudioVersion = 18.0.11109.219 d18.0-oob
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchSocketWebApi", "src\TouchSocketWebApi\TouchSocketWebApi.csproj", "{6BD9363A-D77F-5D90-8444-2BC37495C920}"
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchSocketHttp", "src\TouchSocketHttp\TouchSocketHttp.csproj", "{A7FB43AB-672B-8854-68D7-C2B383B0BC04}"
99
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchSocketHttp31", "src\TouchSocketHttp31\TouchSocketHttp31.csproj", "{DE261A06-A254-FD54-4ACF-EE4D4352BA77}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchSocketWebApi31", "src\TouchSocketWebApi31\TouchSocketWebApi31.csproj", "{6B6A57CE-1F69-FA6E-7458-0A4B6AB60683}"
13+
EndProject
1014
Global
1115
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1216
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +25,14 @@ Global
2125
{A7FB43AB-672B-8854-68D7-C2B383B0BC04}.Debug|Any CPU.Build.0 = Debug|Any CPU
2226
{A7FB43AB-672B-8854-68D7-C2B383B0BC04}.Release|Any CPU.ActiveCfg = Release|Any CPU
2327
{A7FB43AB-672B-8854-68D7-C2B383B0BC04}.Release|Any CPU.Build.0 = Release|Any CPU
28+
{DE261A06-A254-FD54-4ACF-EE4D4352BA77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{DE261A06-A254-FD54-4ACF-EE4D4352BA77}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{DE261A06-A254-FD54-4ACF-EE4D4352BA77}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{DE261A06-A254-FD54-4ACF-EE4D4352BA77}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{6B6A57CE-1F69-FA6E-7458-0A4B6AB60683}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{6B6A57CE-1F69-FA6E-7458-0A4B6AB60683}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{6B6A57CE-1F69-FA6E-7458-0A4B6AB60683}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{6B6A57CE-1F69-FA6E-7458-0A4B6AB60683}.Release|Any CPU.Build.0 = Release|Any CPU
2436
EndGlobalSection
2537
GlobalSection(SolutionProperties) = preSolution
2638
HideSolutionNode = FALSE

frameworks/CSharp/touchsocket/benchmark_config.json

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,44 @@
3838
"display_name": "touchsocket.http",
3939
"notes": "",
4040
"versus": "aspnetcore"
41+
},
42+
"http31": {
43+
"plaintext_url": "/plaintext",
44+
"json_url": "/json",
45+
"port": 8080,
46+
"approach": "Realistic",
47+
"classification": "Micro",
48+
"database": "Postgres",
49+
"framework": "touchsocket.http31",
50+
"language": "C#",
51+
"orm": "Micro",
52+
"platform": ".NET",
53+
"flavor": "CoreCLR",
54+
"webserver": "touchsocket",
55+
"os": "Linux",
56+
"database_os": "Linux",
57+
"display_name": "touchsocket.http31",
58+
"notes": "",
59+
"versus": "aspnetcore"
60+
},
61+
"webapi31": {
62+
"plaintext_url": "/plaintext",
63+
"json_url": "/json",
64+
"port": 8080,
65+
"approach": "Realistic",
66+
"classification": "Fullstack",
67+
"framework": "touchsocket.webapi31",
68+
"language": "C#",
69+
"orm": "Raw",
70+
"platform": ".NET",
71+
"flavor": "CoreCLR",
72+
"webserver": "touchsocket",
73+
"os": "Linux",
74+
"database_os": "Linux",
75+
"display_name": "touchsocket.webapi31",
76+
"notes": "",
77+
"versus": "aspnetcore-mvc"
4178
}
4279
}
4380
]
44-
}
81+
}

frameworks/CSharp/touchsocket/config.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,29 @@ orm = "Raw"
2626
platform = ".NET"
2727
webserver = "touchsocket.http"
2828
versus = "aspcore"
29+
30+
[http31]
31+
urls.plaintext = "/plaintext"
32+
urls.json = "/json"
33+
approach = "Realistic"
34+
classification = "Micro"
35+
database = "Postgres"
36+
database_os = "Linux"
37+
os = "Linux"
38+
orm = "Raw"
39+
platform = ".NET"
40+
webserver = "touchsocket.http31"
41+
versus = "aspcore"
42+
43+
[webapi31]
44+
urls.plaintext = "/plaintext"
45+
urls.json = "/json"
46+
approach = "Realistic"
47+
classification = "Fullstack"
48+
database = "Postgres"
49+
database_os = "Linux"
50+
os = "Linux"
51+
orm = "Raw"
52+
platform = ".NET"
53+
webserver = "touchsocket.webapi31"
54+
versus = "aspcore-mvc"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<clear />
5+
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
6+
</packageSources>
7+
</configuration>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using System.Text;
2+
using TouchSocket.Core;
3+
using TouchSocket.Http;
4+
using TouchSocket.Sockets;
5+
using static System.Net.Mime.MediaTypeNames;
6+
using HttpContent = TouchSocket.Http.HttpContent;
7+
8+
namespace TouchSocketHttp;
9+
10+
public class Program
11+
{
12+
static async Task Main(string[] args)
13+
{
14+
int port = 8080;
15+
16+
Console.WriteLine(DateHelper.DateString);
17+
var service = new MyHttpService();
18+
19+
await service.SetupAsync(new TouchSocketConfig()
20+
.SetListenIPHosts(port)
21+
.SetNoDelay(true)
22+
.SetMaxCount(1000000)
23+
.ConfigureContainer(a =>
24+
{
25+
a.AddConsoleLogger();
26+
}));
27+
28+
await service.StartAsync();
29+
service.Logger.Info($"server is started,port:{port}");
30+
while (true)
31+
{
32+
Console.ReadLine();
33+
}
34+
}
35+
}
36+
37+
sealed class MyHttpService : HttpService<MyHttpSessionClient>
38+
{
39+
protected override MyHttpSessionClient NewClient()
40+
{
41+
return new MyHttpSessionClient();
42+
}
43+
}
44+
45+
sealed class MyHttpSessionClient : HttpSessionClient
46+
{
47+
private readonly HttpContent m_contentPlaintext = new StringHttpContent("Hello, World!", Encoding.UTF8, $"text/plain");
48+
private readonly HttpContent m_contentJson = new StringHttpContent("{\"message\":\"Hello, World!\"}", Encoding.UTF8, $"application/json");
49+
50+
protected override async Task OnReceivedHttpRequest(HttpContext httpContext)
51+
{
52+
var request = httpContext.Request;
53+
var response = httpContext.Response;
54+
55+
switch (request.RelativeURL)
56+
{
57+
case "/plaintext":
58+
{
59+
response.StatusCode = 200;
60+
response.StatusMessage = "success";
61+
response.Headers.Add(HttpHeaders.Server, "T");
62+
response.Headers.Add(HttpHeaders.Date, DateHelper.DateString);
63+
response.Content = m_contentPlaintext;
64+
await response.AnswerAsync().ConfigureAwait(false);
65+
}
66+
break;
67+
case "/json":
68+
{
69+
response.StatusCode = 200;
70+
response.StatusMessage = "success";
71+
response.Headers.Add(HttpHeaders.Server, "T");
72+
response.Headers.Add(HttpHeaders.Date, DateHelper.DateString);
73+
response.Content = m_contentJson;
74+
await response.AnswerAsync().ConfigureAwait(false);
75+
}
76+
break;
77+
default:
78+
response.SetStatus(404, "not find");
79+
await response.AnswerAsync().ConfigureAwait(false);
80+
break;
81+
}
82+
}
83+
}
84+
85+
static class DateHelper
86+
{
87+
static Timer m_timer;
88+
static DateHelper()
89+
{
90+
DateString = DateTime.UtcNow.ToGMTString();
91+
m_timer = new Timer((state) =>
92+
{
93+
DateString = DateTime.UtcNow.ToGMTString();
94+
}, null, 0, 1000);
95+
}
96+
97+
public static string DateString { get; private set; }
98+
}
99+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<OutputType>Exe</OutputType>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<InvariantGlobalization>true</InvariantGlobalization>
9+
<!--<PublishAot>true</PublishAot>-->
10+
<UserSecretsId>dotnet-TouchSocketWebApi-987c185f-10b1-455b-beb6-47d798a5a131</UserSecretsId>
11+
<ServerGarbageCollection>true</ServerGarbageCollection>
12+
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="TouchSocket.Http" Version="3.1.0" />
16+
</ItemGroup>
17+
</Project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<clear />
5+
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
6+
</packageSources>
7+
</configuration>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using System.Text;
2+
using System.Text.Json.Serialization;
3+
using TouchSocket.Core;
4+
using TouchSocket.Http;
5+
using TouchSocket.Rpc;
6+
using TouchSocket.Sockets;
7+
using TouchSocket.WebApi;
8+
9+
using HttpContent = TouchSocket.Http.HttpContent;
10+
11+
namespace TouchSocketWebApi;
12+
13+
public class Program
14+
{
15+
public static void Main(string[] args)
16+
{
17+
var builder = Host.CreateApplicationBuilder(args);
18+
19+
builder.Services.AddServiceHostedService<IHttpService, HttpService>(config =>
20+
{
21+
config.SetListenIPHosts(8080)
22+
.SetNoDelay(true)
23+
.SetMaxCount(1000000)
24+
.ConfigureContainer(a =>
25+
{
26+
a.AddConsoleLogger();
27+
a.AddRpcStore(store =>
28+
{
29+
store.RegisterServer<ApiServer>();
30+
});
31+
})
32+
.ConfigurePlugins(a =>
33+
{
34+
a.UseWebApi()
35+
.ConfigureConverter(converter =>
36+
{
37+
converter.Clear();
38+
converter.AddSystemTextJsonSerializerFormatter(options =>
39+
{
40+
options.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
41+
});
42+
});
43+
a.UseDefaultHttpServicePlugin();
44+
});
45+
});
46+
47+
var host = builder.Build();
48+
host.Run();
49+
}
50+
}
51+
52+
public partial class ApiServer : SingletonRpcServer
53+
{
54+
private readonly HttpContent m_contentPlaintext = new StringHttpContent("Hello, World!", Encoding.UTF8, $"text/plain");
55+
56+
public static MyJson MyJson { get; set; } = new MyJson() { Message = "Hello, World!" };
57+
58+
[Router("/plaintext")]
59+
[WebApi(Method = HttpMethodType.Get)]
60+
public async Task Plaintext(IWebApiCallContext callContext)
61+
{
62+
var response= callContext.HttpContext.Response;
63+
response.SetStatus(200, "success");
64+
response.Content= m_contentPlaintext;
65+
await response.AnswerAsync().ConfigureAwait(false);
66+
}
67+
68+
[Router("/json")]
69+
[WebApi(Method = HttpMethodType.Get)]
70+
public MyJson Json()
71+
{
72+
return MyJson;
73+
}
74+
}
75+
76+
[JsonSerializable(typeof(MyJson))]//ʵ¼ÊÀàÐÍ1
77+
internal partial class AppJsonSerializerContext : JsonSerializerContext
78+
{
79+
80+
}
81+
82+
public class MyJson
83+
{
84+
public string? Message { get; set; }
85+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Worker">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<InvariantGlobalization>true</InvariantGlobalization>
8+
<!--<PublishAot>true</PublishAot>-->
9+
<UserSecretsId>dotnet-TouchSocketWebApi-987c185f-10b1-452b-beb7-47d798a5a131</UserSecretsId>
10+
<ServerGarbageCollection>true</ServerGarbageCollection>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
15+
<PackageReference Include="TouchSocket.Hosting" Version="3.1.0" />
16+
<PackageReference Include="TouchSocket.WebApi" Version="3.1.0" />
17+
</ItemGroup>
18+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.Hosting.Lifetime": "Information"
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)