示例#1
0
        //check login and password
        private async void Auth(string login, string password)
        {
            authBar.IsIndeterminate = true;
            var authOk = false;

            bottomTextBlock.Text  = Properties.Resources.Connecting;
            loginButton.IsEnabled = false;
            try
            {
                if ((_client == null) || (_client.State != CommunicationState.Opened))
                {
                    _client = GetClient();
                }
                authOk = await _client.AuthAsync(login, password);
            }
            catch (FaultException ex)
            {
                (ex.Message).WriteLog(EventLogEntryType.Error, 305);
                MessageBox.Show(Properties.Resources.ServerInternalError, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (Exception ex) when(ex is ServerTooBusyException || ex is WebException)
            {
                (ex.Message + ex.InnerException).WriteLog(EventLogEntryType.Error, 305);
                MessageBox.Show(Properties.Resources.ServerConnectionError, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                _client.Abort();
            }
            catch (Exception ex)
            {
                (ex.Message + ex.InnerException).WriteLog(EventLogEntryType.Error, 305);
                MessageBox.Show(Properties.Resources.ServerTimeoutError, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                _client.Abort();
            }
            if (authOk)
            {
                login.SetRegString("UserId");
                password.SetRegString("UserPassword");
                bottomTextBlock.Text = Properties.Resources.AuthSuccess;
                paramTab.IsEnabled   = true;
                srvTab.IsEnabled     = true;
                startTab.IsEnabled   = true;
            }
            else
            {
                bottomTextBlock.Text = Properties.Resources.AuthError;
            }
            loginButton.IsEnabled   = true;
            authBar.IsIndeterminate = false;
        }