Пример #1
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            bool useReactive = true;

            if (useReactive)
            {
                // Authenticate
                _reactiveApiService.Login(_clientId, _clientSecret)
                .Subscribe((result) =>
                {
                    if (result.HasValue && result.Value)
                    {
                        // Try to use the API
                        _reactiveApiService.GetCurrentUser()
                        .Subscribe((userResult) =>
                        {
                            // TODO
                        },
                                   (error) =>
                        {
                            // TODO
                        });

                        _reactiveApiService.GetAgenda()
                        .Subscribe((agendaResult) =>
                        {
                            // TODO
                        },
                                   (error) =>
                        {
                            // TODO
                        });
                    }
                },
                           (error) =>
                {
                    // TODO
                });
            }
            else
            {
                // Authenticate
                bool?isAuthenticated = await _apiService.LoginAsync(_clientId, _clientSecret);

                // Try to use the API
                try
                {
                    var user = await _apiService.GetCurrentUserAsync();

                    var agenda = await _apiService.GetAgendaAsync();
                }
                catch (Exception ex)
                {
                    return;
                }
            }
        }
Пример #2
0
        public async void TryAuthenticate()
        {
            if (LoginFailed)
            {
                await DispatcherHelper.ExecuteOnUIThreadAsync(() =>
                {
                    LoginFailed = false;
                });
            }

            // Do not login if we are already connected (token already set)
            // Retrieve token and username from previous connections
            string username = RetrieveUserTokenAndUsername();

            if (!string.IsNullOrWhiteSpace(_tvshowtimeApiService.Token) && !string.IsNullOrWhiteSpace(username))
            {
                // Check if token has expired
                var userConnectionProfile = await RetrieveConnectionProfileByUsernameAsync(username);

                if (userConnectionProfile != null && userConnectionProfile.ExpirationDate > DateTime.Now)
                {
                    _navigationService.NavigateTo(ViewConstants.Main);
                    return;
                }
            }

            // Login if there is no current user already logged
            _tvshowtimeApiService.Login(AuthConstants.ClientId, AuthConstants.ClientSecret)
            .Subscribe(async(result) =>
            {
                if (result.HasValue && result.Value)
                {
                    HandleLoginSuccess();
                }
                else
                {
                    await HandleLoginFailedAsync();
                }
            },
                       async(error) =>
            {
                await HandleLoginFailedAsync();
            });
        }