// PlayerW 작업 private void RunSchedule(List <DateTime> items) { List <DbItemBase> schedules = new List <DbItemBase>(); DatabaseManager dbMgr = new DatabaseManager(); using (var crawlerMgr = new Crawler.Manager()) { foreach (var item in items) { var tSchedules = crawlerMgr.GetSchedule(item.Year, item.Month); schedules = schedules.Concat(tSchedules).ToList(); } } dbMgr.Save(schedules); }
// 일정불러오기 public void SelectSchedule() { Crawler.Manager mgr = new Crawler.Manager(); Util.DataBaseManager dbMgr = new Util.DataBaseManager(); // 일정불러오기 var allSchedule = dbMgr.SelectAll<Schedule>(); Int32 year = 2010; Int32 month = 3; if(allSchedule.Count() > 0) { year = (from schedule in allSchedule select schedule.Year).Max(); month = (from schedule in allSchedule where schedule.Year == year select schedule.Month).Max(); } DateTime startDate = new DateTime(year, month, 1); DateTime endDate = DateTime.Now; try { Int32 errorCount = 0; while (startDate <= endDate) { try { var data = mgr.GetSchedule(startDate.Year, startDate.Month); var scheduleTable = dbMgr.DataContext.GetTable<Schedule>(); var delSchedule = from schedule in allSchedule where schedule.Year == startDate.Year && schedule.Month == startDate.Month select schedule; foreach (var schedule in delSchedule) { scheduleTable.DeleteOnSubmit(schedule); } dbMgr.DataContext.SubmitChanges(); dbMgr.Save(data); startDate = startDate.AddMonths(1); errorCount = 0; } catch (OpenQA.Selenium.StaleElementReferenceException exception) { if (errorCount < 10) { errorCount++; continue; } else { throw exception; } } } } finally { mgr.Dispose(); } }
// 일정불러오기 public void SelectSchedule() { Crawler.Manager mgr = new Crawler.Manager(); Util.DataBaseManager dbMgr = new Util.DataBaseManager(); // 일정불러오기 var allSchedule = dbMgr.SelectAll <Schedule>(); Int32 year = 2010; Int32 month = 3; if (allSchedule.Count() > 0) { year = (from schedule in allSchedule select schedule.Year).Max(); month = (from schedule in allSchedule where schedule.Year == year select schedule.Month).Max(); } DateTime startDate = new DateTime(year, month, 1); DateTime endDate = DateTime.Now; try { Int32 errorCount = 0; while (startDate <= endDate) { try { var data = mgr.GetSchedule(startDate.Year, startDate.Month); var scheduleTable = dbMgr.DataContext.GetTable <Schedule>(); var delSchedule = from schedule in allSchedule where schedule.Year == startDate.Year && schedule.Month == startDate.Month select schedule; foreach (var schedule in delSchedule) { scheduleTable.DeleteOnSubmit(schedule); } dbMgr.DataContext.SubmitChanges(); dbMgr.Save(data); startDate = startDate.AddMonths(1); errorCount = 0; } catch (OpenQA.Selenium.StaleElementReferenceException exception) { if (errorCount < 10) { errorCount++; continue; } else { throw exception; } } } } finally { mgr.Dispose(); } }