示例#1
0
        protected async virtual Task <IEnumerable <UnsplashImageBase> > RequestAsync(int pageIndex)
        {
#if DEBUG
            var cts = CTSFactory.MakeCTS();
#else
            var cts = CTSFactory.MakeCTS(15000);
#endif
            try
            {
                var result = await CloudService.GetImages(pageIndex, (int)20u, cts.Token, RequestUrl);

                if (result.IsRequestSuccessful)
                {
                    IEnumerable <UnsplashImageBase> list = null;
                    if (Featured)
                    {
                        list = UnsplashFeaturedImage.ParseListFromJson(result.JsonSrc);
                    }
                    else
                    {
                        list = UnsplashImage.ParseListFromJson(result.JsonSrc);
                    }
                    await CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        UpdateHintVisibility(list);
                    });

                    return(list);
                }
                else
                {
                    throw new ArgumentNullException();
                }
            }
            catch (Exception e)
            {
                await Logger.LogAsync(e);

                return(new List <UnsplashImage>());
            }
        }
        protected async virtual Task <IEnumerable <UnsplashImageBase> > RequestAsync(int pageIndex)
        {
            var result = await CloudService.GetImages(pageIndex, (int)DEFAULT_PER_PAGE, CTSFactory.MakeCTS(10000).Token, RequestUrl);

            if (result.IsRequestSuccessful)
            {
                if (Featured)
                {
                    var list = UnsplashFeaturedImage.ParseListFromJson(result.JsonSrc);
                    UpdateHintVisibility(list);
                    return(list);
                }
                else
                {
                    var list = UnsplashImage.ParseListFromJson(result.JsonSrc);
                    UpdateHintVisibility(list);
                    return(list);
                }
            }
            else
            {
                throw new APIException();
            }
        }
示例#3
0
        protected async override Task <IEnumerable <UnsplashImage> > GetList(int pageIndex)
        {
            try
            {
                if (pageIndex >= 2)
                {
                    MainVM.ShowFooterLoading = Visibility.Visible;
                }

                var result = await CloudService.GetImages(pageIndex, (int)DEFAULT_PER_PAGE, CTSFactory.MakeCTS(10000).Token, RequestUrl);

                if (result.IsRequestSuccessful)
                {
                    var list = UnsplashImage.ParseListFromJson(result.JsonSrc);
                    return(list);
                }
                else
                {
                    throw new APIException();
                }
            }
            catch (APIException)
            {
                await CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    MainVM.ShowFooterLoading    = Visibility.Collapsed;
                    MainVM.ShowFooterReloadGrid = Visibility.Visible;
                    MainVM.IsRefreshing         = false;

                    if (MainVM.MainList?.Count == 0)
                    {
                        MainVM.ShowNoItemHint = Visibility.Visible;
                    }
                    else
                    {
                        MainVM.ShowNoItemHint = Visibility.Collapsed;
                    }

                    ToastService.SendToast("Request failed.");
                });

                return(new List <UnsplashImage>());
            }
            catch (TaskCanceledException)
            {
                await CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    MainVM.ShowFooterLoading    = Visibility.Collapsed;
                    MainVM.ShowFooterReloadGrid = Visibility.Visible;
                    MainVM.IsRefreshing         = false;

                    if (MainVM.MainList.Count == 0)
                    {
                        MainVM.ShowNoItemHint = Visibility.Visible;
                    }
                    else
                    {
                        MainVM.ShowNoItemHint = Visibility.Collapsed;
                    }

                    ToastService.SendToast("Request timeout.");
                });

                return(new List <UnsplashImage>());
            }
            catch (Exception e)
            {
                var task = ExceptionHelper.WriteRecordAsync(e, nameof(ImageDataViewModel), nameof(GetList));
                return(new List <UnsplashImage>());
            }
        }