/// <summary> /// 新增抓取规则 /// </summary> /// <param name="crawlRule"></param> /// <returns></returns> private int SaveCrawlRule(CrawlRuleViewModel crawlRule) { if (string.IsNullOrEmpty(crawlRule.Name) || string.IsNullOrEmpty(crawlRule.Url) || string.IsNullOrEmpty(crawlRule.Partten)) { return(0); } var row = SQLite.ExecuteNonQuery("INSERT INTO crawl_rules(ID, NAME, URL, PARTTEN, MAX_PAGE, ENABLE) VALUES ((SELECT MAX(ID)+1 FROM crawl_rules), @Name, @Url, @Partten, @MaxPage, @Enable)", new List <SQLiteParameter> { new SQLiteParameter("@Name", crawlRule.Name), new SQLiteParameter("@Url", crawlRule.Url), new SQLiteParameter("@Partten", crawlRule.Partten), new SQLiteParameter("@MaxPage", crawlRule.MaxPage), new SQLiteParameter("@Enable", crawlRule.Enable) }); if (row > 0) { //查询最新添加的记录ID var newID = SQLite.sqlone("SELECT MAX(id) FROM crawl_rules", null); crawlRule.Id = Convert.ToInt32(newID); } if (crawlRule.Enable == Convert.ToByte(1)) { ProxyFactoryV2.RestartCrawlIPService(); } return(row); }
/// <summary> /// 表格checkbox点击事件 /// </summary> /// <param name="sender"></param> private void OnGridCheckBoxClick(object sender) { CheckBox checkBox = sender as CheckBox; if (checkBox.Tag.Equals("0")) { //全选 foreach (var crawlRule in CrawlRuls) { crawlRule.EnableView = checkBox.IsChecked.GetValueOrDefault() ? Convert.ToByte(1) : Convert.ToByte(0); } //for (int i = 0; i < mCrawlRulsDataGrid.Items.Count; i++) //{ // //获取行 // DataGridRow neddrow = (DataGridRow)this.mCrawlRulsDataGrid.ItemContainerGenerator.ContainerFromIndex(i); // //获取该行的某列 // CheckBox cb = (CheckBox)this.mCrawlRulsDataGrid.Columns[mCrawlRulsDataGrid.Columns.Count - 1].GetCellContent(neddrow); // cb.IsChecked = checkBox.IsChecked; //} UpdateCrawlRulesEnable(null, checkBox.IsChecked.GetValueOrDefault()); } else { //单选 UpdateCrawlRulesEnable(Convert.ToInt32(checkBox.Tag), checkBox.IsChecked.GetValueOrDefault()); CheckIsCheckedAll(true); } ProxyFactoryV2.RestartCrawlIPService(); }
/// <summary> /// 修改抓取规则 /// </summary> /// <param name="crawlRule"></param> /// <returns></returns> private int ModifyCrawlRule(CrawlRuleViewModel crawlRule) { var row = SQLite.ExecuteNonQuery("UPDATE crawl_rules SET NAME = @Name, URL = @Url, PARTTEN = @Partten, MAX_PAGE = @MaxPage, ENABLE = @Enable WHERE ID = @Id", new List <SQLiteParameter> { new SQLiteParameter("@Name", crawlRule.Name), new SQLiteParameter("@Url", crawlRule.Url), new SQLiteParameter("@Partten", crawlRule.Partten), new SQLiteParameter("@MaxPage", crawlRule.MaxPage), new SQLiteParameter("@Enable", crawlRule.Enable), new SQLiteParameter("@Id", crawlRule.Id) }); if (crawlRule.Enable == Convert.ToByte(1)) { ProxyFactoryV2.RestartCrawlIPService(); } return(row); }
/// <summary> /// 进入页面触发 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void OnPageLoaded(object sender, RoutedEventArgs e) { await ProxyFactoryV2.StartTrack(); }
/// <summary> /// 离开页面触发 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnPageUnloaded(object sender, RoutedEventArgs e) { ProxyFactoryV2.StopTrack(); }