THRIFT-5902 Add net10 support
Client: netstd
Patch: Jens Geyer
diff --git a/tutorial/netstd/Client/Client.csproj b/tutorial/netstd/Client/Client.csproj
index a18d3d0..64357d1 100644
--- a/tutorial/netstd/Client/Client.csproj
+++ b/tutorial/netstd/Client/Client.csproj
@@ -19,7 +19,7 @@
-->
<PropertyGroup>
- <TargetFramework>net9.0</TargetFramework>
+ <TargetFramework>net10.0</TargetFramework>
<LangVersion>latestMajor</LangVersion>
<AssemblyName>Client</AssemblyName>
<PackageId>Client</PackageId>
diff --git a/tutorial/netstd/Client/Program.cs b/tutorial/netstd/Client/Program.cs
index 93175fd..082e767 100644
--- a/tutorial/netstd/Client/Program.cs
+++ b/tutorial/netstd/Client/Program.cs
@@ -115,16 +115,20 @@
{
var numClients = GetNumberOfClients(args);
- Logger.LogInformation("Selected # of clients: {numClients}", numClients);
+ if (Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation("Selected # of clients: {numClients}", numClients);
var transport = GetTransport(args);
- Logger.LogInformation("Selected client transport: {transport}", transport);
+ if (Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation("Selected client transport: {transport}", transport);
var protocol = MakeProtocol( args, MakeTransport(args));
- Logger.LogInformation("Selected client protocol: {GetProtocol(args)}", GetProtocol(args));
+ if (Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation("Selected client protocol: {GetProtocol(args)}", GetProtocol(args));
var mplex = GetMultiplex(args);
- Logger.LogInformation("Multiplex {mplex}", mplex);
+ if (Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation("Multiplex {mplex}", mplex);
var tasks = new Task[numClients];
for (int i = 0; i < numClients; i++)
@@ -133,8 +137,7 @@
tasks[i] = task;
}
- Task.WaitAll(tasks,cancellationToken);
- await Task.CompletedTask;
+ Task.WaitAll(tasks, cancellationToken);
}
private static bool GetMultiplex(string[] args)
@@ -238,7 +241,8 @@
{
var numClients = args.FirstOrDefault(x => x.StartsWith("-mc"))?.Split(':').Skip(1).Take(1).FirstOrDefault();
- Logger.LogInformation("Selected # of clients: {numClients}", numClients);
+ if (Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation("Selected # of clients: {numClients}", numClients);
if (int.TryParse(numClients, out int c) && (0 < c) && (c <= 100))
return c;
@@ -258,7 +262,8 @@
}
else
{
- Logger.LogError("Root path of {path} not found", Directory.GetCurrentDirectory());
+ if (Logger.IsEnabled(LogLevel.Error))
+ Logger.LogError("Root path of {path} not found", Directory.GetCurrentDirectory());
throw new Exception($"Root path of {Directory.GetCurrentDirectory()} not found");
}
}
@@ -315,7 +320,8 @@
}
catch (Exception ex)
{
- Logger.LogError("{ex}",ex);
+ if (Logger.IsEnabled(LogLevel.Error))
+ Logger.LogError("{ex}",ex);
}
finally
{
@@ -324,7 +330,8 @@
}
catch (TApplicationException x)
{
- Logger.LogError("{x}",x);
+ if (Logger.IsEnabled(LogLevel.Error))
+ Logger.LogError("{x}",x);
}
}
@@ -332,14 +339,18 @@
{
await client.OpenTransportAsync(cancellationToken);
- // Async version
+ if (Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation("{client.ClientId} Ping()", client.ClientId);
- Logger.LogInformation("{client.ClientId} Ping()", client.ClientId);
await client.ping(cancellationToken);
- Logger.LogInformation("{client.ClientId} Add(1,1)", client.ClientId);
+ if (Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation("{client.ClientId} Add(1,1)", client.ClientId);
+
var sum = await client.add(1, 1, cancellationToken);
- Logger.LogInformation("{client.ClientId} Add(1,1)={sum}", client.ClientId, sum);
+
+ if (Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation("{client.ClientId} Add(1,1)={sum}", client.ClientId, sum);
var work = new Work
{
@@ -350,13 +361,18 @@
try
{
- Logger.LogInformation("{client.ClientId} Calculate(1)", client.ClientId);
+ if (Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation("{client.ClientId} Calculate(1)", client.ClientId);
+
await client.calculate(1, work, cancellationToken);
- Logger.LogInformation("{client.ClientId} Whoa we can divide by 0", client.ClientId);
+
+ if (Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation("{client.ClientId} Whoa we can divide by 0", client.ClientId);
}
catch (InvalidOperation io)
{
- Logger.LogInformation("{client.ClientId} Invalid operation: {io}", client.ClientId, io);
+ if (Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation("{client.ClientId} Invalid operation: {io}", client.ClientId, io);
}
work.Op = Operation.SUBTRACT;
@@ -365,20 +381,31 @@
try
{
- Logger.LogInformation("{client.ClientId} Calculate(1)", client.ClientId);
+ if (Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation("{client.ClientId} Calculate(1)", client.ClientId);
+
var diff = await client.calculate(1, work, cancellationToken);
- Logger.LogInformation("{client.ClientId} 15-10={diff}", client.ClientId, diff);
+
+ if (Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation("{client.ClientId} 15-10={diff}", client.ClientId, diff);
}
catch (InvalidOperation io)
{
- Logger.LogInformation("{client.ClientId} Invalid operation: {io}", client.ClientId, io);
+ if (Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation("{client.ClientId} Invalid operation: {io}", client.ClientId, io);
}
- Logger.LogInformation("{client.ClientId} GetStruct(1)", client.ClientId);
- var log = await client.getStruct(1, cancellationToken);
- Logger.LogInformation("{client.ClientId} Check log: {log.Value}", client.ClientId, log.Value);
+ if (Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation("{client.ClientId} GetStruct(1)", client.ClientId);
- Logger.LogInformation("{client.ClientId} Zip() with delay 100mc on server side", client.ClientId);
+ var log = await client.getStruct(1, cancellationToken);
+
+ if (Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation("{client.ClientId} Check log: {log.Value}", client.ClientId, log.Value);
+
+ if (Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation("{client.ClientId} Zip() with delay 100mc on server side", client.ClientId);
+
await client.zip(cancellationToken);
}
diff --git a/tutorial/netstd/Interfaces/Interfaces.csproj b/tutorial/netstd/Interfaces/Interfaces.csproj
index 7ebe5c7..122866c 100644
--- a/tutorial/netstd/Interfaces/Interfaces.csproj
+++ b/tutorial/netstd/Interfaces/Interfaces.csproj
@@ -19,7 +19,7 @@
-->
<PropertyGroup>
- <TargetFramework>net9.0</TargetFramework>
+ <TargetFramework>net10.0</TargetFramework>
<AssemblyName>Interfaces</AssemblyName>
<PackageId>Interfaces</PackageId>
<Version>0.23.0.0</Version>
@@ -42,8 +42,8 @@
<Exec Condition="'$(OS)' == 'Windows_NT'" Command="where thrift" ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="PathToThrift" />
</Exec>
- <Exec Condition="Exists('$(PathToThrift)')" Command="$(PathToThrift) -out $(ProjectDir) -gen netstd:wcf,union,serial,net9 -r ./../../tutorial.thrift" />
- <Exec Condition="Exists('thrift')" Command="thrift -out $(ProjectDir) -gen netstd:wcf,union,serial,net9 -r ./../../tutorial.thrift" />
- <Exec Condition="Exists('./../../../compiler/cpp/thrift')" Command="./../../../compiler/cpp/thrift -out $(ProjectDir) -gen netstd:wcf,union,serial,net9 -r ./../../tutorial.thrift" />
+ <Exec Condition="Exists('$(PathToThrift)')" Command="$(PathToThrift) -out $(ProjectDir) -gen netstd:wcf,union,serial,net10 -r ./../../tutorial.thrift" />
+ <Exec Condition="Exists('thrift')" Command="thrift -out $(ProjectDir) -gen netstd:wcf,union,serial,net10 -r ./../../tutorial.thrift" />
+ <Exec Condition="Exists('./../../../compiler/cpp/thrift')" Command="./../../../compiler/cpp/thrift -out $(ProjectDir) -gen netstd:wcf,union,serial,net10 -r ./../../tutorial.thrift" />
</Target>
</Project>
diff --git a/tutorial/netstd/Server/Program.cs b/tutorial/netstd/Server/Program.cs
index a3b12fc..004ea77 100644
--- a/tutorial/netstd/Server/Program.cs
+++ b/tutorial/netstd/Server/Program.cs
@@ -19,6 +19,7 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using shared;
using System;
@@ -224,13 +225,14 @@
try
{
- Logger.LogInformation(
- "TSimpleAsyncServer with \n{transport} transport\n{buffering} buffering\nmultiplex = {multiplex}\n{protocol} protocol",
- transport,
- buffering,
- multiplex ? "yes" : "no",
- protocol
- );
+ if( Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation(
+ "TSimpleAsyncServer with \n{transport} transport\n{buffering} buffering\nmultiplex = {multiplex}\n{protocol} protocol",
+ transport,
+ buffering,
+ multiplex ? "yes" : "no",
+ protocol
+ );
var server = new TSimpleAsyncServer(
itProcessorFactory: new TSingletonProcessorFactory(processor),
@@ -247,7 +249,8 @@
}
catch (Exception x)
{
- Logger.LogInformation("{x}",x);
+ if (Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation("{x}",x);
}
}
@@ -315,13 +318,16 @@
.AddEnvironmentVariables(prefix: "ASPNETCORE_")
.Build();
- var host = new WebHostBuilder()
- .UseConfiguration(config)
- .UseKestrel()
- .UseUrls("http://localhost:9090")
- .UseContentRoot(Directory.GetCurrentDirectory())
- .UseStartup<Startup>()
- .ConfigureLogging((ctx,logging) => LoggingHelper.ConfigureLogging(logging))
+ var host = new HostBuilder().
+ ConfigureWebHost(webhostbuilder => {
+ webhostbuilder.UseConfiguration(config)
+ .UseUrls("http://localhost:9090")
+ .UseContentRoot(Directory.GetCurrentDirectory())
+ .UseStartup<Startup>()
+ .UseKestrel()
+ .ConfigureLogging((ctx, logging) => LoggingHelper.ConfigureLogging(logging))
+ ;
+ })
.Build();
Logger.LogTrace("test");
@@ -373,25 +379,27 @@
public async Task<SharedStruct> getStruct(int key,
CancellationToken cancellationToken)
{
- Logger.LogInformation("GetStruct({key})", key);
- return await Task.FromResult(_log[key]);
+ if (Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation("GetStruct({key})", key);
+ return _log[key];
}
public async Task ping(CancellationToken cancellationToken)
{
Logger.LogInformation("Ping()");
- await Task.CompletedTask;
}
public async Task<int> add(int num1, int num2, CancellationToken cancellationToken)
{
- Logger.LogInformation("Add({num1},{num2})", num1, num2);
- return await Task.FromResult(num1 + num2);
+ if (Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation("Add({num1},{num2})", num1, num2);
+ return num1 + num2;
}
public async Task<int> calculate(int logid, Work? w, CancellationToken cancellationToken)
{
- Logger.LogInformation("Calculate({logid}, [{w.Op},{w.Num1},{w.Num2}])", logid, w?.Op, w?.Num1, w?.Num2);
+ if (Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation("Calculate({logid}, [{w.Op},{w.Num1},{w.Num2}])", logid, w?.Op, w?.Num1, w?.Num2);
int val;
switch (w?.Op)
@@ -441,8 +449,7 @@
};
_log[logid] = entry;
-
- return await Task.FromResult(val);
+ return val;
}
public async Task zip(CancellationToken cancellationToken)
@@ -456,12 +463,14 @@
{
public async Task<SharedStruct> getStruct(int key, CancellationToken cancellationToken)
{
- Logger.LogInformation("GetStruct({key})", key);
- return await Task.FromResult(new SharedStruct()
+ if (Logger.IsEnabled(LogLevel.Information))
+ Logger.LogInformation("GetStruct({key})", key);
+
+ return new SharedStruct()
{
Key = key,
Value = "GetStruct"
- });
+ };
}
}
}
diff --git a/tutorial/netstd/Server/Server.csproj b/tutorial/netstd/Server/Server.csproj
index 940b931..805ee0a 100644
--- a/tutorial/netstd/Server/Server.csproj
+++ b/tutorial/netstd/Server/Server.csproj
@@ -19,7 +19,7 @@
-->
<PropertyGroup>
- <TargetFramework>net9.0</TargetFramework>
+ <TargetFramework>net10.0</TargetFramework>
<LangVersion>latestMajor</LangVersion>
<AssemblyName>Server</AssemblyName>
<PackageId>Server</PackageId>