/// <exception cref="ConnectionException">Could not send feedback because the device is not connected to the web.</exception> public async Task SendFeedbackAsync(int sessionId, ScoredFeedback feedback) { if (!CrossConnectivity.Current.IsConnected) { throw new ConnectionException(); } try { await _apiService.SendFeedbackAsync(sessionId, feedback).ConfigureAwait(false); _dispatcherHelper.ExecuteOnUiThread( () => _dialogService.ShowMessageBox(_loc.GetLocalizedString(Localized.FeedbackSent), _loc.GetLocalizedString(Localized.Success))); } catch (Exception e) { await CatchExceptionAsync(e); } finally { Messenger.Default.Send(new SubmittingMessage(false)); } }
public MainViewModel(ICategoryService categoryService, IDialogService dialogService, ILocalizedStringProvider localizedStringProvider, ILoggingService loggingService, IAuthenticationService authService, INavigationService navigationService, ICourseService courseService, IDispatcherHelper dispatcher) : base(dialogService, localizedStringProvider, loggingService, authService, dispatcher, navigationService) { _categoryService = categoryService; _courseService = courseService; _dispatcher = dispatcher; Categories = new ObservableCollection <Category>(); _lockObject = new object(); FoundCourses = new ObservableCollection <Course>(); Messenger.Default.Register <PropertyChangedMessage <string> >(this, message => { if (message.PropertyName == nameof(SearchValue)) { UpdateSearchResultsAsync(message.NewValue); } }); Messenger.Default.Register <AuthenticationChangedMessage>(this, m => _dispatcher.ExecuteOnUiThread(() => Identity = m.NewIdentity)); if (IsInDesignModeStatic) { var identity = new Identity(); identity.AddClaims(new Claim(Claim.FamilyNameName, Claim.FamilyNameName), new Claim(Claim.EmailName, Claim.EmailName), new Claim(Claim.GivenNameName, Claim.GivenNameName)); Identity = identity; } }
private void SetSearchResults(ICollection <Course> results = null, bool faulted = false) { _dispatcher.ExecuteOnUiThread(() => { FoundCourses.Clear(); if (faulted) { SearchStatus = SearchStatus.Faulted; return; } if (SearchValue.IsNullOrEmpty()) { SearchStatus = SearchStatus.Inactive; return; } if (results == null || !results.Any()) { SearchStatus = SearchStatus.NoResults; return; } SearchStatus = SearchStatus.ResultsAvailable; results.ForEach(c => FoundCourses.Add(c)); }); }
private async Task FetchCourseSessionsAsync(Course course, bool speculative = false) { if (!Current.IsConnected) { throw new ConnectionException(); } try { var apiService = speculative ? _speculative : _userInitiated; var shouldFetch = true; var page = 1; const int pageSize = 10; _dispatcherHelper.ExecuteOnUiThread(() => course.Sessions.Clear()); var random = new Random(); while (shouldFetch) { var sessions = await apiService.GetCourseSessionsAsync(course.Id, page, pageSize); #if DEBUG sessions.ForEach(s => s.AddFakeData(random)); #endif if (sessions.Count < pageSize) { shouldFetch = false; } _dispatcherHelper.ExecuteOnUiThread(() => sessions.ForEach(s => { if (s.FirstStartTime != null && s.FirstStartTime.Value > DateTime.Today) { course.Sessions.Add(s); } })); page++; } _dispatcherHelper.ExecuteOnUiThread(() => course.Sessions.Sort()); Cache.InsertIfMoreDetailsAsync(GetCourseCacheKey(course), course, TimeSpan.FromDays(5)); } catch (Exception exc) { throw new DataSourceException(exc); } }
protected override void StartLoginUi(object viewReference) { _authenticator = new WebRedirectAuthenticator(GetAuthenticationUri(), GetRedirectUri()); _authenticator.Error += AuthenticatorOnError; _authenticator.Completed += AuthenticatorOnCompleted; _dispatcherHelper.ExecuteOnUiThread(() => { _viewController = (UIViewController)viewReference; _viewController.PresentViewController(_authenticator.GetUI(), false, null); }); }
protected PageBase() { HardwareButtons.BackPressed -= HardwareButtonsOnBackPressed; HardwareButtons.BackPressed += HardwareButtonsOnBackPressed; Loc = ServiceLocator.Current.GetInstance <ILocalizedStringProvider>(); _helper = ServiceLocator.Current.GetInstance <IDispatcherHelper>(); var statusBar = StatusBar.GetForCurrentView(); statusBar.BackgroundOpacity = 0; statusBar.ForegroundColor = Color.FromArgb(0, 1, 137, 180); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed statusBar.ShowAsync(); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Messenger.Default.Register <PropertyChangedMessage <bool> >(this, async message => await UpdateLoadingStatusAsync(message).ConfigureAwait(true)); Messenger.Default.Register <SubmittingMessage>(this, message => _helper.ExecuteOnUiThread(async() => await UpdateSubmittingStatusAsync(message).ConfigureAwait(true))); Unloaded += (sender, args) => Messenger.Default.Unregister(sender); _dialogService = ServiceLocator.Current.GetInstance <IDialogService>(); }