/// <summary> /// Show an activity indicator and refresh the page in the background. /// </summary> /// <returns></returns> public async Task RefreshPageAsync() { await this.StackLayoutButtonStack.FadeTo(0, 1); this.ActivityIndicator.IsVisible = true; this.ActivityIndicator.IsRunning = true; this.isSetup = false; await Task.Run(() => QuizRosterDatabase.UpdateLocalDatabaseAsync()); this.CheckSetup(); this.ActivityIndicator.IsVisible = false; this.ActivityIndicator.IsRunning = false; await this.StackLayoutButtonStack.FadeTo(1, 1); }
/// <summary> /// Called when the user tries to download a quiz /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void SyncDownload_Clicked(object sender, EventArgs e) { // this.serverConnected = true; ImageButton button = sender as ImageButton; string dbId = button.ClassId; QuizInfo quizInfo = QuizRosterDatabase.GetQuizInfo(dbId); // DOES THIS WORK? while (quizInfo == null && Plugin.Connectivity.CrossConnectivity.Current.IsConnected) { await QuizRosterDatabase.UpdateLocalDatabaseAsync(); quizInfo = QuizRosterDatabase.GetQuizInfo(dbId); } string authorName = quizInfo.AuthorName; string quizName = quizInfo.QuizName; string category = quizInfo.Category; ActivityIndicator indicatorSyncing = (button.Parent as StackLayout).Children[(int)UISyncStatus.Syncing] as ActivityIndicator; string quizPath = button.ClassId; button.IsVisible = false; indicatorSyncing.IsVisible = true; indicatorSyncing.IsRunning = true; if (await Task.Run(() => ServerOperations.GetQuiz(dbId, category))) { ImageButton buttonSyncNoChange = (button.Parent as StackLayout).Children[(int)UISyncStatus.NoChange] as ImageButton; indicatorSyncing.IsVisible = false; buttonSyncNoChange.IsVisible = true; (((button.Parent as StackLayout).Parent as StackLayout).Parent as Frame).StyleId = "Local"; } else // If it failed to download { indicatorSyncing.IsVisible = false; button.IsVisible = true; await this.DisplayAlert("Quiz Download Failed", "This quiz could not be downloaded from the server. Please try again.", "OK"); } indicatorSyncing.IsRunning = false; await this.UpdateProfileContentAsync( this.SelectedCategory); }
/// <summary> /// Sets up the quizzes owned by this user as cards /// </summary> private async Task SetupQuizzes(string category) { await QuizRosterDatabase.UpdateLocalDatabaseAsync(); // A single LINQ statement to get all quizzes by the current // user that is logged in, and of the specified category, // taking the top 20 of the current chunk ordered by // the subscriber count of the quizzes List <QuizInfo> rosterCopy = QuizRosterDatabase.GetRoster(); List <QuizInfo> quizzes = rosterCopy. Where( quizInfo => (quizInfo.AuthorName == CredentialManager.Username && (quizInfo.Category == category || category == "All"))). OrderBy(quizInfo => quizInfo.SubscriberCount). Take(20 * this.currentChunk).ToList(); this.AddQuizzes(quizzes, false); }
/// <summary> /// Update local data through synchronzing data with server. /// Runs on a timed background task and repeats a synchronization every two minutes. /// </summary> /// <returns></returns> public static async Task RunServerChecksAsync() { await CredentialManager.CheckLoginStatusAsync(); await Task.Run(async() => await QuizRosterDatabase.UpdateLocalDatabaseAsync()); var minutes = TimeSpan.FromMinutes(2); Device.StartTimer(minutes, () => { Task task = Task.Run(async() => { if (CredentialManager.IsLoggedIn) { await CredentialManager.CheckLoginStatusAsync(); } await QuizRosterDatabase.UpdateLocalDatabaseAsync(); BugReportHandler.SubmitSavedReports(); }); // Return true to continue the timer return(true); }); }