THRIFT-5053: Fix the netstd tutorial console logging and README
Client: netstd
Patch: Kengo Seki
This closes #1970
diff --git a/tutorial/netstd/Client/Program.cs b/tutorial/netstd/Client/Program.cs
index 857b3e8..eefccf7 100644
--- a/tutorial/netstd/Client/Program.cs
+++ b/tutorial/netstd/Client/Program.cs
@@ -46,10 +46,10 @@
{
Logger.LogInformation(@"
Usage:
- Client.exe -help
+ Client -help
will diplay help information
- Client.exe -tr:<transport> -bf:<buffering> -pr:<protocol> -mc:<numClients>
+ Client -tr:<transport> -bf:<buffering> -pr:<protocol> -mc:<numClients>
will run client with specified arguments (tcp transport and binary protocol by default) and with 1 client
Options:
@@ -74,7 +74,7 @@
<numClients> - number of multiple clients to connect to server (max 100, default 1)
Sample:
- Client.exe -tr:tcp -p:binary
+ Client -tr:tcp -pr:binary
");
}
@@ -83,19 +83,22 @@
args = args ?? new string[0];
ServiceCollection.AddLogging(logging => ConfigureLogging(logging));
- Logger = ServiceCollection.BuildServiceProvider().GetService<ILoggerFactory>().CreateLogger(nameof(Client));
-
- if (args.Any(x => x.StartsWith("-help", StringComparison.OrdinalIgnoreCase)))
+ using (var serviceProvider = ServiceCollection.BuildServiceProvider())
{
- DisplayHelp();
- return;
- }
+ Logger = serviceProvider.GetService<ILoggerFactory>().CreateLogger(nameof(Client));
- Logger.LogInformation("Starting client...");
+ if (args.Any(x => x.StartsWith("-help", StringComparison.OrdinalIgnoreCase)))
+ {
+ DisplayHelp();
+ return;
+ }
- using (var source = new CancellationTokenSource())
- {
- RunAsync(args, source.Token).GetAwaiter().GetResult();
+ Logger.LogInformation("Starting client...");
+
+ using (var source = new CancellationTokenSource())
+ {
+ RunAsync(args, source.Token).GetAwaiter().GetResult();
+ }
}
}
diff --git a/tutorial/netstd/README.md b/tutorial/netstd/README.md
index 297f4ee..a49fb47 100644
--- a/tutorial/netstd/README.md
+++ b/tutorial/netstd/README.md
@@ -13,13 +13,13 @@
# How to run
-Depending on the platform, the name of the generated executables will vary. On Linux, it is just "client" or "server", on Windows it is "Client.exe" and "Server.exe". In the following, we use the abbreviated form "Client" and "Server".
+Depending on the platform, the name of the generated executables will vary. On Linux, it is just "Client" or "Server", on Windows it is "Client.exe" and "Server.exe". In the following, we use the abbreviated form "Client" and "Server".
- build
- go to folder (Client/Server)
- run the generated executables: server first, then client from a second console
-#Known issues
+# Known issues
- In trace logging mode you can see some not important internal exceptions
# Running of samples
@@ -29,10 +29,10 @@
Usage:
- Server -h
+ Server -help
will diplay help information
- Server -tr:<transport> -pr:<protocol>
+ Server -tr:<transport> -pr:<protocol>
will run server with specified arguments (tcp transport and binary protocol by default)
Options:
@@ -52,7 +52,8 @@
binary - (default) binary protocol will be used
compact - compact protocol will be used
json - json protocol will be used
-
+ multiplexed - multiplexed protocol will be used
+
Sample:
Server -tr:tcp
@@ -68,7 +69,7 @@
Usage:
- Client -h
+ Client -help
will diplay help information
Client -tr:<transport> -pr:<protocol> -mc:<numClients>
@@ -91,7 +92,8 @@
binary - (default) binary protocol will be used
compact - compact protocol will be used
json - json protocol will be used
-
+ multiplexed - multiplexed protocol will be used
+
-mc (multiple clients):
<numClients> - number of multiple clients to connect to server (max 100, default 1)
@@ -237,16 +239,10 @@
val = work.Num1 * work.Num2
elif work.Op == Operation.Divide:
if work.Num2 == 0:
- x = InvalidOperation()
- x.WhatOp = work.Op
- x.Why = 'Cannot divide by 0'
- raise x
+ raise InvalidOperation(work.Op, 'Cannot divide by 0')
val = work.Num1 / work.Num2
else:
- x = InvalidOperation()
- x.WhatOp = work.Op
- x.Why = 'Invalid operation'
- raise x
+ raise InvalidOperation(work.Op, 'Invalid operation')
log = SharedStruct()
log.Key = logid
diff --git a/tutorial/netstd/Server/Program.cs b/tutorial/netstd/Server/Program.cs
index c1e0cb3..3181e8e 100644
--- a/tutorial/netstd/Server/Program.cs
+++ b/tutorial/netstd/Server/Program.cs
@@ -51,26 +51,28 @@
args = args ?? new string[0];
ServiceCollection.AddLogging(logging => ConfigureLogging(logging));
- Logger = ServiceCollection.BuildServiceProvider().GetService<ILoggerFactory>().CreateLogger(nameof(Server));
-
-
- if (args.Any(x => x.StartsWith("-help", StringComparison.OrdinalIgnoreCase)))
+ using (var serviceProvider = ServiceCollection.BuildServiceProvider())
{
- DisplayHelp();
- return;
+ Logger = serviceProvider.GetService<ILoggerFactory>().CreateLogger(nameof(Server));
+
+ if (args.Any(x => x.StartsWith("-help", StringComparison.OrdinalIgnoreCase)))
+ {
+ DisplayHelp();
+ return;
+ }
+
+ using (var source = new CancellationTokenSource())
+ {
+ RunAsync(args, source.Token).GetAwaiter().GetResult();
+
+ Logger.LogInformation("Press any key to stop...");
+
+ Console.ReadLine();
+ source.Cancel();
+ }
+
+ Logger.LogInformation("Server stopped");
}
-
- using (var source = new CancellationTokenSource())
- {
- RunAsync(args, source.Token).GetAwaiter().GetResult();
-
- Logger.LogInformation("Press any key to stop...");
-
- Console.ReadLine();
- source.Cancel();
- }
-
- Logger.LogInformation("Server stopped");
}
private static void ConfigureLogging(ILoggingBuilder logging)
@@ -84,10 +86,10 @@
{
Logger.LogInformation(@"
Usage:
- Server.exe -help
+ Server -help
will diplay help information
- Server.exe -tr:<transport> -bf:<buffering> -pr:<protocol>
+ Server -tr:<transport> -bf:<buffering> -pr:<protocol>
will run server with specified arguments (tcp transport, no buffering, and binary protocol by default)
Options:
@@ -109,7 +111,7 @@
multiplexed - multiplexed protocol will be used
Sample:
- Server.exe -tr:tcp
+ Server -tr:tcp
");
}
diff --git a/tutorial/netstd/build.sh b/tutorial/netstd/build.sh
old mode 100644
new mode 100755