private static bool IsPassedTime(WhenCrawling when, DateTime old, bool isBoot) { DateTime next = new DateTime(old.Ticks); next = next.AddHours(when.Hour < 0 ? 0 : when.Hour); next = next.AddMinutes(when.Min < 0 ? 0 : when.Min); next = next.AddSeconds(when.Sec < 0 ? 0 : when.Sec); DateTime specificNext = new DateTime( old.Year, old.Month, old.Day, when.Hour < 0 ? 0 : when.Hour, when.Min < 0 ? 0 : when.Min, when.Sec < 0 ? 0 : when.Sec); if (isBoot) { switch (when.When) { case Enums.TimeSpanType.BOOT_PROGRAM: return(true); case Enums.TimeSpanType.SPECIFIC_TIME_FORCE: specificNext = specificNext.AddDays((((int)when.Week - (int)old.DayOfWeek) % 7 + 7) % 7); if (specificNext < old) { return(true); } else if (next.Day == DateTime.Now.Day && specificNext < DateTime.Now) { return(true); } break; } } else { switch (when.When) { case Enums.TimeSpanType.PER_FEW_MINUTES: return((when.Week == Enums.Week.NONE || (int)when.Week == (int)DateTime.Now.DayOfWeek) && DateTime.Now >= next); case Enums.TimeSpanType.SPECIFIC_TIME: case Enums.TimeSpanType.SPECIFIC_TIME_FORCE: return((when.Week == Enums.Week.NONE || (int)when.Week == (int)DateTime.Now.DayOfWeek) && (when.Hour < 0 || next.Hour == DateTime.Now.Hour) && (when.Min < 0 || next.Minute == DateTime.Now.Minute) && (when.Sec < 0 || next.Second == DateTime.Now.Second)); } } return(false); }
public static void StartCrawlings(WhenCrawling when, Crawling crawling, List <string> indexs, bool isBoot) { if (crawling.UrlOptionLIst.Count == 0) { crawling.UrlOptionLIst.Add(new UrlOption()); } try { foreach (UrlOption urlOption in crawling.UrlOptionLIst) { if (IsPassedTime(when, urlOption.LastCrawling, isBoot)) { bool success = StasrtCrawling(urlOption.Option, crawling, indexs); if (success) { urlOption.LastCrawling = DateTime.Now; FileHelper.SaveFile(crawling); } } } } catch { } }