Exemplo n.º 1
0
        /// <summary>
        /// Handles commands when in the Recovering state.
        /// </summary>
        /// <param name="command"></param>
        private void RecoveryLoopRecoveringHandler(RecoveryCommand command)
        {
            switch (command)
            {
            case RecoveryCommand.BeginAutomaticRecovery:
                ESLog.Info("Received request to BeginAutomaticRecovery, but already in Recovering state.");
                break;

            case RecoveryCommand.PerformAutomaticRecovery:
                if (TryPerformAutomaticRecovery())
                {
                    m_recoveryLoopState = RecoveryConnectionState.Connected;
                }
                else
                {
                    Task.Delay(m_factory.NetworkRecoveryInterval).ContinueWith(t => { m_recoveryLoopCommandQueue.TryAdd(RecoveryCommand.PerformAutomaticRecovery); });
                }

                break;

            default:
                ESLog.Warn($"RecoveryLoop command {command} is out of range.");
                break;
            }
        }
        /// <summary>
        /// Handles commands when in the Recovering state.
        /// </summary>
        /// <param name="command"></param>
        private void RecoveryLoopRecoveringHandler(RecoveryCommand command)
        {
            switch (command)
            {
            case RecoveryCommand.BeginAutomaticRecovery:
                ESLog.Info("Received request to BeginAutomaticRecovery, but already in Recovering state.");
                break;

            case RecoveryCommand.PerformAutomaticRecovery:
                if (TryPerformAutomaticRecovery())
                {
                    _recoveryLoopState = RecoveryConnectionState.Connected;
                }
                else
                {
                    ScheduleRecoveryRetry();
                }

                break;

            default:
                ESLog.Warn($"RecoveryLoop command {command} is out of range.");
                break;
            }
        }
        /// <summary>
        /// Handles commands when in the Recovering state.
        /// </summary>
        /// <param name="command"></param>
        private async Task RecoveryLoopRecoveringHandler(RecoveryCommand command)
        {
            switch (command)
            {
            case RecoveryCommand.BeginAutomaticRecovery:
                ESLog.Info("Received request to BeginAutomaticRecovery, but already in Recovering state.");
                break;

            case RecoveryCommand.PerformAutomaticRecovery:
                if (TryPerformAutomaticRecovery())
                {
                    _recoveryLoopState = RecoveryConnectionState.Connected;
                }
                else
                {
                    await Task.Delay(_factory.NetworkRecoveryInterval);

                    _recoveryLoopCommandQueue.Enqueue(RecoveryCommand.PerformAutomaticRecovery);
                    _semaphore.Release();
                }

                break;

            default:
                ESLog.Warn($"RecoveryLoop command {command} is out of range.");
                break;
            }
        }
Exemplo n.º 4
0
        protected LoginTabViewModel(IRepositoryHosts repositoryHosts, IVisualStudioBrowser browser)
        {
            Guard.ArgumentNotNull(repositoryHosts, nameof(repositoryHosts));
            Guard.ArgumentNotNull(browser, nameof(browser));

            RepositoryHosts = repositoryHosts;

            UsernameOrEmailValidator = ReactivePropertyValidator.For(this, x => x.UsernameOrEmail)
                                       .IfNullOrEmpty(Resources.UsernameOrEmailValidatorEmpty)
                                       .IfMatch(@"\s", Resources.UsernameOrEmailValidatorSpaces);

            PasswordValidator = ReactivePropertyValidator.For(this, x => x.Password)
                                .IfNullOrEmpty(Resources.PasswordValidatorEmpty);

            canLogin = this.WhenAny(
                x => x.UsernameOrEmailValidator.ValidationResult.IsValid,
                x => x.PasswordValidator.ValidationResult.IsValid,
                (x, y) => x.Value && y.Value).ToProperty(this, x => x.CanLogin);

            Login = ReactiveCommand.CreateAsyncObservable(this.WhenAny(x => x.CanLogin, x => x.Value), LogIn);

            Login.ThrownExceptions.Subscribe(ex =>
            {
                if (ex.IsCriticalException())
                {
                    return;
                }

                log.Info(string.Format(CultureInfo.InvariantCulture, "Error logging into '{0}' as '{1}'", BaseUri, UsernameOrEmail), ex);

                if (ex is Octokit.ForbiddenException)
                {
                    Error = new UserError(Resources.LoginFailedForbiddenMessage, ex.Message);
                }
                else
                {
                    Error = new UserError(ex.Message);
                }
            });

            isLoggingIn = Login.IsExecuting.ToProperty(this, x => x.IsLoggingIn);

            Reset = ReactiveCommand.CreateAsyncTask(_ => Clear());

            NavigateForgotPassword = new RecoveryCommand(Resources.ForgotPasswordLink, _ =>
            {
                browser.OpenUrl(new Uri(BaseUri, GitHubUrls.ForgotPasswordPath));
                return(RecoveryOptionResult.RetryOperation);
            });

            SignUp = ReactiveCommand.CreateAsyncObservable(_ =>
            {
                browser.OpenUrl(GitHubUrls.Plans);
                return(Observable.Return(Unit.Default));
            });
        }
Exemplo n.º 5
0
        protected LoginTabViewModel(IRepositoryHosts repositoryHosts, IVisualStudioBrowser browser)
        {
            RepositoryHosts = repositoryHosts;

            UsernameOrEmailValidator = ReactivePropertyValidator.For(this, x => x.UsernameOrEmail)
                .IfNullOrEmpty(Resources.UsernameOrEmailValidatorEmpty)
                .IfMatch(@"\s", Resources.UsernameOrEmailValidatorSpaces);

            PasswordValidator = ReactivePropertyValidator.For(this, x => x.Password)
                .IfNullOrEmpty(Resources.PasswordValidatorEmpty);

            canLogin = this.WhenAny(
                x => x.UsernameOrEmailValidator.ValidationResult.IsValid,
                x => x.PasswordValidator.ValidationResult.IsValid,
                (x, y) => x.Value && y.Value).ToProperty(this, x => x.CanLogin);

            Login = ReactiveCommand.CreateAsyncObservable(this.WhenAny(x => x.CanLogin, x => x.Value), LogIn);

            Login.ThrownExceptions.Subscribe(ex =>
            {
                if (ex.IsCriticalException()) return;

                log.Info(string.Format(CultureInfo.InvariantCulture, "Error logging into '{0}' as '{1}'", BaseUri, UsernameOrEmail), ex);
                if (ex is Octokit.ForbiddenException)
                {
                    UserError.Throw(new UserError(Resources.LoginFailedForbiddenMessage));
                }
                else
                {
                    UserError.Throw(new UserError(ex.Message));
                }
            });

            isLoggingIn = Login.IsExecuting.ToProperty(this, x => x.IsLoggingIn);

            Reset = ReactiveCommand.CreateAsyncTask(_ => Clear());

            NavigateForgotPassword = new RecoveryCommand(Resources.ForgotPasswordLink, _ =>
            {
                browser.OpenUrl(new Uri(BaseUri, GitHubUrls.ForgotPasswordPath));
                return RecoveryOptionResult.RetryOperation;
            });

            SignUp = ReactiveCommand.CreateAsyncObservable(_ =>
            {
                browser.OpenUrl(GitHubUrls.Plans);
                return Observable.Return(Unit.Default);
            });
        }
Exemplo n.º 6
0
        /// <summary>
        /// Handles commands when in the Connected state.
        /// </summary>
        /// <param name="command"></param>
        private void RecoveryLoopConnectedHandler(RecoveryCommand command)
        {
            switch (command)
            {
            case RecoveryCommand.PerformAutomaticRecovery:
                ESLog.Warn("Not expecting PerformAutomaticRecovery commands while in the connected state.");
                break;

            case RecoveryCommand.BeginAutomaticRecovery:
                m_recoveryLoopState = RecoveryConnectionState.Recovering;
                Task.Delay(m_factory.NetworkRecoveryInterval).ContinueWith(t => { m_recoveryLoopCommandQueue.TryAdd(RecoveryCommand.PerformAutomaticRecovery); });
                break;

            default:
                ESLog.Warn($"RecoveryLoop command {command} is out of range.");
                break;
            }
        }
        /// <summary>
        /// Handles commands when in the Connected state.
        /// </summary>
        /// <param name="command"></param>
        private void RecoveryLoopConnectedHandler(RecoveryCommand command)
        {
            switch (command)
            {
            case RecoveryCommand.PerformAutomaticRecovery:
                ESLog.Warn("Not expecting PerformAutomaticRecovery commands while in the connected state.");
                break;

            case RecoveryCommand.BeginAutomaticRecovery:
                _recoveryLoopState = RecoveryConnectionState.Recovering;
                ScheduleRecoveryRetry();
                break;

            default:
                ESLog.Warn($"RecoveryLoop command {command} is out of range.");
                break;
            }
        }
Exemplo n.º 8
0
        protected LoginTabViewModel(
            IConnectionManager connectionManager,
            IVisualStudioBrowser browser)
        {
            Guard.ArgumentNotNull(connectionManager, nameof(connectionManager));
            Guard.ArgumentNotNull(browser, nameof(browser));

            ConnectionManager = connectionManager;

            UsernameOrEmailValidator = ReactivePropertyValidator.For(this, x => x.UsernameOrEmail)
                                       .IfNullOrEmpty(Resources.UsernameOrEmailValidatorEmpty)
                                       .IfMatch(@"\s", Resources.UsernameOrEmailValidatorSpaces);

            PasswordValidator = ReactivePropertyValidator.For(this, x => x.Password)
                                .IfNullOrEmpty(Resources.PasswordValidatorEmpty);

            canLogin = this.WhenAny(
                x => x.UsernameOrEmailValidator.ValidationResult.IsValid,
                x => x.PasswordValidator.ValidationResult.IsValid,
                (x, y) => x.Value && y.Value).ToProperty(this, x => x.CanLogin);

            Login = ReactiveCommand.CreateAsyncTask(this.WhenAny(x => x.CanLogin, x => x.Value), LogIn);
            Login.ThrownExceptions.Subscribe(HandleError);
            isLoggingIn = Login.IsExecuting.ToProperty(this, x => x.IsLoggingIn);

            LoginViaOAuth = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.IsLoggingIn, x => !x),
                LogInViaOAuth);
            LoginViaOAuth.ThrownExceptions.Subscribe(HandleError);

            Reset = ReactiveCommand.CreateAsyncTask(_ => Clear());

            NavigateForgotPassword = new RecoveryCommand(Resources.ForgotPasswordLink, _ =>
            {
                browser.OpenUrl(new Uri(BaseUri, GitHubUrls.ForgotPasswordPath));
                return(RecoveryOptionResult.RetryOperation);
            });

            SignUp = ReactiveCommand.CreateAsyncObservable(_ =>
            {
                browser.OpenUrl(GitHubUrls.Plans);
                return(Observable.Return(Unit.Default));
            });
        }
Exemplo n.º 9
0
        /// <summary>
        /// Handles commands when in the Connected state.
        /// </summary>
        /// <param name="command"></param>
        private async Task RecoveryLoopConnectedHandler(RecoveryCommand command)
        {
            switch (command)
            {
            case RecoveryCommand.PerformAutomaticRecovery:
                ESLog.Warn("Not expecting PerformAutomaticRecovery commands while in the connected state.");
                break;

            case RecoveryCommand.BeginAutomaticRecovery:
                _recoveryLoopState = RecoveryConnectionState.Recovering;
                await Task.Delay(_factory.NetworkRecoveryInterval).ConfigureAwait(false);

                _recoveryLoopCommandQueue.TryAdd(RecoveryCommand.PerformAutomaticRecovery);
                break;

            default:
                ESLog.Warn($"RecoveryLoop command {command} is out of range.");
                break;
            }
        }