コード例 #1
0
ファイル: App.xaml.cs プロジェクト: nijunjie/UITextTransRepo
 private void StartUITextTrans()
 {
     try
     {
         AddTestInfoRecord();
         if (Common.NetWork())
         {
             TranslatorServiceClient _transClient = new TranslatorServiceClient();
             if (TranslatorServiceClient.Account != null)
             {
                 new frmUITextTrans().Show();
             }
             else
             {
                 new frmLogin().Show();
             }
         }
         else
         {
             new frmProxySetting().Show();
         }
     }
     catch (ArgumentException ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
コード例 #2
0
 private void Start(bool isCustomAccount, string loginName, string password)
 {
     try
     {
         TranslatorServiceClient _transClient = new TranslatorServiceClient(isCustomAccount, loginName, password);
         if (TranslatorServiceClient.Account != null)
         {
             if (!isCustomAccount)
             {
                 _transClient.InitAuthentication(TranslatorServiceClient.Account.ClientId, TranslatorServiceClient.Account.ClientSecret);
             }
             else
             {
                 WriteAccount(loginName, password);
             }
             this.Hide();
             new frmUITextTrans().Show();
         }
         else
         {
             MessageBox.Show("Error Login Name or Password.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     catch (InvalidOperationException ex)
     {
         MessageBox.Show("Error Client ID or Client Secret.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
コード例 #3
0
 private void ShowUI()
 {
     TranslatorServiceClient _transClient = new TranslatorServiceClient();
     if (TranslatorServiceClient.Account != null)
     {
         this.Hide();
         new frmUITextTrans().Show();
     }
     else
     {
         this.Hide();
         new frmLogin().Show();
     }
 }
コード例 #4
0
 /// <summary>
 /// Check Translator Service Client, if client is null or the time is expired, will renew the  client.
 /// </summary>
 public void CheckTranslatorServiceClient()
 {
     if (_transClient == null || _transClient.tokenReceived.AddMinutes(expires) <= DateTime.Now)
     {
         try
         {
             _transClient = new TranslatorServiceClient(TranslatorServiceClient.IsCustomAccount,
                                                         TranslatorServiceClient.LoginName,
                                                         TranslatorServiceClient.Password);
             _transClient.InitAuthentication(TranslatorServiceClient.Account.ClientId, TranslatorServiceClient.Account.ClientSecret);
         }
         catch (InvalidOperationException ex)
         {
             throw ex;
         }
     }
 }
コード例 #5
0
 private string FilterExceptionMessage(string message)
 {
     if (message.Contains("the incoming token has expired."))
     {
         return "";
     }
     else if (message.Contains("The remote server returned an unexpected response: (400) Bad Request."))
     {
         _transClient = null;
         return "";
     }
     return message;
 }