コード例 #1
0
        protected async Task Startup()
        {
            var accounts = (await _accountsService.GetAccounts()).ToList();

            if (!accounts.Any())
            {
                GoToLoginCommand.ExecuteNow();
                return;
            }

            var account = await _applicationService.GetDefaultAccount();

            if (account == null)
            {
                GoToAccountsCommand.ExecuteNow();
                return;
            }

            if (string.IsNullOrEmpty(account.Token) || string.IsNullOrEmpty(account.RefreshToken))
            {
                GoToLoginCommand.ExecuteNow();
                return;
            }

            try
            {
                IsLoggingIn = true;
                Status      = "Logging in as " + account.Username;

                var ret = await BitbucketClient.GetRefreshToken(
                    Secrets.ClientId, Secrets.ClientSecret, account.RefreshToken);

                if (ret == null)
                {
                    await _alertDialogService.Alert("Error!", "Unable to refresh OAuth token. Please login again.");

                    GoToLoginCommand.ExecuteNow();
                    return;
                }

                account.RefreshToken = ret.RefreshToken;
                account.Token        = ret.AccessToken;
                await _accountsService.Save(account);
                await AttemptLogin(account);

                GoToMenuCommand.ExecuteNow();
            }
            catch (Exception e)
            {
                _alertDialogService
                .Alert("Error!", "Unable to login successfully: " + e.Message)
                .ToObservable()
                .BindCommand(GoToAccountsCommand);
            }
            finally
            {
                IsLoggingIn = false;
            }
        }
コード例 #2
0
        protected async Task Startup()
        {
            if (!_applicationService.Accounts.Any())
            {
                GoToLoginCommand.Execute(null);
                return;
            }

            var account = GetDefaultAccount();

            if (account == null)
            {
                GoToAccountsCommand.Execute(null);
                return;
            }

            if (string.IsNullOrEmpty(account.Token) || string.IsNullOrEmpty(account.RefreshToken))
            {
                await AlertService.Alert("Welcome!", "CodeBucket is now OAuth compliant!\n\nFor your security, " +
                                         "you will now be prompted to login to Bitbucket via their OAuth portal. This will swap out your credentials" +
                                         " for an OAuth token you may revoke at any time!");

                GoToLoginCommand.Execute(null);
                return;
            }

            try
            {
                IsLoggingIn = true;
                Status      = "Logging in as " + account.Username;

                var ret = await Task.Run(() => Client.RefreshToken(LoginViewModel.ClientId, LoginViewModel.ClientSecret, account.RefreshToken));

                if (ret == null)
                {
                    await DisplayAlert("Unable to refresh OAuth token. Please login again.");

                    GoToLoginCommand.Execute(null);
                    return;
                }

                account.RefreshToken = ret.RefreshToken;
                account.Token        = ret.AccessToken;
                _accountsService.Update(account);

                await AttemptLogin(account);

                GoToMenuCommand.Execute(null);
            }
            catch (Exception e)
            {
                DisplayAlert("Unable to login successfully: " + e.Message).FireAndForget();
                GoToAccountsCommand.Execute(null);
            }
            finally
            {
                IsLoggingIn = false;
            }
        }
コード例 #3
0
ファイル: StartupViewModel.cs プロジェクト: yhtsnda/CodeHub
 private void GoToAccountsOrNewUser()
 {
     if (_accountsService.Any())
     {
         GoToAccountsCommand.ExecuteIfCan();
     }
     else
     {
         GoToNewUserCommand.ExecuteIfCan();
     }
 }
コード例 #4
0
 private void GoToAccountsOrNewUser()
 {
     if (AccountsService.Any())
     {
         GoToAccountsCommand.Execute(null);
     }
     else
     {
         GoToNewUserCommand.Execute(null);
     }
 }
コード例 #5
0
        public StartupViewModel(IAccountsService accountsService, ILoginService loginService)
        {
            _accountsService = accountsService;
            _loginService    = loginService;

            GoToMainCommand           = ReactiveCommand.Create();
            GoToAccountsCommand       = ReactiveCommand.Create();
            GoToNewUserCommand        = ReactiveCommand.Create();
            BecomeActiveWindowCommand = ReactiveCommand.Create();

            GoToAccountsCommand.Subscribe(_ => ShowViewModel(CreateViewModel <AccountsViewModel>()));

            GoToNewUserCommand.Subscribe(_ => ShowViewModel(CreateViewModel <NewAccountViewModel>()));

            GoToMainCommand.Subscribe(_ => ShowViewModel(CreateViewModel <MenuViewModel>()));

            LoadCommand = ReactiveCommand.CreateAsyncTask(x => Load());
        }
コード例 #6
0
ファイル: StartupViewModel.cs プロジェクト: yhtsnda/CodeHub
        private async Task Load()
        {
            var account = _accountsService.GetDefault();

            // Account no longer exists
            if (account == null)
            {
                GoToAccountsOrNewUser();
            }
            else
            {
                try
                {
                    Status = string.Format("Logging in {0}", account.Username);

                    Uri avatarUri;
                    if (Uri.TryCreate(account.AvatarUrl, UriKind.Absolute, out avatarUri))
                    {
                        ImageUrl = avatarUri;
                    }

                    IsLoggingIn = true;
                    await _loginService.LoginAccount(account);

                    _accountsService.ActiveAccount = account;
                    GoToMainCommand.ExecuteIfCan();
                }
                catch
                {
                    GoToAccountsCommand.ExecuteIfCan();
                }
                finally
                {
                    IsLoggingIn = false;
                }
            }
        }
コード例 #7
0
ファイル: MenuViewModel.cs プロジェクト: iOSAppList/CodeHub
        public MenuViewModel(IApplicationService applicationService, IAccountsService accountsService)
            : base(accountsService)
        {
            _applicationService = applicationService;

            GoToNotificationsCommand = ReactiveCommand.Create();
            GoToNotificationsCommand.Subscribe(_ =>
            {
                var vm = CreateViewModel <NotificationsViewModel>();
                ShowViewModel(vm);
            });

            GoToAccountsCommand = ReactiveCommand.Create();
            GoToAccountsCommand.Subscribe(_ => CreateAndShowViewModel <AccountsViewModel>());

            GoToProfileCommand = ReactiveCommand.Create();
            GoToProfileCommand.Subscribe(_ =>
            {
                var vm      = CreateViewModel <UserViewModel>();
                vm.Username = Account.Username;
                ShowViewModel(vm);
            });

            GoToMyIssuesCommand = ReactiveCommand.Create();
            GoToMyIssuesCommand.Subscribe(_ => CreateAndShowViewModel <MyIssuesViewModel>());

            GoToUpgradesCommand = ReactiveCommand.Create();
            GoToUpgradesCommand.Subscribe(_ => CreateAndShowViewModel <UpgradesViewModel>());

            GoToAboutCommand = ReactiveCommand.Create();
            GoToAboutCommand.Subscribe(_ => CreateAndShowViewModel <AboutViewModel>());

            GoToRepositoryCommand = ReactiveCommand.Create();
            GoToRepositoryCommand.OfType <RepositoryIdentifier>().Subscribe(x =>
            {
                var vm             = CreateViewModel <RepositoryViewModel>();
                vm.RepositoryOwner = x.Owner;
                vm.RepositoryName  = x.Name;
                ShowViewModel(vm);
            });

            GoToSettingsCommand = ReactiveCommand.Create();
            GoToSettingsCommand.Subscribe(_ => CreateAndShowViewModel <SettingsViewModel>());

            GoToNewsCommand = ReactiveCommand.Create();
            GoToNewsCommand.Subscribe(_ => CreateAndShowViewModel <NewsViewModel>());

            GoToOrganizationsCommand = ReactiveCommand.Create();
            GoToOrganizationsCommand.Subscribe(_ =>
            {
                var vm      = CreateViewModel <OrganizationsViewModel>();
                vm.Username = Account.Username;
                ShowViewModel(vm);
            });

            GoToTrendingRepositoriesCommand = ReactiveCommand.Create();
            GoToTrendingRepositoriesCommand.Subscribe(_ => CreateAndShowViewModel <RepositoriesTrendingViewModel>());

            GoToExploreRepositoriesCommand = ReactiveCommand.Create();
            GoToExploreRepositoriesCommand.Subscribe(_ => CreateAndShowViewModel <RepositoriesExploreViewModel>());

            GoToOrganizationEventsCommand = ReactiveCommand.Create();
            GoToOrganizationEventsCommand.OfType <string>().Subscribe(name =>
            {
                var vm      = CreateViewModel <UserEventsViewModel>();
                vm.Username = name;
                ShowViewModel(vm);
            });

            GoToOrganizationCommand = ReactiveCommand.Create();
            GoToOrganizationCommand.OfType <string>().Subscribe(name =>
            {
                var vm      = CreateViewModel <OrganizationViewModel>();
                vm.Username = name;
                ShowViewModel(vm);
            });

            GoToOwnedRepositoriesCommand = ReactiveCommand.Create();
            GoToOwnedRepositoriesCommand.Subscribe(_ =>
            {
                var vm      = CreateViewModel <UserRepositoriesViewModel>();
                vm.Username = Account.Username;
                ShowViewModel(vm);
            });

            GoToStarredRepositoriesCommand = ReactiveCommand.Create().WithSubscription(
                _ => CreateAndShowViewModel <RepositoriesStarredViewModel>());

            GoToPublicGistsCommand = ReactiveCommand.Create().WithSubscription(
                _ => CreateAndShowViewModel <PublicGistsViewModel>());

            GoToStarredGistsCommand = ReactiveCommand.Create().WithSubscription(
                _ => CreateAndShowViewModel <StarredGistsViewModel>());

            GoToMyGistsCommand = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm      = CreateViewModel <UserGistsViewModel>();
                vm.Username = Account.Username;
                ShowViewModel(vm);
            });

            GoToMyEvents = ReactiveCommand.Create();
            GoToMyEvents.Subscribe(_ =>
            {
                var vm      = CreateViewModel <UserEventsViewModel>();
                vm.Username = Account.Username;
                ShowViewModel(vm);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(_ =>
            {
                var notificationRequest = applicationService.Client.Notifications.GetAll();
                notificationRequest.RequestFromCache = false;
                notificationRequest.CheckIfModified  = false;

                var task2 = applicationService.Client.ExecuteAsync(notificationRequest)
                            .ContinueWith(t => Notifications = t.Result.Data.Count, TaskScheduler.FromCurrentSynchronizationContext());

                var task3 = applicationService.Client.ExecuteAsync(applicationService.Client.AuthenticatedUser.GetOrganizations())
                            .ContinueWith(t => Organizations = t.Result.Data.Select(y => y.Login).ToList(), TaskScheduler.FromCurrentSynchronizationContext());

                return(Task.WhenAll(task2, task3));
            });
        }