Exemplo n.º 1
0
 public static WaterfallItemViewModel FromItem(WaterfallItem Item)
 => new WaterfallItemViewModel()
 {
     ItemId       = Item.Id,
     Title        = Item.Title,
     Author       = Item.Author,
     ImageUri     = Item.ImageUri,
     IsBookmarked = Item.IsBookmarked,
     Stars        = Item.Stars,
     Pages        = Item.Pages,
     Width        = Item.Width,
     Height       = Item.Height
 };
        protected override async Task <LoadMoreItemsResult> LoadMoreItemsAsync(CancellationToken c, uint count)
        {
            try
            {
                LoadMoreItemsResult toret = new LoadMoreItemsResult {
                    Count = 0
                };
                if (!HasMoreItems)
                {
                    return(toret);
                }
                PixivCS.Objects.IllustRecommended recommendres = null;
                try
                {
                    Debug.WriteLine($"[RecommendIllustsCollection.LoadMoreItemsAsync]\t{nexturl}");
                    if (nexturl == "begin")
                    {
                        recommendres = await new PixivAppAPI(OverAll.GlobalBaseAPI)
                                       .GetIllustRecommendedAsync();
                    }
                    else
                    {
                        Uri next = new Uri(nexturl);
                        string getparam(string param) => HttpUtility.ParseQueryString(next.Query).Get(param);

                        recommendres = await new PixivAppAPI(OverAll.GlobalBaseAPI)
                                       .GetIllustRecommendedAsync(
                            ContentType: getparam("content_type"),
                            IncludeRankingLabel: bool.Parse(getparam("include_ranking_label")),
                            Filter: getparam("filter"),
                            MinBookmarkIDForRecentIllust: getparam("min_bookmark_id_for_recent_illust"),
                            MaxBookmarkIDForRecommended: getparam("max_bookmark_id_for_recommend"),
                            Offset: getparam("offset"),
                            IncludeRankingIllusts: bool.Parse(getparam("include_ranking_illusts")),
                            IncludePrivacyPolicy: getparam("include_privacy_policy"));
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                    return(toret);
                }
                nexturl = recommendres.NextUrl?.ToString() ?? "";
                Debug.WriteLine($"[RecommendIllustsCollection.LoadMoreItemsAsync]\t{nexturl}");
                if (recommendres.Illusts is null)
                {
                    Debug.WriteLine("出现了NULL");
                    // 这里调用更新身份信息的方法

                    Debug.WriteLine("Done");
                }
                else
                {
                    foreach (var recillust in recommendres.Illusts)
                    {
                        await Task.Run(pause.WaitOne);

                        Debug.WriteLine($"[RecommendIllustsCollection.LoadMoreItemsAsync]\t加载图片:{toret.Count + 1}/{recommendres.Illusts.Length}");
                        if (_emergencyStop)
                        {
                            Debug.WriteLine("_emergencyStop = " + _emergencyStop);
                            nexturl = "";
                            Clear();
                            return(new LoadMoreItemsResult {
                                Count = 0
                            });
                        }
                        WaterfallItem recommendi     = WaterfallItem.FromObject(recillust);
                        var           recommendmodel = ViewModels.WaterfallItemViewModel.FromItem(recommendi);
                        await recommendmodel.LoadImageAsync();

                        Add(recommendmodel);
                        toret.Count++;
                    }
                }
                return(toret);
            }
            finally
            {
                LoadMoreItemsAsync_Finally();
            }
        }
Exemplo n.º 3
0
        protected override async Task <LoadMoreItemsResult> LoadMoreItemsAsync(CancellationToken c, uint count)
        {
            try
            {
                if (!HasMoreItems)
                {
                    return new LoadMoreItemsResult()
                           {
                               Count = 0
                           }
                }
                ;
                LoadMoreItemsResult toret = new LoadMoreItemsResult()
                {
                    Count = 0
                };
                PixivCS.Objects.SearchIllustResult searchres = null;
                try
                {
                    if (nexturl == "begin")
                    {
                        searchres = await new PixivCS
                                    .PixivAppAPI(OverAll.GlobalBaseAPI)
                                    .GetSearchIllustAsync(word, searchTarget, sort, duration);
                    }
                    else
                    {
                        Uri next = new Uri(nexturl);
                        string getparam(string param) => HttpUtility.ParseQueryString(next.Query).Get(param);

                        var test = getparam("duration");
                        searchres = await new PixivCS
                                    .PixivAppAPI(OverAll.GlobalBaseAPI)
                                    .GetSearchIllustAsync(getparam("word"), getparam("search_target"),
                                                          getparam("sort"), getparam("duration"), getparam("filter"), getparam("offset"));
                    }
                }
                catch
                {
                    return(toret);
                }
                nexturl = searchres.NextUrl?.ToString() ?? "";
                foreach (var recillust in searchres.Illusts)
                {
                    await Task.Run(() => pause.WaitOne());

                    if (_emergencyStop)
                    {
                        nexturl = "";
                        Clear();
                        return(new LoadMoreItemsResult()
                        {
                            Count = 0
                        });
                    }
                    WaterfallItem recommendi     = WaterfallItem.FromObject(recillust);
                    var           recommendmodel = ViewModels.WaterfallItemViewModel.FromItem(recommendi);
                    await recommendmodel.LoadImageAsync();

                    Add(recommendmodel);
                    toret.Count++;
                }
                return(toret);
            }
            finally
            {
                _busy = false;
                if (_emergencyStop)
                {
                    nexturl = "";
                    Clear();
                    GC.Collect();
                }
            }
        }
        protected override async Task <LoadMoreItemsResult> LoadMoreItemsAsync(CancellationToken c, uint count)
        {
            try
            {
                LoadMoreItemsResult toret = new LoadMoreItemsResult {
                    Count = 0
                };
                if (!HasMoreItems)
                {
                    return(toret);
                }
                PixivCS.Objects.UserIllusts bookmarkres = null;
                try
                {
                    if (nexturl == "begin")
                    {
                        bookmarkres = await new PixivCS
                                      .PixivAppAPI(OverAll.GlobalBaseAPI)
                                      .GetUserBookmarksIllustAsync(userID);
                    }
                    else
                    {
                        Uri next = new Uri(nexturl);
                        string getparam(string param) => HttpUtility.ParseQueryString(next.Query).Get(param);

                        bookmarkres = await new PixivCS
                                      .PixivAppAPI(OverAll.GlobalBaseAPI)
                                      .GetUserBookmarksIllustAsync(userID, getparam("restrict"),
                                                                   getparam("filter"), getparam("max_bookmark_id"));
                    }
                }
                catch
                {
                    return(toret);
                }
                nexturl = bookmarkres.NextUrl?.ToString() ?? "";
                foreach (var recillust in bookmarkres.Illusts)
                {
                    await Task.Run(() => pause.WaitOne());

                    if (_emergencyStop)
                    {
                        nexturl = "";
                        Clear();
                        return(new LoadMoreItemsResult()
                        {
                            Count = 0
                        });
                    }
                    WaterfallItem recommendi     = WaterfallItem.FromObject(recillust);
                    var           recommendmodel = ViewModels.WaterfallItemViewModel.FromItem(recommendi);
                    await recommendmodel.LoadImageAsync();

                    Add(recommendmodel);
                    toret.Count++;
                }
                return(toret);
            }
            finally
            {
                LoadMoreItemsAsync_Finally();
            }
        }