Exemple #1
0
        private void OnCheckTokenValidityCompleted(object sender, CheckTokenValidityCompletedEventArgs e)
        {
            _signInService.CheckTokenValidityCompleted -= OnCheckTokenValidityCompleted;
            if (e.Error != null)
            {
                return;
            }
            // current token is still valid.
            if (e.IsValid)
            {
                this.OnLoginAsyncCompleted(e.Token);
            }
            else
            {
                // need to get a new token.

                // we need to check if the settings are okay too because this takes place before the check performed in the OnSignIn command handler.
                var formatValidity = _synoSettings.IsCredentialFormatValid();

                if (formatValidity != CredentialFormatValidationResult.Valid)
                {
                    _signInService.ShowCredentialErrorMessage(formatValidity);
                    return;
                }

                _audioStationSession.Host = Host;
                _audioStationSession.Port = Port;

                try
                {
                    _audioStationSession.LoginAsync(this.UserName, this.Password, this.OnLoginAsyncCompleted,
                                                    this.OnLoginAsyncException, this._synoSettings.UseSsl);
                }
                catch (ArgumentNullException exception)
                {
                    // FIXME : Use noification service instead
                    MessageBox.Show(
                        "The connection settings don't look valid, please make sure they are entered correctly.",
                        "Credentials not valid",
                        MessageBoxButton.OK);
                }
                catch (UriFormatException exception)
                {
                    // FIXME : Use noification service instead
                    MessageBox.Show(
                        "The format of the provided hostname is not valid. Check that it is not prefixed it with http:// or https://",
                        "The host name is not valid",
                        MessageBoxButton.OK);
                }
            }
        }