| 336 | } |
| 337 | |
| 338 | private static async Task ExecuteCalculatorClientOperations( Calculator.Client client, CancellationToken cancellationToken) |
| 339 | { |
| 340 | await client.OpenTransportAsync(cancellationToken); |
| 341 | |
| 342 | if (Logger.IsEnabled(LogLevel.Information)) |
| 343 | Logger.LogInformation("{client.ClientId} Ping()", client.ClientId); |
| 344 | |
| 345 | await client.ping(cancellationToken); |
| 346 | |
| 347 | if (Logger.IsEnabled(LogLevel.Information)) |
| 348 | Logger.LogInformation("{client.ClientId} Add(1,1)", client.ClientId); |
| 349 | |
| 350 | var sum = await client.add(1, 1, cancellationToken); |
| 351 | |
| 352 | if (Logger.IsEnabled(LogLevel.Information)) |
| 353 | Logger.LogInformation("{client.ClientId} Add(1,1)={sum}", client.ClientId, sum); |
| 354 | |
| 355 | var work = new Work |
| 356 | { |
| 357 | Op = Operation.DIVIDE, |
| 358 | Num1 = 1, |
| 359 | Num2 = 0 |
| 360 | }; |
| 361 | |
| 362 | try |
| 363 | { |
| 364 | if (Logger.IsEnabled(LogLevel.Information)) |
| 365 | Logger.LogInformation("{client.ClientId} Calculate(1)", client.ClientId); |
| 366 | |
| 367 | await client.calculate(1, work, cancellationToken); |
| 368 | |
| 369 | if (Logger.IsEnabled(LogLevel.Information)) |
| 370 | Logger.LogInformation("{client.ClientId} Whoa we can divide by 0", client.ClientId); |
| 371 | } |
| 372 | catch (InvalidOperation io) |
| 373 | { |
| 374 | if (Logger.IsEnabled(LogLevel.Information)) |
| 375 | Logger.LogInformation("{client.ClientId} Invalid operation: {io}", client.ClientId, io); |
| 376 | } |
| 377 | |
| 378 | work.Op = Operation.SUBTRACT; |
| 379 | work.Num1 = 15; |
| 380 | work.Num2 = 10; |
| 381 | |
| 382 | try |
| 383 | { |
| 384 | if (Logger.IsEnabled(LogLevel.Information)) |
| 385 | Logger.LogInformation("{client.ClientId} Calculate(1)", client.ClientId); |
| 386 | |
| 387 | var diff = await client.calculate(1, work, cancellationToken); |
| 388 | |
| 389 | if (Logger.IsEnabled(LogLevel.Information)) |
| 390 | Logger.LogInformation("{client.ClientId} 15-10={diff}", client.ClientId, diff); |
| 391 | } |
| 392 | catch (InvalidOperation io) |
| 393 | { |
| 394 | if (Logger.IsEnabled(LogLevel.Information)) |
| 395 | Logger.LogInformation("{client.ClientId} Invalid operation: {io}", client.ClientId, io); |