Esempio n. 1
0
        public void alterAddr(addrConfig model)
        {
            if (list_addrInfo.Count > 0)
            {
                if (model.addrModel.guid != Guid.Empty && list_addrInfo.Exists(q => q.addrModel.guid == model.addrModel.guid))
                {
                    addrConfig loc_model = list_addrInfo.First(q => q.addrModel.guid == model.addrModel.guid);
                    list_addrInfo.Remove(loc_model);
                    if (model.list_depthInfo == null)
                    {
                        model.list_depthInfo = new List <DepthInfo>();
                    }

                    list_addrInfo.Add(model);
                    saveAddrInfo();
                    RefreshAddrInfo();
                    logOp.writeLog(logfileName, "Alter address added.");
                    logOp.writeLog(logfileName, model.addrModel.guid.ToString());
                    logOp.writeLog(logfileName, model.addrModel.href);
                }
                else
                {
                    throw new Exception("Guid is empty or the item is not exists (ALTER).");
                }
            }
            else
            {
                throw new Exception("No members.");
            }
        }
Esempio n. 2
0
        public void addAddr(addrConfig model)
        {
            if (model.addrModel.guid != null)
            {
                if (list_addrInfo.Count > 0 && list_addrInfo.Exists(q => q.addrModel.guid == model.addrModel.guid))
                {
                    throw new Exception("The addr has already existed.");
                }
                if (model.list_depthInfo == null)
                {
                    model.list_depthInfo = new List <DepthInfo>();
                }

                list_addrInfo.Add(model);
                saveAddrInfo();
                RefreshAddrInfo();
                logOp.writeLog(logfileName, "New address added.");
                logOp.writeLog(logfileName, model.addrModel.guid.ToString());
                logOp.writeLog(logfileName, model.addrModel.href);
            }
            else
            {
                throw new Exception("Guid is null.");
            }
        }
Esempio n. 3
0
        public void RefreshDepth()
        {
            dgv_depthInfo.DataSource = null;
            if (dgv_addrInfo.SelectedRows.Count <= 0)
            {
                btn_alterAddr.Enabled = false;
                btn_delAddr.Enabled   = false;
                return;
            }
            addrConfig locAddrConfig = list_addrInfo.First(q => q.addrModel.guid == (Guid.Parse(dgv_addrInfo.SelectedRows[0].Cells[GVARS.addrKey].Value.ToString())));

            if (locAddrConfig.list_depthInfo != null && locAddrConfig.list_depthInfo.Count > 0)
            {
                dgv_depthInfo.DataSource =
                    (from q in locAddrConfig.list_depthInfo.AsEnumerable()
                     select new DepthModel
                {
                    prefix = q.depthModel.prefix,
                    depth = q.depthModel.depth,
                    maxActionSpan = q.depthModel.maxActionSpan,
                    maxWndCount = q.depthModel.maxWndCount,
                    minActionSpan = q.depthModel.minActionSpan
                }
                    ).ToList();
            }
            for (int i = 0; i < dgv_depthInfo.Rows.Count; i++)
            {
                dgv_depthInfo.Rows[i].ReadOnly = true;
            }
            btn_alterAddr.Enabled = true;
            btn_delAddr.Enabled   = true;
        }
Esempio n. 4
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            if (dgv_addrInfo.SelectedRows.Count <= 0 || !list_addrInfo.Exists(q => q.addrModel.guid.ToString() == dgv_addrInfo.SelectedRows[0].Cells[GVARS.addrKey].Value.ToString()))
            {
                return;
            }
            addrConfig loc_addConfig =
                loc_addConfig = list_addrInfo.First(q => q.addrModel.guid.ToString() == dgv_addrInfo.SelectedRows[0].Cells[GVARS.addrKey].Value.ToString());

            list_addrInfo.Remove(loc_addConfig);
            loc_addConfig.list_depthInfo = (List <DepthInfo>)dgv_depthInfo.DataSource;
            RefreshAddrInfo();
        }
Esempio n. 5
0
 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();
     }
 }
Esempio n. 6
0
 public void delAddr(addrConfig model)
 {
     if (model.addrModel.guid != Guid.Empty && list_addrInfo.Exists(q => q.addrModel.guid == model.addrModel.guid))
     {
         addrConfig loc_model = list_addrInfo.First(q => q.addrModel.guid == model.addrModel.guid);
         list_addrInfo.Remove(loc_model);
         saveAddrInfo();
         RefreshAddrInfo();
         logOp.writeLog(logfileName, "Delete address.");
         logOp.writeLog(logfileName, model.addrModel.guid.ToString());
         logOp.writeLog(logfileName, model.addrModel.href);
     }
     else
     {
         throw new Exception("Guid is null or the item is not exists (DEL).");
     }
 }
Esempio n. 7
0
        private void btn_alterDepth_Click(object sender, EventArgs e)
        {
            if (dgv_addrInfo.SelectedRows.Count > 0)
            {
                addrConfig loc_addr =
                    list_addrInfo.First(q => q.addrModel.guid.ToString() == dgv_addrInfo.SelectedRows[0].Cells[GVARS.addrKey].Value.ToString());
                (new editDepth(loc_addr.addrModel.guid, loc_addr.list_depthInfo.Find(q => q.depthModel.depth.ToString() == dgv_depthInfo.SelectedRows[0].Cells[GVARS.depthKey].Value.ToString()).depthModel)).ShowDialog(this);
            }
            return;

            Button loc_btn = (Button)sender;

            if (dgv_depthInfo.SelectedRows.Count <= 0)
            {
                return;
            }
            dgv_depthInfo.SelectedRows[0].ReadOnly = false;
        }
Esempio n. 8
0
        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);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 9
0
        private void scanAddr()
        {
            for (int i = 0; i < list_wbInfo.Count(); i++)
            {
                if (
                    list_wbInfo[i].startDate.AddSeconds(list_wbInfo[i].lastDate) < DateTime.Now &&
                    !list_wbInfo.Exists(q => q.preGuid == list_wbInfo[i].webForm.cur_Guid &&
                                        !list_addrInfo.Find(p => p.addrModel.guid == list_wbInfo[i].webForm.addrGuid).list_depthInfo.Find(p => p.depthModel.depth == list_wbInfo[i].webForm.depth).list_links.Exists(w => w.visited == 0 && w.parent_Guid == list_wbInfo[i].webForm.cur_Guid)
                                        )
                    )
                {
                    addrConfig loc_addr  = list_addrInfo.Find(p => p.addrModel.guid == list_wbInfo[i].webForm.addrGuid);
                    var        loc_links = loc_addr.list_depthInfo.Find(q => q.depthModel.depth == list_wbInfo[i].webForm.depth).list_links.Where(p => p.parent_Guid == list_wbInfo[i].webForm.cur_Guid);
                    Console.WriteLine("closed url:" + list_wbInfo[i].webForm.uri.ToString() + " " + "");
                    list_wbInfo[i].webForm.Close();
                    list_wbInfo.RemoveAt(i);
                }
            }
            Random rand        = new Random();
            int    nextDepthId = -1;//13829617088

            for (int i = 0; i < list_addrInfo.Count(); i++)
            {
                if (!list_addrInfo[i].actived)
                {
                    continue;
                }

                for (int j = 0; j < list_addrInfo[i].list_depthInfo.Count(); j++)
                {
                    tag_BrowserInfo wbInfo;
                    if (list_wbInfo.Count(q => q.webForm.depth == list_addrInfo[i].list_depthInfo[j].depthModel.depth) >= list_addrInfo[i].list_depthInfo[j].depthModel.maxWndCount)
                    {
                        continue;
                    }
                    for (int k = 0; k < list_addrInfo[i].list_depthInfo[j].list_links.Count(); k++)
                    {
                        if (list_wbInfo.Count() >= g_visistConfig.maxWndCount || list_addrInfo[i].list_depthInfo[j].list_links[k].visited == 1 || list_addrInfo[i].list_depthInfo[j].list_links[k].visitDate > DateTime.Now || list_wbInfo.Count(q => q.webForm.depth == list_addrInfo[i].list_depthInfo[j].depthModel.depth) >= list_addrInfo[i].list_depthInfo[j].depthModel.maxWndCount)
                        {
                            continue;
                        }
                        wbInfo      = new tag_BrowserInfo();
                        nextDepthId = list_addrInfo[i].list_depthInfo.FindIndex(q => q.depthModel.depth == (list_addrInfo[i].list_depthInfo[j].depthModel.depth + 1));
                        if (nextDepthId >= 0)
                        {
                            wbInfo.webForm = new webBrowser(new Uri(list_addrInfo[i].list_depthInfo[j].list_links[k].href), list_addrInfo[i].addrModel.guid, list_addrInfo[i].list_depthInfo[nextDepthId].depthModel.prefix, list_addrInfo[i].list_depthInfo[nextDepthId].depthModel.depth);
                        }
                        else
                        {
                            wbInfo.webForm = new webBrowser(new Uri(list_addrInfo[i].list_depthInfo[j].list_links[k].href), list_addrInfo[i].addrModel.guid, list_addrInfo[i].list_depthInfo[j].depthModel.prefix, list_addrInfo[i].list_depthInfo[j].depthModel.depth);
                        }
                        wbInfo.startDate = DateTime.Now;
                        wbInfo.preGuid   = list_addrInfo[i].list_depthInfo[j].list_links[k].parent_Guid;
                        wbInfo.lastDate  = (ulong)(list_addrInfo[i].list_depthInfo[j].depthModel.minLastTime + rand.Next() % (list_addrInfo[i].list_depthInfo[j].depthModel.maxLastTime - list_addrInfo[i].list_depthInfo[j].depthModel.minLastTime));
                        list_wbInfo.Add(wbInfo);
                        list_addrInfo[i].list_depthInfo[j].list_links[k].visited = 1;
                        Console.WriteLine("visited:" + list_addrInfo[i].list_depthInfo[j].list_links.Count(q => q.visited == 1));
                        Console.WriteLine("not visit:" + list_addrInfo[i].list_depthInfo[j].list_links.Count(q => q.visited == 0));
                        if (g_visistConfig.showWnd)
                        {
                            wbInfo.webForm.Show(this);
                        }
                        return;
                    }
                }
            }
        }
Esempio n. 10
0
 public addAddr(addrConfig m = new addrConfig())
 {
     InitializeComponent();
     model = m;
     Inital();
 }