private void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { switch (this.CurrentStatus) { case Synchronizer.Status.Connecting: { this.CurrentStatus = Synchronizer.Status.AddingCategories; this.runWork(); break; } case Synchronizer.Status.AddingCategories: { this.CurrentStatus = Synchronizer.Status.AddingPages; this.runWork(); break; } case Synchronizer.Status.AddingPages: { if (this.index.X >= this.categories.Count) { this.CurrentStatus = Synchronizer.Status.AddingBooks; this.index = new Point(); } this.runWork(); break; } case Synchronizer.Status.AddingBooks: { if (this.index.X >= this.categories.Count) { this.CurrentStatus = Synchronizer.Status.VerifyingBookLinks; this.index = new Point(); } this.runWork(); break; } case Synchronizer.Status.VerifyingBookLinks: { this.runWork(); break; } } }
public void Sync() { this.CurrentStatus = Synchronizer.Status.Connecting; this.categories = new List <Category>(); this.callback(0, "يتم الآن إحصاء أقسام الكتب..."); this.runWork(); while (this.CurrentStatus != Synchronizer.Status.AddingPages) { } addPages(); this.toBeVerified = new List <Book>(); addBooks(); verifyBooks(); this.CurrentStatus = Status.End; //this.callback(0, "يتم الآن تحميل الملفات..."); this.addFilesToDownloadList(); }
private void runWork() { switch (this.CurrentStatus) { case Synchronizer.Status.Connecting: { this.browser.Navigate("http://www.waqfeya.com/index.php"); break; } case Synchronizer.Status.AddingCategories: { Regex regex1 = new Regex("<A title=\"[^\"]+\" href=\"category[.]php[?]cid[=][0-9]+\">[^\"]+</A>"); MatchCollection matchCollections1 = regex1.Matches(this.browser.Document.Body.OuterHtml); this.callback(0, string.Concat("تم العثور على ", matchCollections1.Count, " قسم")); for (var i = 0; i < matchCollections1.Count; i++) { this.categories.Add(this.parseCategory(matchCollections1[i].Value)); } if (matchCollections1.Count <= 0) { this.CurrentStatus = Synchronizer.Status.End; } else { this.callback(Form1.ChoocingCategoriesMsg, this.categories); Application.DoEvents(); while (Form1.UserHasChoosedCategories == 0) { } this.CurrentStatus = Status.AddingPages; } break; } } }
private void runWork_old() { int i; int num; Regex regex; MatchCollection matchCollections; bool flag; int num1; bool count; switch (this.CurrentStatus) { case Synchronizer.Status.Connecting: { this.browser.Navigate("http://www.waqfeya.com/index.php"); break; } case Synchronizer.Status.AddingCategories: { Regex regex1 = new Regex("<A title=\"[^\"]+\" href=\"category[.]php[?]cid[=][0-9]+\">[^\"]+</A>"); MatchCollection matchCollections1 = regex1.Matches(this.browser.Document.Body.OuterHtml); this.callback(0, string.Concat("تم العثور على ", matchCollections1.Count, " قسم")); for (i = 0; i < matchCollections1.Count; i++) { this.categories.Add(this.parseCategory(matchCollections1[i].Value)); } if (matchCollections1.Count <= 0) { this.CurrentStatus = Synchronizer.Status.End; } else { this.callback(Form1.ChoocingCategoriesMsg, this.categories); Application.DoEvents(); while (Form1.UserHasChoosedCategories == 0) { } this.index.X = 0; this.browser.Navigate(this.categories[0].Pages[0]); } break; } case Synchronizer.Status.AddingPages: { if (this.index.X < this.categories.Count) { Regex regex2 = new Regex(string.Concat("<A href[=]\"category[.]php[?]cid[=]", this.categories[this.index.X].Id, "[&]amp;st=[0-9]+\"><U>[0-9]+</U></A>")); MatchCollection matchCollections2 = regex2.Matches(this.browser.Document.Body.OuterHtml); for (i = 0; i < matchCollections2.Count; i++) { num = matchCollections2[i].Value.IndexOf("href=\"") + "href=\"".Length; int num2 = matchCollections2[i].Value.IndexOf('\"', num + 1); string str = matchCollections2[i].Value.Substring(num, num2 - num); str = str.Remove(str.IndexOf("amp;"), 4); this.categories[this.index.X].Pages.Add(string.Concat("http://www.waqfeya.com/", str)); } this.callback((this.index.X + 1) * 100 / this.categories.Count, string.Concat("تم استكشاف الصفحات لقسم ", this.categories[this.index.X].Name)); this.progress.Y = this.progress.Y + this.categories[this.index.X].Pages.Count; } int x = this.index.X + 1; num1 = x; this.index.X = x; if (num1 >= this.categories.Count) { this.toBeVerified = new List <Book>(); this.browser.Navigate(this.categories[0].Pages[0]); } else { this.browser.Navigate(this.categories[this.index.X].Pages[0]); } break; } case Synchronizer.Status.AddingBooks: { if (this.index.X < this.categories.Count) { regex = new Regex("<A title[=]\"اضغط على الرابط وانتظر قليلاً لحين الاتصال بالسيرفر\" href=\"[^\"]+\">[^\"]+</A>"); matchCollections = regex.Matches(this.browser.Document.Body.OuterHtml); List <int> nums = new List <int>(); i = 0; while (true) { int num3 = this.browser.Document.Body.OuterHtml.IndexOf("عنوان الكتاب", i); i = num3; if (num3 < 0) { break; } int num4 = i; i = num4 + 1; nums.Add(num4); } this.addBooksInCurrentCategory(categories[this.progress.X], matchCollections, nums, this.browser.Document.Body.OuterHtml); Synchronizer.ReportProgressCallback reportProgressCallback = this.callback; int x1 = this.progress.X; num1 = x1; this.progress.X = x1 + 1; int y = num1 * 100 / this.progress.Y; object[] objArray = new object[] { "تم استكشاف الكتب في الصفحة ", this.index.Y + 1, " من قسم ", this.categories[this.index.X].Name }; reportProgressCallback(y, string.Concat(objArray)); } if (this.index.X >= this.categories.Count) { count = true; } else { int y1 = this.index.Y + 1; num1 = y1; this.index.Y = y1; count = num1 < this.categories[this.index.X].Pages.Count; } if (!count) { this.index = new Point(this.index.X + 1, 0); } if (this.index.X < this.categories.Count) { this.browser.Navigate(this.categories[this.index.X].Pages[this.index.Y]); } else if (this.toBeVerified.Count <= 0) { this.CurrentStatus = Synchronizer.Status.End; } else { this.callback(0, "يتم الآن إصلاح الروابط غير المباشرة للملفات..."); flag = false; i = 0; while (i < this.toBeVerified.Count) { int num5 = 0; while (num5 < this.toBeVerified[i].URLs.Count) { if (this.isFileLink(this.toBeVerified[i].URLs[num5])) { num5++; } else { this.browser.Navigate(this.toBeVerified[0].URLs[0]); flag = true; break; } } if (!flag) { i++; } else { break; } } } break; } case Synchronizer.Status.VerifyingBookLinks: { if (this.index.X < this.toBeVerified.Count) { regex = new Regex("<A title[=]\"اضغط على الرابط وانتظر قليلاً لحين الاتصال بالسيرفر\" href=\"[^\"]+\">[^\"]+</A>"); matchCollections = regex.Matches(this.browser.Document.Body.OuterHtml); this.toBeVerified[this.index.X].URLs.RemoveAt(this.index.Y); for (i = 0; i < matchCollections.Count; i++) { string value = matchCollections[i].Value; num = value.IndexOf("href=\"") + "href=\"".Length; this.toBeVerified[this.index.X].URLs.Add(value.Substring(num, value.IndexOf('>', num) - 1 - num)); } this.index.Y = this.index.Y + 1; flag = false; while (true) { if (this.index.Y >= this.toBeVerified[this.index.X].URLs.Count) { this.index = new Point(this.index.X + 1, 0); } if (this.index.X < this.toBeVerified.Count) { while (this.index.Y < this.toBeVerified[this.index.X].URLs.Count) { if (this.isFileLink(this.toBeVerified[this.index.X].URLs[this.index.Y])) { this.index.Y = this.index.Y + 1; } else { this.browser.Navigate(this.toBeVerified[this.index.X].URLs[this.index.Y]); flag = true; break; } } if (flag) { break; } } else { break; } } } if (this.index.X >= this.toBeVerified.Count) { this.CurrentStatus = Synchronizer.Status.End; } else { this.browser.Navigate(this.toBeVerified[this.index.X].URLs[this.index.Y]); } break; } } }