diff options
author | Kengo Seki <sekikn@apache.org> | 2019-12-29 17:04:50 +0900 |
---|---|---|
committer | Jens Geyer <jensg@apache.org> | 2020-01-11 00:52:42 +0100 |
commit | bee4f2fd69db32621addd9353ab0aa2e2ba94349 (patch) | |
tree | a8e40cb7416ee977d7fb42c095348bb7d04cff5a /tutorial/netstd | |
parent | 30ac2598e84928d9af7066b5d3248b7aea4376b2 (diff) | |
download | thrift-bee4f2fd69db32621addd9353ab0aa2e2ba94349.tar.gz |
THRIFT-5053: Fix the netstd tutorial console logging and README
Client: netstd
Patch: Kengo Seki
This closes #1970
Diffstat (limited to 'tutorial/netstd')
-rw-r--r-- | tutorial/netstd/Client/Program.cs | 29 | ||||
-rw-r--r-- | tutorial/netstd/README.md | 26 | ||||
-rw-r--r-- | tutorial/netstd/Server/Program.cs | 36 | ||||
-rwxr-xr-x[-rw-r--r--] | tutorial/netstd/build.sh | 0 |
4 files changed, 46 insertions, 45 deletions
diff --git a/tutorial/netstd/Client/Program.cs b/tutorial/netstd/Client/Program.cs index 857b3e808..eefccf703 100644 --- a/tutorial/netstd/Client/Program.cs +++ b/tutorial/netstd/Client/Program.cs @@ -46,10 +46,10 @@ namespace Client { 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 @@ Options: <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 @@ Sample: 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)); + + if (args.Any(x => x.StartsWith("-help", StringComparison.OrdinalIgnoreCase))) + { + DisplayHelp(); + return; + } - Logger.LogInformation("Starting client..."); + Logger.LogInformation("Starting client..."); - using (var source = new CancellationTokenSource()) - { - RunAsync(args, source.Token).GetAwaiter().GetResult(); + using (var source = new CancellationTokenSource()) + { + RunAsync(args, source.Token).GetAwaiter().GetResult(); + } } } diff --git a/tutorial/netstd/README.md b/tutorial/netstd/README.md index 297f4ee32..a49fb474b 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 @@ On machines that do not have the SDK installed, you need to install the NET Core 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 @@ Options: 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 @@ Sample: Usage: - Client -h + Client -help will diplay help information Client -tr:<transport> -pr:<protocol> -mc:<numClients> @@ -91,7 +92,8 @@ Options: 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 @@ class CalculatorHandler: 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 c1e0cb3ec..3181e8e33 100644 --- a/tutorial/netstd/Server/Program.cs +++ b/tutorial/netstd/Server/Program.cs @@ -51,26 +51,28 @@ namespace Server args = args ?? new string[0]; ServiceCollection.AddLogging(logging => ConfigureLogging(logging)); - Logger = ServiceCollection.BuildServiceProvider().GetService<ILoggerFactory>().CreateLogger(nameof(Server)); + using (var serviceProvider = ServiceCollection.BuildServiceProvider()) + { + Logger = serviceProvider.GetService<ILoggerFactory>().CreateLogger(nameof(Server)); + if (args.Any(x => x.StartsWith("-help", StringComparison.OrdinalIgnoreCase))) + { + DisplayHelp(); + return; + } - if (args.Any(x => x.StartsWith("-help", StringComparison.OrdinalIgnoreCase))) - { - DisplayHelp(); - return; - } + using (var source = new CancellationTokenSource()) + { + RunAsync(args, source.Token).GetAwaiter().GetResult(); - using (var source = new CancellationTokenSource()) - { - RunAsync(args, source.Token).GetAwaiter().GetResult(); + Logger.LogInformation("Press any key to stop..."); - Logger.LogInformation("Press any key to stop..."); + Console.ReadLine(); + source.Cancel(); + } - Console.ReadLine(); - source.Cancel(); + Logger.LogInformation("Server stopped"); } - - Logger.LogInformation("Server stopped"); } private static void ConfigureLogging(ILoggingBuilder logging) @@ -84,10 +86,10 @@ namespace Server { 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 @@ Options: 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 index c97e310f0..c97e310f0 100644..100755 --- a/tutorial/netstd/build.sh +++ b/tutorial/netstd/build.sh |