コード例 #1
0
ファイル: Form1.cs プロジェクト: sorainnosia/HwzCrawler
        private void button1_Click(object sender, EventArgs e)
        {
            bool requireLogin = AppConfig.GetRequireLogin();

            if (requireLogin && (string.IsNullOrEmpty(txtUsername.Text) || string.IsNullOrEmpty(txtPassword.Text)))
            {
                MessageBox.Show("Invalid user login");
                return;
            }
            if (requireLogin)
            {
                string str = ScrapperMinPool.RunSingle(AppConfig.GetScriptPrefix() + "SBF_LOGIN", new string[] { txtUsername.Text, txtPassword.Text });
                if (str == "FAIL LOGIN")
                {
                    MessageBox.Show("Invalid user login");
                    return;
                }
            }

            AppConfig.AddOrUpdateAppSettings("User", txtUsername.Text);
            AppConfig.AddOrUpdateAppSettings("Pass", txtPassword.Text);
            if (AppLicense.IsValid("", "", AppConfig.GetLicense()) == false)
            {
                MessageBox.Show("Invalid License Key");
                return;
            }
            Form2 frm = new Form2(txtUsername.Text, txtPassword.Text);

            frm.ShowDialog();
        }
コード例 #2
0
ファイル: AppLibrary.cs プロジェクト: sorainnosia/HwzCrawler
        public void StartReal()
        {
            InitAll();
            string uu = AppConfig.GetThreadLink();

            int pageIndex = 1;

            while (IsRunningAll)
            {
                pageIndex++;
                string   scriptprefix = AppConfig.GetScriptPrefix();
                string[] ts           = ScrapperMinPool.RunMultiple(scriptprefix + PageScript, new string[] { User, Pass, pageIndex.ToString() });

                if ((ts == null || ts.Length == 0))
                {
                    pageIndex = 1;
                    continue;
                }

                List <string> threads = new List <string>();
                string[]      doms    = AppConfig.GetIgnoreDomains().Split(new char[] { '\n' });
                if (doms != null && doms.Length > 0 && doms[0] == "")
                {
                    doms = new string[0];
                }
                List <string> domains = new List <string>();
                if (doms.Length > 0 && doms[0] != "")
                {
                    foreach (string dom in doms)
                    {
                        domains.Add(dom.Trim());
                    }
                }

                foreach (string str in ts)
                {
                    string[] ss = str.Split(new char[] { ' ' });
                    if (ss == null || ss.Length != 2)
                    {
                        continue;
                    }

                    int t = 0;
                    if (int.TryParse(ss[1], out t) == false)
                    {
                        continue;
                    }

                    int maxPage = AppConfig.GetMaxThreadPage();
                    if (t > maxPage && maxPage != 0)
                    {
                        string sss = string.Format(uu, ss[0], t.ToString());
                        AddLog("[Skip] ExceedMaxPageThread:true, url:'" + sss + "'");
                        continue;
                    }

                    for (int i = 1; i <= t; i++)
                    {
                        string sss = string.Format(uu, ss[0], i.ToString());
                        if (ALL.Contains(sss))
                        {
                            continue;
                        }

                        bool contains = false;
                        foreach (string dom in domains)
                        {
                            if (sss.ToLower().Contains(dom.ToLower()))
                            {
                                AddLog("[Skip] IgnoreDomains:'" + dom + "', url:'" + sss + "'");
                                contains = true;
                                break;
                            }
                        }
                        if (contains)
                        {
                            continue;
                        }

                        string s = ss[0] + " " + i.ToString();
                        if (threads.Contains(s) == false)
                        {
                            threads.Add(s);
                        }
                    }
                }

                Parallel.ForEach(threads,
                                 new ParallelOptions {
                    MaxDegreeOfParallelism = AppConfig.GetParallelism()
                },
                                 t =>
                {
                    if (IsRunningAll == false)
                    {
                        return;
                    }
                    if (AppConfig.GetFirstPage())
                    {
                        return;
                    }
                    try
                    {
                        AddLink(t);
                    }
                    catch (Exception ex) { AddLog("[Fail] Add Log " + ex.Message); }

                    lock (ThreadsLock) ThreadsDone++;
                    if (ThreadsDone == threads.Count)
                    {
                        lock (ThreadsLock) ThreadsDone = 0;
                    }
                });

                if (AppConfig.GetFirstPage())
                {
                    return;
                }
            }
        }