public void Execute(IJobExecutionContext context) { //IDbCommandInterceptor interceptor = new DbCommandInterceptor(); //dbcontext.Session.AddInterceptor(interceptor); DateTime dt = DateTime.Now; string shortdate = dt.ToString("yyyy-MM-dd"); IQuery <Page> cpq = dbcontext.Query <Page>(); IQuery <Chapter> cq = dbcontext.Query <Chapter>(); List <Page> plst = cpq.Where(a => a.pagelocal.Length == 0).Take(20).ToList(); HttpWebHelper web = new HttpWebHelper(); foreach (var p in plst) { try { Stream stream = web.GetStream("http://cdn.sns.dongmanmanhua.cn/20150119_288/1421677325732TxLNo_JPEG/thumbnail_ipad.jpg"); Image img = Image.FromStream(stream); stream.Close(); string filePath = AppDomain.CurrentDomain.BaseDirectory + "DownLoadImgs/" + p.Id + ".jpg"; img.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg); string localimg = UcHelper.uploadFile("Page/" + p.Id + ".jpg", filePath); p.pagelocal = localimg; p.modify = dt; dbcontext.Update(p); dbcontext.Update <Chapter>(a => a.Id == p.chapterid, a => new Chapter() { downstatus = DownChapter.完图片, modify = dt }); File.Delete(filePath); } catch (Exception ex) { logger.Error(ex.Message); //Chapter chapter = cq.Where(x => x.Id == p.chapterid).FirstOrDefault(); //chapter.retry = chapter.retry + 1; //chapter.modify = dt; //dbcontext.Update(chapter); dbcontext.Update <Chapter>(a => a.Id == p.chapterid, a => new Chapter() { retry = a.retry + 1, modify = dt }); Err_PageJob err = new Err_PageJob(); err.imgurl = p.pagesource; err.source = p.source; err.errtype = ErrPage.限制访问; err.modify = dt; err.shortdate = shortdate; err.message = ex.Message; err = dbcontext.Insert(err); continue; } } }
public void Execute(IJobExecutionContext context) { //IDbCommandInterceptor interceptor = new DbCommandInterceptor(); //dbcontext.Session.AddInterceptor(interceptor); DateTime dt = DateTime.Now; string shortdate = dt.ToString("yyyy-MM-dd"); IQuery <Comic> comicq = dbcontext.Query <Comic>(); IQuery <Chapter> cpq = dbcontext.Query <Chapter>(); List <Chapter> plst = cpq.Where(a => a.chaptersource.Length != 0 && a.chapterlocal.Length == 0).TakePage(1, 20).ToList(); HttpWebHelper web = new HttpWebHelper(); foreach (var p in plst) { try { string refer = ""; if (p.source == Source.dongmanmanhua) { var comic = comicq.Where(x => x.comicid == p.comicid).FirstOrDefault(); refer = comic.bookurl; } Stream stream = web.GetStream(p.chaptersource, 300, "", null, refer, null); Image img = Image.FromStream(stream); stream.Close(); string filePath = AppDomain.CurrentDomain.BaseDirectory + "DownLoadImgs/" + p.Id + ".jpg"; img.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg); string localimg = UcHelper.uploadFile("Chapter/" + p.Id + ".jpg", filePath); p.chapterlocal = localimg; p.modify = dt; dbcontext.Update(p); } catch (Exception ex) { Err_ChapterJob err = new Err_ChapterJob(); err.bookurl = p.chapterurl; err.errtype = ErrChapter.图片出错; err.modify = dt; err.shortdate = shortdate; err.message = ex.Message; err = dbcontext.Insert(err); continue; } } }
public void Execute(IJobExecutionContext context) { //IDbCommandInterceptor interceptor = new DbCommandInterceptor(); //dbcontext.Session.AddInterceptor(interceptor); DateTime dt = DateTime.Now; string shortdate = dt.ToString("yyyy-MM-dd"); IQuery <Comic> cpq = dbcontext.Query <Comic>(); List <Comic> plst = cpq.Where(a => a.comiccoverlocal.Length == 0).TakePage(1, 20).ToList(); HttpWebHelper web = new HttpWebHelper(); foreach (var p in plst) { try { Stream stream = web.GetStream(p.comiccoversource); Image img = Image.FromStream(stream); stream.Close(); string filePath = AppDomain.CurrentDomain.BaseDirectory + "DownLoadImgs/" + p.Id + ".jpg"; img.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg); string localimg = UcHelper.uploadFile("Comic/" + p.Id + ".jpg", filePath); p.comiccoverlocal = localimg; p.modify = dt; dbcontext.Update(p); } catch (Exception ex) { Err_ComicJob err = new Err_ComicJob(); err.bookurl = p.bookurl; err.errtype = ErrComic.图片出错; err.modify = dt; err.shortdate = shortdate; err.message = ex.Message; err = dbcontext.Insert(err); continue; } } }
public void Execute(IJobExecutionContext context) { //IDbCommandInterceptor interceptor = new DbCommandInterceptor(); //dbcontext.Session.AddInterceptor(interceptor); DateTime dt = DateTime.Now; string shortdate = dt.ToString("yyyy-MM-dd"); IQuery <Page> cpq = dbcontext.Query <Page>(); IQuery <Chapter> cq = dbcontext.Query <Chapter>(); List <Page> plst; if (m_DownTotal > 0) { plst = cpq.Where(a => a.pagestate == PageState.None && a.Id % m_DownTotal == m_DownIndex).Take(100).ToList(); } else { plst = cpq.Where(a => a.pagestate == PageState.None).Take(100).ToList(); } //if (plst.Count < pageSize) // pageIndex = 1; //else // pageIndex++; HttpWebHelper web = new HttpWebHelper(); foreach (var p in plst) { string filePath = AppDomain.CurrentDomain.BaseDirectory + "DownLoadImgs/" + p.Id + ".jpg"; try { string refer = ""; if (p.source == Source.dongmanmanhua || p.source == Source.dmzj) { var chapter = cq.Where(x => x.chapterid == p.chapterid).FirstOrDefault(); refer = chapter.chapterurl; Stream stream = web.GetStream(p.pagesource, 3000, "", null, refer, null); Image img = Image.FromStream(stream); stream.Close(); img.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg); } else { WebClient myclient = new WebClient(); myclient.DownloadFile(p.pagesource, filePath); } string localimg = UcHelper.uploadFile("Page/" + p.Id + ".jpg", filePath); p.pagelocal = localimg; p.pagestate = PageState.成功; p.modify = dt; dbcontext.Update(p); File.Delete(filePath); } catch (Exception ex) { try { WebClient myclient = new WebClient(); myclient.DownloadFile(p.pagesource, filePath); Bitmap bytes; using (WebP webp = new WebP()) bytes = webp.Load(filePath); File.Delete(filePath); bytes.Save(filePath); string localimg = UcHelper.uploadFile("Page/" + p.Id + ".jpg", filePath); p.pagelocal = localimg; p.modify = dt; p.pagestate = PageState.成功; dbcontext.Update(p); File.Delete(filePath); continue; } catch (Exception) { logger.Error(ex.Message); Chapter chapter = cq.Where(x => x.chapterid == p.chapterid).FirstOrDefault(); chapter.retry = chapter.retry + 1; chapter.modify = dt; if (chapter.retry > 30) { p.pagestate = PageState.失败; p.modify = dt; dbcontext.Update(p); } dbcontext.Update(chapter); //dbcontext.Update<Chapter>(a => a.chapterid == p.chapterid, a => new Chapter() //{ // retry = a.retry + 1, // modify = dt //}); Err_PageJob err = new Err_PageJob(); err.imgurl = p.pagesource; err.source = p.source; err.errtype = ErrPage.限制访问; err.modify = dt; err.shortdate = shortdate; err.message = ex.Message; err = dbcontext.Insert(err); continue; } } } }