Exemplo n.º 1
0
        private async void btnGetPerson_Click(object sender, RoutedEventArgs e)
        {
            var window = new Windows.GetPerson {
                Owner = this
            };

            if (window.ShowDialog() ?? false)
            {
                try
                {
                    WriteLine("Method: GetPerson");
                    WriteLine("Request: {0}", window.Value.ToString());
                    var result = await Client.GetPersonAsync(new PersonRequest { Id = window.Value });

                    switch (result.ResultCase)
                    {
                    default:
                    case PersonResponse.ResultOneofCase.None:
                        WriteLine("Response: none");
                        break;

                    case PersonResponse.ResultOneofCase.Error:
                        WriteLine("Response: Error (code: {0}, message: {1})", result.Error.Code.ToString(), result.Error.Message);
                        break;

                    case PersonResponse.ResultOneofCase.Person:
                        WriteLine("Response: Person (name: {0}, address: {1}, age: {2})", result.Person.Name, result.Person.Address, result.Person.Age.ToString());
                        break;
                    }
                }
                catch (Exception ex)
                {
                    WriteLine("Error: {0}", ex.Message);
                }
            }
        }