示例#1
0
        /// <summary>
        /// 作品推送
        /// </summary>
        /// <returns></returns>
        public async Task <ImageInfo> SelectArtWork()
        {
            await listUpdate();

            ImageInfo img = null;

            if (results != null && results.Count > 0)
            {
                string id = "";
                while (true)
                {
                    if (results.TryDequeue(out id))
                    {
                        img = await p.getImageInfo(id);
                    }
                    break;
                }

                if (!await p.downloadImg(img))
                {
                    img = null;
                }
            }
            return(img);
        }
示例#2
0
        /// <summary>
        /// 使用Web模拟登录的选择方式
        /// </summary>
        /// <returns></returns>
        public async Task <ImageInfo> SelectArtWorkV1()
        {
            if (pixiv.token == null || pixiv.token.Equals(""))
            {
                if (c.token.Equals(""))
                {
                    if (!await pixiv.getToken(c.cookie))            //getToken不成功,返回null
                    {
                        return(null);
                    }
                    else                                       //getToken成功,将token写入配置文件
                    {
                        c.cookie = pixiv.cookie;
                        c.token  = pixiv.token;
                    }
                }
                else                                          //配置文件中已有token,直接调用(可能出现token过期情况)
                {
                    pixiv.cookie = c.cookie;
                    pixiv.token  = c.token;
                }
            }

            await ListUpdateV1();

            ImageInfo img = null;

            if (like != null && like.Count != 0)
            {
                while (true)
                {
                    string id = "";
                    if (like.TryDequeue(out id))
                    {
                        img = await pixiv.getImageInfo(id);
                    }
                    if (img != null && img.WHratio >= 1.33 && !img.isR18)
                    {
                        if (!await pixiv.downloadImg(img))         //当获取插画失败时返回null
                        {
                            img = null;
                        }
                        break;
                    }
                }
            }
            else
            {
                //使UI线程调用lambda表达式内的方法

                /*await MainPage.mp.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
                 * {
                 *  //UI code here
                 *  MessageDialog dialog = new MessageDialog("更新推荐列表失败");
                 *  await dialog.ShowAsync();
                 * });*/
                string          title   = "获取pixiv推荐列表失败";
                string          content = "请检查网络连接,并尝试清理cookie与token";
                ToastManagement tm      = new ToastManagement(title, content, ToastManagement.ErrorMessage);
                tm.ToastPush(60);
            }
            return(img);
        }