public void alterDepth(Guid guid, DepthModel model) { addrConfig loc_addrConfig; if (list_addrInfo.Count > 0 && list_addrInfo.Exists(q => q.addrModel.guid == guid)) { loc_addrConfig = list_addrInfo.First(q => q.addrModel.guid == guid); if (loc_addrConfig.list_depthInfo != null && loc_addrConfig.list_depthInfo.Count > 0 && loc_addrConfig.list_depthInfo.Exists(q => q.depthModel.depth == model.depth)) { DepthInfo loc_depthInfo = loc_addrConfig.list_depthInfo.First(q => q.depthModel.depth == model.depth); DepthInfo depthInfo = new DepthInfo(); depthInfo.depthModel = model; depthInfo.list_links = new List <LinkInfo>(); int index = list_addrInfo.FindIndex(q => q.addrModel.guid == guid); list_addrInfo[index].list_depthInfo.Remove(loc_depthInfo); list_addrInfo[index].list_depthInfo.Add(depthInfo); saveAddrInfo(); RefreshDepth(); } else { if (list_addrInfo.Count > 0 && list_addrInfo.Exists(q => q.addrModel.guid == guid)) { loc_addrConfig = list_addrInfo.First(q => q.addrModel.guid == guid); int index = list_addrInfo.IndexOf(loc_addrConfig); if (loc_addrConfig.list_depthInfo == null) { loc_addrConfig.list_depthInfo = new List <DepthInfo>(); } DepthModel loc_depthModel;// = loc_addrConfig.list_depthInfo.OrderBy(q => q.depthModel.depth).Last().depthModel; if (loc_addrConfig.list_depthInfo.Count > 0) { loc_depthModel = loc_addrConfig.list_depthInfo.OrderBy(q => q.depthModel.depth).Last().depthModel; model.depth = loc_depthModel.depth + 1; } else { model.depth = 1; } DepthInfo depthInfo = new DepthInfo(); depthInfo.depthModel = model; depthInfo.list_links = new List <LinkInfo>(); if (loc_addrConfig.list_depthInfo == null) { loc_addrConfig.list_depthInfo.Add(depthInfo); list_addrInfo.RemoveAt(index); list_addrInfo.Insert(index, loc_addrConfig); } list_addrInfo[index].list_depthInfo.Add(depthInfo); saveAddrInfo(); RefreshDepth(); } } } }
public void addDepth(Guid guid, DepthModel model) { if (list_addrInfo.Count > 0 && list_addrInfo.Exists(q => q.addrModel.guid == guid)) { addrConfig loc_addrConfig = list_addrInfo.First(q => q.addrModel.guid == guid); DepthModel loc_depthModel = loc_addrConfig.list_depthInfo.OrderBy(q => q.depthModel.depth).Last().depthModel; model.depth = loc_depthModel.depth + 1; DepthInfo depthInfo = new DepthInfo(); depthInfo.depthModel = model; depthInfo.list_links = new List <LinkInfo>(); list_addrInfo[list_addrInfo.FindIndex(q => q.addrModel.guid == guid)].list_depthInfo.Add(depthInfo); saveAddrInfo(); RefreshDepth(); } }
private void btn_save_Click(object sender, EventArgs e) { if (!Uri.IsWellFormedUriString(tb_addr.Text.Trim(), UriKind.Absolute)) { MessageBox.Show("请输入正确的URL地址!", "提示"); return; } model.addrModel.href = tb_addr.Text.Trim(); model.addrModel.maxDepth = (uint)nud_maxDepth.Value; model.addrModel.maxWndCount = (uint)nud_maxWndCount.Value; model.addrModel.name = tb_name.Text.Trim(); model.addrModel.notice = tb_notice.Text.Trim(); model.addrModel.priority = (uint)nud_priority.Value; model.addrModel.leastVisitTS = (uint)nud_visitTS.Value; model.actived = cb_active.Checked; if (model.addrModel.guid == Guid.Empty) { model.addrModel.guid = Guid.NewGuid(); model.list_depthInfo = new List <DepthInfo>(); DepthInfo depthInfo = new DepthInfo(); depthInfo.depthModel.minActionSpan = 2; depthInfo.depthModel.maxActionSpan = 10; depthInfo.depthModel.depth = 1; depthInfo.depthModel.maxWndCount = 1; depthInfo.depthModel.prefix = model.addrModel.href; depthInfo.list_links = new List <LinkInfo>(); model.list_depthInfo.Add(depthInfo); ((Form1)this.Owner).addAddr(model); MessageBox.Show("添加成功!", "提示"); Close(); } else { ((Form1)this.Owner).alterAddr(model); MessageBox.Show("修改成功!", "提示"); Close(); } }
public void browserCompleted(Guid addrGuid, int depth, List <LinkInfo> list_links) { //List<LinkInfo> loc_adas = list_links.AsEnumerable().Where(q=>q.href.StartsWith("http://www.so.com/s?src=")).ToList(); //return; if (addrGuid != Guid.Empty && list_addrInfo != null && list_addrInfo.Count > 0) { if (list_addrInfo.Exists(q => q.addrModel.guid == addrGuid)) { addrConfig loc_addrConfig = list_addrInfo.Find(q => q.addrModel.guid == addrGuid); int addrIndex = list_addrInfo.FindIndex(q => q.addrModel.guid == addrGuid); if (list_addrInfo[addrIndex].list_depthInfo == null || list_addrInfo[addrIndex].list_depthInfo.Count() <= 0 || !list_addrInfo[addrIndex].list_depthInfo.Exists(q => q.depthModel.depth == depth)) { logOp.writeLog(logfileName, "Depth info error.Guid:" + addrGuid.ToString()); throw new Exception("Depth info error."); } int depthIndex = list_addrInfo[addrIndex].list_depthInfo.FindIndex(q => q.depthModel.depth == depth); if (list_addrInfo[addrIndex].list_depthInfo[depthIndex].list_links == null) { DepthInfo loc_depthInfo = list_addrInfo[addrIndex].list_depthInfo[depthIndex]; loc_depthInfo.list_links = new List <LinkInfo>(); list_addrInfo[addrIndex].list_depthInfo.RemoveAt(depthIndex); list_addrInfo[addrIndex].list_depthInfo.Insert(depthIndex, loc_depthInfo); } //list_addrInfo[addrIndex].list_depthInfo[depthIndex].list_links.Clear(); Random rand = new Random(); if (list_links.Count() > 0) { list_links[0].visitDate = DateTime. Now. AddSeconds(list_addrInfo[addrIndex].list_depthInfo[depthIndex].depthModel.minActionSpan + rand.Next() % (list_addrInfo[addrIndex].list_depthInfo[depthIndex].depthModel.maxActionSpan - list_addrInfo[addrIndex].list_depthInfo[depthIndex].depthModel.minActionSpan)); } for (int i = 1; i < list_links.Count(); i++) { list_links[i].visitDate = list_links[i - 1].visitDate. AddSeconds(list_addrInfo[addrIndex].list_depthInfo[depthIndex].depthModel.minActionSpan + rand.Next() % (list_addrInfo[addrIndex].list_depthInfo[depthIndex].depthModel.maxActionSpan - list_addrInfo[addrIndex].list_depthInfo[depthIndex].depthModel.minActionSpan)); } if (list_addrInfo[addrIndex].list_depthInfo[depthIndex].depthModel.visitTimesLimit > list_addrInfo[addrIndex].list_depthInfo[depthIndex].list_links.Count()) { if (list_addrInfo[addrIndex].list_depthInfo[depthIndex].depthModel.maxWndCount >= list_links.Count) { foreach (LinkInfo item in list_links) { if (!list_addrInfo[addrIndex].list_depthInfo[depthIndex].list_links.Exists(q => q.href == item.href)) { list_addrInfo[addrIndex].list_depthInfo[depthIndex].list_links.Insert(0, item); //list_links; } } } else if (list_links.Count() > 0 && list_addrInfo[addrIndex].list_depthInfo.Count() >= depth) { LinkInfo linkInfo; for (int i = 0; i < list_addrInfo[addrIndex].list_depthInfo[depthIndex].depthModel.maxWndCount && list_addrInfo[addrIndex].list_depthInfo[depthIndex].depthModel.visitTimesLimit > list_addrInfo[addrIndex].list_depthInfo[depthIndex].list_links.Count(); i++) { linkInfo = list_links[rand.Next() % list_links.Count()]; if (!list_addrInfo[addrIndex].list_depthInfo[depthIndex].list_links.Exists(q => q.href == linkInfo.href)) { list_addrInfo[addrIndex].list_depthInfo[depthIndex].list_links.Add(linkInfo); } list_links.Remove(linkInfo); } } } } } }