/// <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; } } }
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); } }