private static async Task ExecuteCalculatorClientOperations(CancellationToken cancellationToken, Calculator.Client client) { await client.OpenTransportAsync(cancellationToken); // Async version Logger.LogInformation($"{client.ClientId} PingAsync()"); await client.pingAsync(cancellationToken); Logger.LogInformation($"{client.ClientId} AddAsync(1,1)"); var sum = await client.addAsync(1, 1, cancellationToken); Logger.LogInformation($"{client.ClientId} AddAsync(1,1)={sum}"); var work = new Work { Op = Operation.DIVIDE, Num1 = 1, Num2 = 0 }; try { Logger.LogInformation($"{client.ClientId} CalculateAsync(1)"); await client.calculateAsync(1, work, cancellationToken); Logger.LogInformation($"{client.ClientId} Whoa we can divide by 0"); } catch (InvalidOperation io) { Logger.LogInformation($"{client.ClientId} Invalid operation: " + io); } work.Op = Operation.SUBTRACT; work.Num1 = 15; work.Num2 = 10; try { Logger.LogInformation($"{client.ClientId} CalculateAsync(1)"); var diff = await client.calculateAsync(1, work, cancellationToken); Logger.LogInformation($"{client.ClientId} 15-10={diff}"); } catch (InvalidOperation io) { Logger.LogInformation($"{client.ClientId} Invalid operation: " + io); } Logger.LogInformation($"{client.ClientId} GetStructAsync(1)"); var log = await client.getStructAsync(1, cancellationToken); Logger.LogInformation($"{client.ClientId} Check log: {log.Value}"); Logger.LogInformation($"{client.ClientId} ZipAsync() with delay 100mc on server side"); await client.zipAsync(cancellationToken); }
private static async Task ExecuteCalculatorClientTest(CancellationToken cancellationToken, Calculator.Client client) { await client.OpenTransportAsync(cancellationToken); Stopwatch sw = Stopwatch.StartNew(); int max = 100000; foreach (var i in Enumerable.Range(0, max)) { var sum = await client.addAsync(1, 1, cancellationToken); //Logger.LogInformation($"{client.ClientId} AddAsync(1,1)={sum}"); } sw.Stop(); Logger.LogInformation($"{client.ClientId} AddAsync(1,1) do:{max} ms:{sw.ElapsedMilliseconds}"); }
private static async Task RunClientAsync(TProtocol protocol, CancellationToken cancellationToken) { try { var client = new Calculator.Client(protocol); await client.OpenTransportAsync(cancellationToken); try { // Async version Logger.LogInformation("PingAsync()"); await client.pingAsync(cancellationToken); Logger.LogInformation("AddAsync(1,1)"); var sum = await client.addAsync(1, 1, cancellationToken); Logger.LogInformation($"AddAsync(1,1)={sum}"); var work = new Work { Op = Operation.DIVIDE, Num1 = 1, Num2 = 0 }; try { Logger.LogInformation("CalculateAsync(1)"); await client.calculateAsync(1, work, cancellationToken); Logger.LogInformation("Whoa we can divide by 0"); } catch (InvalidOperation io) { Logger.LogInformation("Invalid operation: " + io); } work.Op = Operation.SUBTRACT; work.Num1 = 15; work.Num2 = 10; try { Logger.LogInformation("CalculateAsync(1)"); var diff = await client.calculateAsync(1, work, cancellationToken); Logger.LogInformation($"15-10={diff}"); } catch (InvalidOperation io) { Logger.LogInformation("Invalid operation: " + io); } Logger.LogInformation("GetStructAsync(1)"); var log = await client.getStructAsync(1, cancellationToken); Logger.LogInformation($"Check log: {log.Value}"); Logger.LogInformation("ZipAsync() with delay 100mc on server side"); await client.zipAsync(cancellationToken); } catch (Exception ex) { Logger.LogError(ex.ToString()); } finally { protocol.Transport.Close(); } } catch (TApplicationException x) { Logger.LogError(x.ToString()); } }
private static async Task RunClientAsync(TProtocol protocol, CancellationToken cancellationToken) { try { var client = new Calculator.Client(protocol); await client.OpenTransportAsync(cancellationToken); try { // Async version Logger.LogInformation("PingAsync()"); await client.pingAsync(cancellationToken); Logger.LogInformation("AddAsync(1,1)"); var sum = await client.addAsync(1, 1, cancellationToken); Logger.LogInformation($"AddAsync(1,1)={sum}"); var work = new Work { Op = Operation.DIVIDE, Num1 = 1, Num2 = 0 }; try { Logger.LogInformation("CalculateAsync(1)"); await client.calculateAsync(1, work, cancellationToken); Logger.LogInformation("Whoa we can divide by 0"); } catch (InvalidOperation io) { Logger.LogInformation("Invalid operation: " + io); } work.Op = Operation.SUBTRACT; work.Num1 = 15; work.Num2 = 10; try { Logger.LogInformation("CalculateAsync(1)"); var diff = await client.calculateAsync(1, work, cancellationToken); Logger.LogInformation($"15-10={diff}"); } catch (InvalidOperation io) { Logger.LogInformation("Invalid operation: " + io); } Logger.LogInformation("GetStructAsync(1)"); var log = await client.getStructAsync(1, cancellationToken); Logger.LogInformation($"Check log: {log.Value}"); Logger.LogInformation("ZipAsync() with delay 100mc on server side"); await client.zipAsync(cancellationToken); } catch (Exception ex) { Logger.LogError(ex.ToString()); } finally { protocol.Transport.Close(); } } catch (TApplicationException x) { Logger.LogError(x.ToString()); } }