Ejemplo n.º 1
0
        /// <summary>
        /// Called when an item in the exercise list is tapped.
        /// </summary>
        /// <param name="sender">The object sending the event.</param>
        /// <param name="e">The event parameters.</param>
        private async void ExerciseList_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            if (await ConnectivityCheck.AskToEnableConnectivity(this))
            {
                // TODO: support other exercise types
                try
                {
                    ExerciseApi   exerciseEndpoint = new ExerciseApi(App.OAuth2Account, ((EssayExercise)e.Item).Uid);
                    EssayExercise essay            = await Task.Run(async() => await exerciseEndpoint.CallEndpointAsExerciseModel()) as EssayExercise;

                    if (essay == null)
                    {
                        await this.DisplayAlert(Properties.Resources.Error, Properties.Resources.Exercise_UnableToDisplay, Properties.Resources.ButtonOK);
                    }
                    else
                    {
                        await this.Navigation.PushAsync(new EssayExerciseView(essay));
                    }
                }
                catch (UnsuccessfulApiCallException ex)
                {
                    Tools.Logger.Log("ExerciseList_ItemTapped", ex);
                    await this.DisplayAlert(Properties.Resources.Error, Properties.Resources.Exercise_UnableToDisplay, Properties.Resources.ButtonOK);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Event handler
        /// </summary>
        /// <param name="sender">Sender param</param>
        /// <param name="e">evet param</param>
        private async void LoadButton_Clicked(object sender, EventArgs e)
        {
            try
            {
                ExerciseApi exAPI  = new ExerciseApi(App.OAuth2Account, this.ex.Uid);
                Exercise    result = await exAPI.CallEndpointAsExerciseModel();

                if (!(result is EssayExercise))
                {
                    throw new NotImplementedException(Properties.Resources.EssayExerciseViewExerciseTypeNotSupported);
                }

                await this.FillData((EssayExercise)result);
            }
            catch (NotImplementedException ex)
            {
                // This shouldn't happen
                await Tools.Logger.LogWithErrorMessage(this, "LoadButton_Clicked - This shouln't happen!", ex);
            }
            catch (UnsuccessfulApiCallException ex)
            {
                Tools.Logger.Log(this.GetType().ToString(), "LoadButton_Clicked method", ex);
            }
            catch (Exception ex)
            {
                Tools.Logger.Log(this.GetType().ToString(), "LoadButton_Clicked method", ex);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Refreshes the list containing the exercise history.
        /// </summary>
        /// <returns>True if everything was completed correctly</returns>
        /// <exception cref="UnsuccessfulApiCallException">Thrown if
        /// <see cref="ExerciseHistoryApi.CallEndpointAsObjectAsync()"/> fails.</exception>
        /// <exception cref="Exception">Thrown if something else fails.</exception>
        public async Task RefreshExerciseHistory()
        {
            List <Exercise>    historyWithResults = new List <Exercise>();
            ExerciseHistoryApi historyEndpoint    = new ExerciseHistoryApi(App.OAuth2Account);

            // These exceptions are handled in the view directly.
            IList <UserActivity> history = new List <UserActivity>();

            history = await historyEndpoint.CallEndpointAsObjectAsync().ConfigureAwait(false);

            // Performance
            ExerciseApi       exerciseEndpoint;
            Exercise          histEx;
            UserActivityEssay histActEssay;
            EssayExercise     histExEssay;

            foreach (UserActivity histAct in history)
            {
                try
                {
                    exerciseEndpoint = new ExerciseApi(App.OAuth2Account, histAct.ActivityId);
                    histEx           = await exerciseEndpoint.CallEndpointAsExerciseModel().ConfigureAwait(false);

                    if (histAct is UserActivityEssay && histEx is EssayExercise)
                    {
                        histActEssay          = (UserActivityEssay)histAct;
                        histExEssay           = (EssayExercise)histEx;
                        histExEssay.Contents  = histActEssay.Text;
                        histExEssay.Status    = histActEssay.Status;
                        histExEssay.Timestamp = histActEssay.Timestamp;
                    }
                    else
                    {
                        historyWithResults.Add(histEx);
                    }
                }
                catch (UnsuccessfulApiCallException ex)
                {
                    Tools.Logger.Log(this.GetType().ToString(), "RefreshExerciseHistory method - Internal UserActivity loop", ex);

                    // TODO: Add activity indicator
                    // this.SwitchActivityIndicator(false);
                }
                catch (Exception ex)
                {
                    Tools.Logger.Log(this.GetType().ToString(), "RefreshExerciseHistory method - Internal UserActivity loop", ex);

                    // TODO: Add activity indicator
                    // this.SwitchActivityIndicator(false);
                }
            }

            this._exerciseHistory = new ReadOnlyObservableCollection <Exercise>(new ObservableCollection <Exercise>(historyWithResults));
            this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("History"));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Refreshes the exercise history asynchronously.
        /// </summary>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        private static async Task <ReadOnlyObservableCollection <Exercise> > GetHistoryAsync()
        {
            List <Exercise>    historyWithResults = new List <Exercise>();
            ExerciseHistoryApi historyEndpoint    = new ExerciseHistoryApi(App.OAuth2Account);

            IEnumerable <UserActivity> history = new List <UserActivity>();

            history = await Task.Run(async() => await historyEndpoint.CallEndpointAsObjectAsync());

            // Remove dictionary searches (they are not meant to be displayed in the list).
            history = history.Where(x => x.GetType() != typeof(DictionarySearchExercise));

            // Preload all exercises in the list to improve performance.
            ExerciseApi exerciseEndpoint;

            foreach (UserActivity histAct in history)
            {
                exerciseEndpoint = new ExerciseApi(App.OAuth2Account, histAct.ActivityId);
                historyWithResults.Add(await Task.Run(async() => await exerciseEndpoint.CallEndpointAsExerciseModel()));
            }

            return(new ReadOnlyObservableCollection <Exercise>(new ObservableCollection <Exercise>(historyWithResults)));
        }