private void BW_DoWork(object sender, DoWorkEventArgs e) { while (currChapter != "-1") { try { //string url = txt_Url.Text; //BW.ReportProgress(0, "开始下载..."); string url = @"http://a.heiyan.com/ajax/chapter/content/{0}?callback=jQuery183042279977366378296_1489487599999&_=1489487600401"; url = string.Format(url, currChapter); if (!string.IsNullOrEmpty(url)) { string html = httper.GetHtml(new HttpItem() { URL = url }); //txt_Content.Text = HttpHelper.GetUrl(url); if (!string.IsNullOrEmpty(html)) { int startIndex = html.IndexOf("({") + 1; html = html.Substring(startIndex, html.Length - 1 - startIndex); var book_chapter = JsonConvert.DeserializeObject <heiyan_chapter>(html); var title = book_chapter.chapter.title; var content = book_chapter.chapter.htmlContent; content = content.Replace("“", "“").Replace("”", "”"); content = content.Replace("<p>", "").Replace(@"</p>", "\r\n"); content = content.Replace("…", "...").Replace(@"—", "-"); bookStr += string.Format("{0}\r\n\r\n{1}\r\n\r\n", title, content); //txt_Content.Text = bookStr; currChapter = book_chapter.nextChapterId; BW.ReportProgress(100, book_chapter.chapter.title); } } } catch (Exception ex) { //MessageBox.Show(ex.Message); currChapter = "-1"; } } }
public override void RunUpload(IEnumerable <PictureItem> items, BackgroundWorker bw) { this.BW = bw; this.RootFolder = FTPSettings.Server + FTPSettings.InternalFTPFolder; CreateDirectory(this.RootFolder); string rootF = RootFolder + @"/" + this.UploadFolder; CreateDirectory(rootF); RootFolder = rootF + @"/"; BW.ReportProgress(0, "Сохранение фото..."); ProgressTicker ticker = new ProgressTicker(items.Count(), 20); ticker.ProgressChanged += Ticker_ProgressChanged; foreach (var item in items) { try { if (!ImageDownloadHelper.IsUrlImage((item.Address))) { throw new Exception("Скачиваемый контент не является графическим изображением."); } byte[] imageByteArray = ImageDownloadHelper.DownloadData(item.Address); string ext = imageByteArray.GetExtention(); string pictureName = $"{item.Name}.{ext}"; item.Address = UploadPicture(imageByteArray, pictureName); item.Status = true; ticker.Tick(); } catch (Exception ex) { item.Status = false; item.Address += $" Ошибка: {ex.Message}."; } } ticker = null; }
//Načtení anime private void BW_DoWork(object sender, DoWorkEventArgs e) { DataTable DT = DatabaseSelect("SELECT TOP " + SQLCount + " * FROM (SELECT TOP " + SQLCount + " * FROM (SELECT TOP " + (SQLPage * SQLCount) + " * FROM anime ORDER BY CStr([anime]![anime_nazevjap]) ASC) ORDER BY CStr([anime]![anime_nazevjap]) DESC) ORDER by CStr([anime]![anime_nazevjap]) ASC", null, false); for (int i = 0; i < DT.Rows.Count; i++) { if (BW.CancellationPending) { break; } Loading = false; AnimeID.Add(DT.Rows[i]["id_anime"].ToString()); if (File.Exists(GlobalAdresar + @"Accounts\!imgs\" + DT.Rows[i]["anime_obr"].ToString())) { StreamReader cti = new StreamReader(GlobalAdresar + @"Accounts\!imgs\" + DT.Rows[i]["anime_obr"].ToString()); Image img = Image.FromStream(cti.BaseStream); if (BW.CancellationPending) { break; } img = RoundCorners(img, 10, Color.Transparent); if (BW.CancellationPending) { break; } img = resizeImage(img, new Size(250, 200)); if (BW.CancellationPending) { break; } img = Lighter(img); if (BW.CancellationPending) { break; } BW.ReportProgress(i, img); cti.Close(); } else { BW.ReportProgress(i, new Bitmap(1, 1)); } while (true) { if (Loading) { break; } if (BW.CancellationPending) { break; } Thread.Sleep(1); } } }