private void OnButtonClick(object sender, RoutedEventArgs e)
        {
            Output.Visibility = Visibility.Collapsed;
            Error.Visibility  = Visibility.Collapsed;
            int  number;
            bool ok = Int32.TryParse(InputNumber.Text, out number);

            if (!ok)
            {
                Error.Text       = "Enter a number";
                Error.Visibility = Visibility.Visible;
                return;
            }
            var proxy = new StateNameProxy();

            proxy.BeginGetName(number, asr =>
            {
                Dispatcher.BeginInvoke(delegate()
                {
                    try
                    {
                        StateName.Text    = proxy.EndGetName(asr);
                        StateNumber.Text  = number.ToString();
                        Output.Visibility = Visibility.Visible;
                    }
                    catch (XmlRpcFaultException fex)
                    {
                        Error.Text       = "[" + fex.FaultCode.ToString() + "] " + fex.FaultString;
                        Error.Visibility = Visibility.Visible;
                    }
                    catch (Exception ex)
                    {
                        Error.Text       = ex.Message;
                        Error.Visibility = Visibility.Visible;
                    }
                });
            });
        }
Beispiel #2
0
 private void OnButtonClick(object sender, RoutedEventArgs e)
 {
   Output.Visibility = Visibility.Collapsed;
   Error.Visibility = Visibility.Collapsed;
   int number;
   bool ok = Int32.TryParse(InputNumber.Text, out number);
   if (!ok)
   {
     Error.Text = "Enter a number";
     Error.Visibility = Visibility.Visible;
     return;
   }
   var proxy = new StateNameProxy();
   proxy.BeginGetName(number, asr =>
   {
     Dispatcher.BeginInvoke(delegate() 
       {
         try
         {
           StateName.Text = proxy.EndGetName(asr);
           StateNumber.Text = number.ToString();
           Output.Visibility = Visibility.Visible;
         }
         catch (XmlRpcFaultException fex)
         {
           Error.Text = "[" + fex.FaultCode.ToString() + "] " + fex.FaultString;
           Error.Visibility = Visibility.Visible;
         }
         catch (Exception ex)
         {
           Error.Text = ex.Message;
           Error.Visibility = Visibility.Visible;
         }
       });
   });
 }