Пример #1
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> >()));
        }
Пример #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 <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)));
        }