Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 1 | // Licensed to the Apache Software Foundation(ASF) under one |
| 2 | // or more contributor license agreements.See the NOTICE file |
| 3 | // distributed with this work for additional information |
| 4 | // regarding copyright ownership.The ASF licenses this file |
| 5 | // to you under the Apache License, Version 2.0 (the |
| 6 | // "License"); you may not use this file except in compliance |
| 7 | // with the License. You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, |
| 12 | // software distributed under the License is distributed on an |
| 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | // KIND, either express or implied. See the License for the |
| 15 | // specific language governing permissions and limitations |
| 16 | // under the License. |
| 17 | |
| 18 | using System; |
| 19 | using System.Collections.Generic; |
Mario Emmenlauer | 47e4923 | 2020-04-07 18:43:46 +0200 | [diff] [blame] | 20 | using System.Diagnostics; |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 21 | using System.IO; |
| 22 | using System.Linq; |
| 23 | using System.Net; |
| 24 | using System.Net.Security; |
| 25 | using System.Security.Cryptography.X509Certificates; |
| 26 | using System.Threading; |
| 27 | using System.Threading.Tasks; |
| 28 | using Microsoft.Extensions.Logging; |
Mario Emmenlauer | 47e4923 | 2020-04-07 18:43:46 +0200 | [diff] [blame] | 29 | using Microsoft.Extensions.DependencyInjection; |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 30 | using Thrift; |
| 31 | using Thrift.Protocol; |
| 32 | using Thrift.Transport; |
| 33 | using Thrift.Transport.Client; |
| 34 | using tutorial; |
| 35 | using shared; |
| 36 | |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 37 | #pragma warning disable IDE0063 // using |
| 38 | #pragma warning disable IDE0057 // substr |
| 39 | |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 40 | namespace Client |
| 41 | { |
| 42 | public class Program |
| 43 | { |
Jens Geyer | 2b2ea62 | 2021-04-09 22:55:11 +0200 | [diff] [blame^] | 44 | private static readonly ServiceCollection ServiceCollection = new(); |
Jens Geyer | b11f63c | 2019-03-14 21:12:38 +0100 | [diff] [blame] | 45 | private static ILogger Logger; |
Jens Geyer | eacd1d4 | 2019-11-20 19:03:14 +0100 | [diff] [blame] | 46 | private static readonly TConfiguration Configuration = null; // new TConfiguration() if needed |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 47 | |
| 48 | private static void DisplayHelp() |
| 49 | { |
| 50 | Logger.LogInformation(@" |
| 51 | Usage: |
Kengo Seki | bee4f2f | 2019-12-29 17:04:50 +0900 | [diff] [blame] | 52 | Client -help |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 53 | will diplay help information |
| 54 | |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 55 | Client -tr:<transport> -bf:<buffering> -pr:<protocol> [-mc:<numClients>] [-multiplex] |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 56 | will run client with specified arguments (tcp transport and binary protocol by default) and with 1 client |
| 57 | |
| 58 | Options: |
| 59 | -tr (transport): |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 60 | tcp - (default) tcp transport (localhost:9090) |
| 61 | tcptls - tcp tls transport (localhost:9090) |
| 62 | namedpipe - namedpipe transport (pipe "".test"") |
| 63 | http - http transport (http://localhost:9090) |
Kyle Smith | 7b94dd4 | 2019-03-23 17:26:56 +0100 | [diff] [blame] | 64 | |
| 65 | -bf (buffering): |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 66 | none - (default) no buffering |
| 67 | buffered - buffered transport |
| 68 | framed - framed transport |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 69 | |
| 70 | -pr (protocol): |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 71 | binary - (default) binary protocol |
| 72 | compact - compact protocol |
| 73 | json - json protocol |
| 74 | |
| 75 | -multiplex - adds multiplexed protocol |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 76 | |
| 77 | -mc (multiple clients): |
| 78 | <numClients> - number of multiple clients to connect to server (max 100, default 1) |
| 79 | |
| 80 | Sample: |
Kengo Seki | bee4f2f | 2019-12-29 17:04:50 +0900 | [diff] [blame] | 81 | Client -tr:tcp -pr:binary |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 82 | "); |
| 83 | } |
| 84 | |
| 85 | public static void Main(string[] args) |
| 86 | { |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 87 | args ??= Array.Empty<string>(); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 88 | |
Jens Geyer | b11f63c | 2019-03-14 21:12:38 +0100 | [diff] [blame] | 89 | ServiceCollection.AddLogging(logging => ConfigureLogging(logging)); |
Kengo Seki | bee4f2f | 2019-12-29 17:04:50 +0900 | [diff] [blame] | 90 | using (var serviceProvider = ServiceCollection.BuildServiceProvider()) |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 91 | { |
Kengo Seki | bee4f2f | 2019-12-29 17:04:50 +0900 | [diff] [blame] | 92 | Logger = serviceProvider.GetService<ILoggerFactory>().CreateLogger(nameof(Client)); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 93 | |
Kengo Seki | bee4f2f | 2019-12-29 17:04:50 +0900 | [diff] [blame] | 94 | if (args.Any(x => x.StartsWith("-help", StringComparison.OrdinalIgnoreCase))) |
| 95 | { |
| 96 | DisplayHelp(); |
| 97 | return; |
| 98 | } |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 99 | |
Kengo Seki | bee4f2f | 2019-12-29 17:04:50 +0900 | [diff] [blame] | 100 | Logger.LogInformation("Starting client..."); |
| 101 | |
| 102 | using (var source = new CancellationTokenSource()) |
| 103 | { |
| 104 | RunAsync(args, source.Token).GetAwaiter().GetResult(); |
| 105 | } |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | |
Jens Geyer | b11f63c | 2019-03-14 21:12:38 +0100 | [diff] [blame] | 109 | private static void ConfigureLogging(ILoggingBuilder logging) |
| 110 | { |
| 111 | logging.SetMinimumLevel(LogLevel.Trace); |
| 112 | logging.AddConsole(); |
| 113 | logging.AddDebug(); |
| 114 | } |
| 115 | |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 116 | private static async Task RunAsync(string[] args, CancellationToken cancellationToken) |
| 117 | { |
| 118 | var numClients = GetNumberOfClients(args); |
| 119 | |
| 120 | Logger.LogInformation($"Selected # of clients: {numClients}"); |
| 121 | |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 122 | var transport = GetTransport(args); |
| 123 | Logger.LogInformation($"Selected client transport: {transport}"); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 124 | |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 125 | var protocol = MakeProtocol( args, MakeTransport(args)); |
| 126 | Logger.LogInformation($"Selected client protocol: {GetProtocol(args)}"); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 127 | |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 128 | var mplex = GetMultiplex(args); |
| 129 | Logger.LogInformation("Multiplex " + (mplex ? "yes" : "no")); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 130 | |
| 131 | var tasks = new Task[numClients]; |
| 132 | for (int i = 0; i < numClients; i++) |
| 133 | { |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 134 | var task = RunClientAsync(protocol, mplex, cancellationToken); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 135 | tasks[i] = task; |
| 136 | } |
| 137 | |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 138 | Task.WaitAll(tasks,cancellationToken); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 139 | await Task.CompletedTask; |
| 140 | } |
| 141 | |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 142 | private static bool GetMultiplex(string[] args) |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 143 | { |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 144 | var mplex = args.FirstOrDefault(x => x.StartsWith("-multiplex")); |
| 145 | return !string.IsNullOrEmpty(mplex); |
| 146 | } |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 147 | |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 148 | private static Protocol GetProtocol(string[] args) |
| 149 | { |
| 150 | var protocol = args.FirstOrDefault(x => x.StartsWith("-pr"))?.Split(':')?[1]; |
| 151 | if (string.IsNullOrEmpty(protocol)) |
| 152 | return Protocol.Binary; |
| 153 | |
| 154 | protocol = protocol.Substring(0, 1).ToUpperInvariant() + protocol.Substring(1).ToLowerInvariant(); |
| 155 | if (Enum.TryParse(protocol, true, out Protocol selectedProtocol)) |
| 156 | return selectedProtocol; |
| 157 | else |
| 158 | return Protocol.Binary; |
| 159 | } |
| 160 | |
| 161 | private static Buffering GetBuffering(string[] args) |
| 162 | { |
| 163 | var buffering = args.FirstOrDefault(x => x.StartsWith("-bf"))?.Split(":")?[1]; |
| 164 | if (string.IsNullOrEmpty(buffering)) |
| 165 | return Buffering.None; |
| 166 | |
| 167 | buffering = buffering.Substring(0, 1).ToUpperInvariant() + buffering.Substring(1).ToLowerInvariant(); |
| 168 | if (Enum.TryParse<Buffering>(buffering, out var selectedBuffering)) |
| 169 | return selectedBuffering; |
| 170 | else |
| 171 | return Buffering.None; |
| 172 | } |
| 173 | |
| 174 | private static Transport GetTransport(string[] args) |
| 175 | { |
| 176 | var transport = args.FirstOrDefault(x => x.StartsWith("-tr"))?.Split(':')?[1]; |
| 177 | if (string.IsNullOrEmpty(transport)) |
| 178 | return Transport.Tcp; |
| 179 | |
| 180 | transport = transport.Substring(0, 1).ToUpperInvariant() + transport.Substring(1).ToLowerInvariant(); |
| 181 | if (Enum.TryParse(transport, true, out Transport selectedTransport)) |
| 182 | return selectedTransport; |
| 183 | else |
| 184 | return Transport.Tcp; |
| 185 | } |
| 186 | |
| 187 | |
| 188 | private static TTransport MakeTransport(string[] args) |
| 189 | { |
Kyle Smith | 7b94dd4 | 2019-03-23 17:26:56 +0100 | [diff] [blame] | 190 | // construct endpoint transport |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 191 | TTransport transport = null; |
| 192 | Transport selectedTransport = GetTransport(args); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 193 | { |
| 194 | switch (selectedTransport) |
| 195 | { |
| 196 | case Transport.Tcp: |
Jens Geyer | eacd1d4 | 2019-11-20 19:03:14 +0100 | [diff] [blame] | 197 | transport = new TSocketTransport(IPAddress.Loopback, 9090, Configuration); |
Kyle Smith | 7b94dd4 | 2019-03-23 17:26:56 +0100 | [diff] [blame] | 198 | break; |
| 199 | |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 200 | case Transport.NamedPipe: |
Jens Geyer | eacd1d4 | 2019-11-20 19:03:14 +0100 | [diff] [blame] | 201 | transport = new TNamedPipeTransport(".test", Configuration); |
Kyle Smith | 7b94dd4 | 2019-03-23 17:26:56 +0100 | [diff] [blame] | 202 | break; |
| 203 | |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 204 | case Transport.Http: |
Jens Geyer | eacd1d4 | 2019-11-20 19:03:14 +0100 | [diff] [blame] | 205 | transport = new THttpTransport(new Uri("http://localhost:9090"), Configuration); |
Kyle Smith | 7b94dd4 | 2019-03-23 17:26:56 +0100 | [diff] [blame] | 206 | break; |
| 207 | |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 208 | case Transport.TcpTls: |
Jens Geyer | eacd1d4 | 2019-11-20 19:03:14 +0100 | [diff] [blame] | 209 | transport = new TTlsSocketTransport(IPAddress.Loopback, 9090, Configuration, |
| 210 | GetCertificate(), CertValidator, LocalCertificateSelectionCallback); |
Kyle Smith | 7b94dd4 | 2019-03-23 17:26:56 +0100 | [diff] [blame] | 211 | break; |
| 212 | |
| 213 | default: |
| 214 | Debug.Assert(false, "unhandled case"); |
| 215 | break; |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
Kyle Smith | 7b94dd4 | 2019-03-23 17:26:56 +0100 | [diff] [blame] | 219 | // optionally add layered transport(s) |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 220 | Buffering selectedBuffering = GetBuffering(args); |
| 221 | switch (selectedBuffering) |
Kyle Smith | 7b94dd4 | 2019-03-23 17:26:56 +0100 | [diff] [blame] | 222 | { |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 223 | case Buffering.Buffered: |
| 224 | transport = new TBufferedTransport(transport); |
| 225 | break; |
Kyle Smith | 7b94dd4 | 2019-03-23 17:26:56 +0100 | [diff] [blame] | 226 | |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 227 | case Buffering.Framed: |
| 228 | transport = new TFramedTransport(transport); |
| 229 | break; |
Kyle Smith | 7b94dd4 | 2019-03-23 17:26:56 +0100 | [diff] [blame] | 230 | |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 231 | default: // layered transport(s) are optional |
| 232 | Debug.Assert(selectedBuffering == Buffering.None, "unhandled case"); |
| 233 | break; |
Kyle Smith | 7b94dd4 | 2019-03-23 17:26:56 +0100 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | return transport; |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | private static int GetNumberOfClients(string[] args) |
| 240 | { |
| 241 | var numClients = args.FirstOrDefault(x => x.StartsWith("-mc"))?.Split(':')?[1]; |
| 242 | |
| 243 | Logger.LogInformation($"Selected # of clients: {numClients}"); |
| 244 | |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 245 | if (int.TryParse(numClients, out int c) && (0 < c) && (c <= 100)) |
| 246 | return c; |
| 247 | else |
| 248 | return 1; |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | private static X509Certificate2 GetCertificate() |
| 252 | { |
| 253 | // due to files location in net core better to take certs from top folder |
| 254 | var certFile = GetCertPath(Directory.GetParent(Directory.GetCurrentDirectory())); |
| 255 | return new X509Certificate2(certFile, "ThriftTest"); |
| 256 | } |
| 257 | |
| 258 | private static string GetCertPath(DirectoryInfo di, int maxCount = 6) |
| 259 | { |
| 260 | var topDir = di; |
| 261 | var certFile = |
| 262 | topDir.EnumerateFiles("ThriftTest.pfx", SearchOption.AllDirectories) |
| 263 | .FirstOrDefault(); |
| 264 | if (certFile == null) |
| 265 | { |
| 266 | if (maxCount == 0) |
| 267 | throw new FileNotFoundException("Cannot find file in directories"); |
| 268 | return GetCertPath(di.Parent, maxCount - 1); |
| 269 | } |
| 270 | |
| 271 | return certFile.FullName; |
| 272 | } |
| 273 | |
| 274 | private static X509Certificate LocalCertificateSelectionCallback(object sender, |
| 275 | string targetHost, X509CertificateCollection localCertificates, |
| 276 | X509Certificate remoteCertificate, string[] acceptableIssuers) |
| 277 | { |
| 278 | return GetCertificate(); |
| 279 | } |
| 280 | |
| 281 | private static bool CertValidator(object sender, X509Certificate certificate, |
| 282 | X509Chain chain, SslPolicyErrors sslPolicyErrors) |
| 283 | { |
| 284 | return true; |
| 285 | } |
| 286 | |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 287 | private static TProtocol MakeProtocol(string[] args, TTransport transport) |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 288 | { |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 289 | Protocol selectedProtocol = GetProtocol(args); |
Jens Geyer | 2b2ea62 | 2021-04-09 22:55:11 +0200 | [diff] [blame^] | 290 | return selectedProtocol switch |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 291 | { |
Jens Geyer | 2b2ea62 | 2021-04-09 22:55:11 +0200 | [diff] [blame^] | 292 | Protocol.Binary => new TBinaryProtocol(transport), |
| 293 | Protocol.Compact => new TCompactProtocol(transport), |
| 294 | Protocol.Json => new TJsonProtocol(transport), |
| 295 | _ => throw new Exception("unhandled protocol"), |
| 296 | }; |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 297 | } |
| 298 | |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 299 | private static async Task RunClientAsync(TProtocol protocol, bool multiplex, CancellationToken cancellationToken) |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 300 | { |
| 301 | try |
| 302 | { |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 303 | try |
| 304 | { |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 305 | if( multiplex) |
| 306 | protocol = new TMultiplexedProtocol(protocol, nameof(Calculator)); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 307 | |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 308 | var client = new Calculator.Client(protocol); |
| 309 | await ExecuteCalculatorClientOperations(client, cancellationToken); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 310 | } |
| 311 | catch (Exception ex) |
| 312 | { |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 313 | Logger.LogError(ex.ToString()); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 314 | } |
| 315 | finally |
| 316 | { |
| 317 | protocol.Transport.Close(); |
| 318 | } |
| 319 | } |
| 320 | catch (TApplicationException x) |
| 321 | { |
| 322 | Logger.LogError(x.ToString()); |
| 323 | } |
| 324 | } |
| 325 | |
Jens Geyer | 0d12832 | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 326 | private static async Task ExecuteCalculatorClientOperations( Calculator.Client client, CancellationToken cancellationToken) |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 327 | { |
| 328 | await client.OpenTransportAsync(cancellationToken); |
| 329 | |
| 330 | // Async version |
| 331 | |
Jens Geyer | 2b2ea62 | 2021-04-09 22:55:11 +0200 | [diff] [blame^] | 332 | Logger.LogInformation($"{client.ClientId} Ping()"); |
| 333 | await client.ping(cancellationToken); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 334 | |
Jens Geyer | 2b2ea62 | 2021-04-09 22:55:11 +0200 | [diff] [blame^] | 335 | Logger.LogInformation($"{client.ClientId} Add(1,1)"); |
| 336 | var sum = await client.add(1, 1, cancellationToken); |
| 337 | Logger.LogInformation($"{client.ClientId} Add(1,1)={sum}"); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 338 | |
| 339 | var work = new Work |
| 340 | { |
| 341 | Op = Operation.DIVIDE, |
| 342 | Num1 = 1, |
| 343 | Num2 = 0 |
| 344 | }; |
| 345 | |
| 346 | try |
| 347 | { |
Jens Geyer | 2b2ea62 | 2021-04-09 22:55:11 +0200 | [diff] [blame^] | 348 | Logger.LogInformation($"{client.ClientId} Calculate(1)"); |
| 349 | await client.calculate(1, work, cancellationToken); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 350 | Logger.LogInformation($"{client.ClientId} Whoa we can divide by 0"); |
| 351 | } |
| 352 | catch (InvalidOperation io) |
| 353 | { |
| 354 | Logger.LogInformation($"{client.ClientId} Invalid operation: " + io); |
| 355 | } |
| 356 | |
| 357 | work.Op = Operation.SUBTRACT; |
| 358 | work.Num1 = 15; |
| 359 | work.Num2 = 10; |
| 360 | |
| 361 | try |
| 362 | { |
Jens Geyer | 2b2ea62 | 2021-04-09 22:55:11 +0200 | [diff] [blame^] | 363 | Logger.LogInformation($"{client.ClientId} Calculate(1)"); |
| 364 | var diff = await client.calculate(1, work, cancellationToken); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 365 | Logger.LogInformation($"{client.ClientId} 15-10={diff}"); |
| 366 | } |
| 367 | catch (InvalidOperation io) |
| 368 | { |
| 369 | Logger.LogInformation($"{client.ClientId} Invalid operation: " + io); |
| 370 | } |
| 371 | |
Jens Geyer | 2b2ea62 | 2021-04-09 22:55:11 +0200 | [diff] [blame^] | 372 | Logger.LogInformation($"{client.ClientId} GetStruct(1)"); |
| 373 | var log = await client.getStruct(1, cancellationToken); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 374 | Logger.LogInformation($"{client.ClientId} Check log: {log.Value}"); |
| 375 | |
Jens Geyer | 2b2ea62 | 2021-04-09 22:55:11 +0200 | [diff] [blame^] | 376 | Logger.LogInformation($"{client.ClientId} Zip() with delay 100mc on server side"); |
| 377 | await client.zip(cancellationToken); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 378 | } |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 379 | |
| 380 | |
| 381 | private enum Transport |
| 382 | { |
| 383 | Tcp, |
| 384 | NamedPipe, |
| 385 | Http, |
| 386 | TcpBuffered, |
| 387 | Framed, |
| 388 | TcpTls |
| 389 | } |
| 390 | |
| 391 | private enum Protocol |
| 392 | { |
| 393 | Binary, |
| 394 | Compact, |
| 395 | Json, |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 396 | } |
Kyle Smith | 7b94dd4 | 2019-03-23 17:26:56 +0100 | [diff] [blame] | 397 | |
| 398 | private enum Buffering |
| 399 | { |
| 400 | None, |
| 401 | Buffered, |
| 402 | Framed |
| 403 | } |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 404 | } |
| 405 | } |