예제 #1
0
파일: Program.cs 프로젝트: zkx2013/thrift
        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);
        }
예제 #2
0
파일: Program.cs 프로젝트: nsuke/thrift
        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());
            }
        }
예제 #3
0
        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());
            }
        }