示例#1
0
        /// <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);
        }