/// <summary> /// 站点登录处理 通过IE /// </summary> /// <param name="imageSite">站点</param> /// <param name="cookie">站点内部cookie, 将返回登录后的cookie, 登录失败为string.Empty</param> /// <param name="LoggedFlags">登录成功页面验证字符, 多个字符用|分隔; 无需验证请置null</param> /// <param name="Sweb">站点内部SessionClient</param> /// <param name="shc">站点内部SessionHeadersCollection</param> /// <param name="PageString">返回验证登录时的页面HTML</param> /// <returns></returns> public static bool LoginSite(IMageSite imageSite, ref string cookie, string LoggedFlags, ref SessionClient Sweb, ref SessionHeadersCollection shc, ref string pageString) { string tmp_cookie = CookiesHelper.GetIECookies(imageSite.SiteUrl); bool result = !string.IsNullOrWhiteSpace(tmp_cookie) && tmp_cookie.Length > 3; if (result) { shc.Timeout = shc.Timeout * 2; shc.Set("Cookie", tmp_cookie); try { pageString = Sweb.Get(imageSite.SiteUrl, Mainproxy, shc); result = !string.IsNullOrWhiteSpace(pageString); if (result && LoggedFlags != null) { string[] LFlagsArray = LoggedFlags.Split('|'); foreach (string Flag in LFlagsArray) { result &= pageString.Contains(Flag); } } cookie = result ? tmp_cookie : cookie; } catch { //有cookie访问时发生超时之类的错误 还是作为用户登录状态 返回true cookie = string.Empty; } } return(result); }
//预加载的页面内容 public string GetPreFetchedPage(int page, int count, string word, IMageSite site) { if (page == prePage && count == preCount && word == preWord && site == preSite) { return(preFetchedPage); } else { return(null); } }
/// <summary> /// do in a separate thread /// 下载缩略图线程 /// </summary> /// <param name="page"></param> /// <param name="count"></param> /// <param name="word"></param> public void PreFetchPage(int page, int count, string word, IMageSite site) { new Thread(new ThreadStart(() => { try { preFetchedPage = site.GetPageString(page, count, word, MainWindow.WebProxy); prePage = page; preCount = count; preWord = word; preSite = site; List <Img> imgs = site.GetImages(preFetchedPage, MainWindow.WebProxy); //获得所有图片列表后反馈得到的数量 PreListLoaded(imgs.Count, null); if (imgs.Count < 1) { return; } SessionClient sweb = new SessionClient(); SessionHeadersCollection shc = new SessionHeadersCollection { Accept = null, ContentType = SessionHeadersValue.ContentTypeAuto, Referer = site.Referer }; shc = site.SiteHeaders; shc.Add("Accept-Ranges", "bytes"); imgs = site.FilterImg(imgs, MainWindow.MainW.MaskInt, MainWindow.MainW.MaskRes, MainWindow.MainW.LastViewed, MainWindow.MainW.MaskViewed, true, false); //预加载缩略图 foreach (HttpWebRequest req1 in imgReqs) { if (req1 != null) { req1.Abort(); } } preFetchedImg.Clear(); imgReqs.Clear(); //prefetch one by one int cacheCount = CachedImgCount < imgs.Count ? CachedImgCount : imgs.Count; for (int i = 0; i < cacheCount; i++) { WebResponse res = sweb.GetWebResponse(imgs[i].PreviewUrl, MainWindow.WebProxy, 10000, shc); System.IO.Stream str = res.GetResponseStream(); if (!preFetchedImg.ContainsKey(imgs[i].PreviewUrl)) { preFetchedImg.Add(imgs[i].PreviewUrl, MainWindow.MainW.CreateImageSrc(str)); } res.Close(); res.Dispose(); str.Close(); str.Dispose(); } } catch { //Console.WriteLine("useless"); } })).Start(); }
/// <summary> /// 构造函数 /// </summary> /// <param name="img">图片</param> /// <param name="index">缩略图位置索引</param> /// <param name="site">图片站点</param> public ImgControl(Img img, int index, IMageSite site) { InitializeComponent(); this.site = site; Image = img; this.index = index; shc.Add("Accept-Ranges", "bytes"); shc.Accept = null; shc.Referer = site.Referer; shc.Timeout = 8000; shc.ContentType = SessionHeadersValue.ContentTypeAuto; if (img.IsViewed) { //statusBorder.Background = new SolidColorBrush(Color.FromArgb(0xCC, 0xFE, 0xE2, 0xE2)); statusBorder.Background = new SolidColorBrush(Color.FromArgb(0xEE, 0xE9, 0x93, 0xAA)); } //try //{ //string s = .Substring(img.Score.IndexOf(' '), img.Score.Length - img.Score.IndexOf(' ')); //score.Text = img.Score.ToString(); //} //catch { } /* * if (!supportScore) * { * brdScr.Visibility = System.Windows.Visibility.Hidden; * }*/ //chk.Text = img.Dimension; //RenderOptions.SetBitmapScalingMode(preview, BitmapScalingMode.Fant); preview.DataContext = img; preview.SizeChanged += new SizeChangedEventHandler(preview_SizeChanged); preview.ImageFailed += new EventHandler <ExceptionRoutedEventArgs>(preview_ImageFailed); preview.MouseUp += new MouseButtonEventHandler(preview_MouseUp); statusBorder.MouseUp += new MouseButtonEventHandler(preview_MouseUp); chk.MouseUp += new MouseButtonEventHandler(preview_MouseUp); txtDesc.MouseUp += new MouseButtonEventHandler(preview_MouseUp); downBtn.MouseUp += new MouseButtonEventHandler(Border_MouseUp); magBtn.MouseUp += new MouseButtonEventHandler(preview_Click); //chk.Click += chk_Checked; //ToolTip tip = preview.ToolTip as ToolTip; //tip.PlacementTarget = preview.Parent as UIElement; //TextBlock desc = (tip.Content as Border).Child as TextBlock; //下载缩略图 //DownloadImg(); if (img.DownloadDetail != null) { //need detail LayoutRoot.IsEnabled = false; //isRetrievingDetail = true; chk.Text = "信息未加载"; } else { ShowImgDetail(); } }
/// <summary> /// 站点登录处理 通过IE /// </summary> /// <param name="imageSite">站点</param> /// <param name="cookie">站点内部cookie, 将返回登录后的cookie, 登录失败为string.Empty</param> /// <param name="LoggedFlags">登录成功页面验证字符, 多个字符用|分隔; 无需验证请置null</param> /// <param name="Sweb">站点内部SessionClient</param> /// <param name="shc">站点内部SessionHeadersCollection</param> /// <returns></returns> public static bool LoginSite(IMageSite imageSite, ref string cookie, string LoggedFlags, ref SessionClient Sweb, ref SessionHeadersCollection shc) { string NullPageString = string.Empty; return(LoginSite(imageSite, ref cookie, LoggedFlags, ref Sweb, ref shc, ref NullPageString)); }
/// <summary> /// 调用站点登录 /// </summary> /// <param name="site">站点</param> /// <param name="loginArgs">登录参数</param> public static void LoginSiteCall(IMageSite site, LoginSiteArgs loginArgs) { try { site.LoginCall(loginArgs); } catch { } }