Пример #1
0
        /// <summary>
        /// Gets the words appearing in the exercise text, grouped by level, asynchronously.
        /// </summary>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        private async Task <ReadOnlyObservableCollection <Grouping <IWord> > > GetWordsInTextByLevelAsync()
        {
            Collection <Grouping <IWord> > wordGroups = new Collection <Grouping <IWord> >();
            LanguageLevelClassificationToShortDescriptionConverter  shortLanguageConverter = new LanguageLevelClassificationToShortDescriptionConverter();
            LanguageLevelClassificationToLongDescriptionConverter   longLanguageConverter  = new LanguageLevelClassificationToLongDescriptionConverter();
            Dictionary <LanguageLevelClassification, List <IWord> > exerciseResults        = await this._exercise.LevelClassification;

            foreach (KeyValuePair <LanguageLevelClassification, List <IWord> > exercisePair in exerciseResults)
            {
                if (exercisePair.Value.Count > 0)
                {
                    wordGroups.Add(new Grouping <IWord>(
                                       (string)longLanguageConverter.Convert(exercisePair.Key, typeof(string), null, CultureInfo.CurrentUICulture),
                                       (string)shortLanguageConverter.Convert(exercisePair.Key, typeof(string), null, CultureInfo.CurrentUICulture),
                                       exercisePair.Value));
                }
            }

            return(new ReadOnlyObservableCollection <Grouping <IWord> >(new ObservableCollection <Grouping <IWord> >(wordGroups)));
        }
Пример #2
0
        /// <summary>
        /// Refreshes the list of featured exercises asynchronously.
        /// </summary>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        private static async Task <ReadOnlyObservableCollection <Grouping <Exercise> > > GetFeaturedExercisesAsync()
        {
            ExerciseFeaturedApi    featuredEndpoint = new ExerciseFeaturedApi(App.OAuth2Account);
            IEnumerable <Exercise> featuredExercises;

            try
            {
                featuredExercises = await Task.Run(async() => await featuredEndpoint.CallEndpointAsExerciseModel());

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

                // Group the exercises by their CEFR level.
                LanguageLevelClassificationToLongDescriptionConverter longDescConverter  = new LanguageLevelClassificationToLongDescriptionConverter();
                LanguageLevelClassificationToHtmlParamConverter       htmlParamConverter = new LanguageLevelClassificationToHtmlParamConverter();
                IEnumerable <Grouping <Exercise> > featuredByGroup = from ex in featuredExercises group ex by ex.Level into exSameLevel select new Grouping <Exercise>((string)longDescConverter.Convert(exSameLevel.Key, typeof(string), null, CultureInfo.CurrentCulture), (string)htmlParamConverter.Convert(exSameLevel.Key, typeof(string), null, CultureInfo.CurrentCulture), exSameLevel.ToList());

                return(new ReadOnlyObservableCollection <Grouping <Exercise> >(new ObservableCollection <Grouping <Exercise> >(featuredByGroup)));
            }
            catch (AggregateException ex)
            {
                ex.Handle(x =>
                {
                    Tools.Logger.Log("FeaturedExercise", ex);
                    return(true);
                });
            }

            return(new ReadOnlyObservableCollection <Grouping <Exercise> >(new ObservableCollection <Grouping <Exercise> >()));
        }
Пример #3
0
        /// <summary>
        /// Refreshes the list of featured exercises asynchronously.
        /// </summary>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        private static async Task <ReadOnlyObservableCollection <ExerciseGroup> > GetFeaturedExercisesAsync()
        {
            ExerciseFeaturedApi featuredEndpoint  = new ExerciseFeaturedApi(App.OAuth2Account);
            IList <Exercise>    featuredExercises = await Task.Run(async() => await featuredEndpoint.CallEndpointAsExerciseModel());

            // Group the exercises by their CEFR level.
            LanguageLevelClassificationToLongDescriptionConverter longDescConverter  = new LanguageLevelClassificationToLongDescriptionConverter();
            LanguageLevelClassificationToHtmlParamConverter       htmlParamConverter = new LanguageLevelClassificationToHtmlParamConverter();
            IEnumerable <ExerciseGroup> featuredByGroup = from ex in featuredExercises group ex by ex.Level into exSameLevel select new ExerciseGroup((string)longDescConverter.Convert(exSameLevel.Key, typeof(string), null, CultureInfo.CurrentCulture), (string)htmlParamConverter.Convert(exSameLevel.Key, typeof(string), null, CultureInfo.CurrentCulture), exSameLevel.ToList());

            return(new ReadOnlyObservableCollection <ExerciseGroup>(new ObservableCollection <ExerciseGroup>(featuredByGroup)));
        }