コード例 #1
0
        internal static RankInfo[] AnalyzHtml()
        {
            RankInfo[] ris = new RankInfo[100];

            HtmlAgilityPack.HtmlDocument h = new HtmlAgilityPack.HtmlDocument();

            h.Load(Strings.HTML_PATH);
            for (int i = 0; i < 100; i++)
            {
                ris[i] = new RankInfo();
                HtmlAgilityPack.HtmlNode hn_user  = h.DocumentNode.SelectSingleNode(XPATH_PLAYER1 + (i + 2) + XPATH_PLAYER2);
                HtmlAgilityPack.HtmlNode hn_score = h.DocumentNode.SelectSingleNode(XPATH_SCORE1 + (i + 2) + XPATH_SCORE2);
                HtmlAgilityPack.HtmlNode hn_rank  = h.DocumentNode.SelectSingleNode(XPATH_RANK1 + (i + 2) + XPATH_RANK2);

                ris[i].User  = hn_user.InnerText;
                ris[i].Score = ProductivityInfo.ToInt(hn_score.InnerText);
                ris[i].Rank  = ProductivityInfo.ToInt(hn_rank.InnerText);
            }
            return(ris);
        }
コード例 #2
0
        internal static ConstructionInfo AnalyzHtml()
        {
            ConstructionInfo ci = new ConstructionInfo();
            HtmlDocument     h  = new HtmlAgilityPack.HtmlDocument();

            h.Load(Strings.HTML_PATH);
            //当前金属矿
            int firstN = 0;

            for (int i = 2; i < 8; i++)
            {
                HtmlNode hn_firstcon = h.DocumentNode.SelectSingleNode(string.Format(XPATH_CONSTRUCTION + "/a", i));
                if (hn_firstcon != null && ("金属矿".Equals(hn_firstcon.InnerText.Trim()) || "机器人工厂".Equals(hn_firstcon.InnerText.Trim())))
                {
                    firstN = i;
                    break;
                }
            }
            if (firstN != 0)
            {
                for (int j = firstN; true; j++)
                {
                    HtmlNode hn_con_name     = h.DocumentNode.SelectSingleNode(string.Format(XPATH_CONSTRUCTION + "/a", j));
                    HtmlNode hn_con_next_1st = h.DocumentNode.SelectSingleNode(string.Format(XPATH_CONSTRUCTION + "/b[1]", j));
                    HtmlNode hn_con_next_2nd = h.DocumentNode.SelectSingleNode(string.Format(XPATH_CONSTRUCTION + "/b[2]", j));
                    HtmlNode hn_con_next_3rd = h.DocumentNode.SelectSingleNode(string.Format(XPATH_CONSTRUCTION + "/b[3]", j));

                    HtmlNode hn_con_need_1st = h.DocumentNode.SelectSingleNode(string.Format(XPATH_CONSTRUCTION + "/font/b[1]", j));
                    HtmlNode hn_con_need_2nd = h.DocumentNode.SelectSingleNode(string.Format(XPATH_CONSTRUCTION + "/font//b[2]", j));
                    HtmlNode hn_con_need_3rd = h.DocumentNode.SelectSingleNode(string.Format(XPATH_CONSTRUCTION + "/font//b[3]", j));

                    if (hn_con_name == null)
                    {
                        break;
                    }
                    else
                    {
                        Construction c = new Construction();
                        c.innerText = hn_con_name.InnerText;
                        //如果是地形改造器,则不需要金属。
                        if ("地形改造器".Equals(c.innerText.Trim()))
                        {
                            c.nextMetal = 0;
                            c.needMetal = 0;
                            if (hn_con_next_1st != null)
                            {
                                c.nextCrystal = ProductivityInfo.ToInt(hn_con_next_1st.InnerText);
                            }
                            if (hn_con_next_2nd != null)
                            {
                                c.nextH = ProductivityInfo.ToInt(hn_con_next_2nd.InnerText);
                            }
                            if (hn_con_need_1st != null)
                            {
                                c.needCrystal = ProductivityInfo.ToInt(hn_con_need_1st.InnerText);
                            }
                            if (hn_con_need_2nd != null)
                            {
                                c.needH = ProductivityInfo.ToInt(hn_con_need_2nd.InnerText);
                            }
                        }
                        else
                        {
                            if (hn_con_next_1st != null)
                            {
                                c.nextMetal = ProductivityInfo.ToInt(hn_con_next_1st.InnerText);
                            }
                            if (hn_con_next_2nd != null)
                            {
                                c.nextCrystal = ProductivityInfo.ToInt(hn_con_next_2nd.InnerText);
                            }
                            if (hn_con_next_3rd != null)
                            {
                                c.nextH = ProductivityInfo.ToInt(hn_con_next_3rd.InnerText);
                            }
                            if (hn_con_need_1st != null)
                            {
                                c.needMetal = ProductivityInfo.ToInt(hn_con_need_1st.InnerText);
                            }
                            if (hn_con_need_2nd != null)
                            {
                                c.needCrystal = ProductivityInfo.ToInt(hn_con_need_2nd.InnerText);
                            }
                            if (hn_con_need_3rd != null)
                            {
                                c.needH = ProductivityInfo.ToInt(hn_con_need_3rd.InnerText);
                            }
                        }
                        ci.allCons.Add(c);
                    }
                }
            }
            return(ci);
        }
コード例 #3
0
        internal static void Locations(object o)
        {
            ha = LocationsInfo.PrepareHttpAccesser(universe);
            //ha.Referer = referer;
            ha.Cookies = ccold;
            IEnumerator i = ccnew.GetEnumerator();

            while (i.MoveNext())
            {
                ha.Cookies.Add((Cookie)i.Current);
            }
            ccold = ha.Cookies;
            ccnew = ha.access();
            LocationsInfo[] mylis = LocationsInfo.AnalyzHtml();

            ha.AccessMethod = HttpAccesser.ACCESS_METHOD.POST;
            ha.AccessUrl    = "http://" + universe + ".cicihappy.com/ogame/galaxy.php?mode=1";
            ha.Referer      = "http://" + universe + ".cicihappy.com/ogame/galaxy.php?mode=0";
            //Txtout.writeA("银河系,太阳系,行星,联盟,玩家,星球名,月球,度假\r\n", "balls.csv");
            string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;data source=rank.accdb";

            try
            {
                using (OleDbConnection dbc = new OleDbConnection(connStr))
                {
                    dbc.Open();
                    OleDbDataAdapter adp = new OleDbDataAdapter();
                    adp.SelectCommand = new OleDbCommand(@"select max([_id]) as maxid from scanprocess where not complete", dbc);
                    DataTable dt        = new DataTable();
                    string    processid = string.Empty;
                    bool      usecontinue;
                    adp.Fill(dt);
                    if (dt.Rows.Count > 0 && !dt.Rows[0][0].ToString().Equals(string.Empty))
                    {
                        usecontinue = true;
                        processid   = dt.Rows[0][0].ToString();
                    }
                    else
                    {
                        usecontinue = false;
                    }
                    if (usecontinue)
                    {
                        //找到最后一次扫描的最后一个球的坐标 -- galaxy and solar index
                        adp.SelectCommand = new OleDbCommand(@"select top 1 galaxy, solar from 
    (select *,galaxy * 1000 + solar as xuhao from galaxymap where process = " + processid + @")t1 order by xuhao desc", dbc);
                        dt.Columns.Clear();
                        dt.Clear();
                        adp.Fill(dt);
                        int galaxyStart;
                        int solarStart;
                        if (dt.Rows.Count == 0)
                        {
                            galaxyStart = 1;
                            solarStart  = 1;
                        }
                        else
                        {
                            galaxyStart = ProductivityInfo.ToInt(dt.Rows[0][0].ToString());
                            solarStart  = ProductivityInfo.ToInt(dt.Rows[0][1].ToString());
                        }
                        //根据坐标继续扫描
                        GalaxyLoop(processid, galaxyStart, solarStart, adp, dbc);
                    }
                    else
                    {
                        //创建一个新的扫描过程
                        adp.InsertCommand = new OleDbCommand(@"insert into scanprocess (complete, cdate) values (false, now())", dbc);
                        adp.InsertCommand.ExecuteNonQuery();
                        adp.SelectCommand = new OleDbCommand(@"select max([_id]) as maxid from scanprocess where not complete", dbc);
                        dt.Columns.Clear();
                        dt.Clear();
                        adp.Fill(dt);
                        if (dt.Rows.Count > 0)
                        {
                            processid = dt.Rows[0][0].ToString();
                            //从头扫描
                            GalaxyLoop(processid, 1, 1, adp, dbc);
                        }
                    }
                }
            }
            catch (System.InvalidOperationException ioe)
            {
                if (ioe.ToString().Contains("OLEDB"))
                {
                    MessageBox.Show(ConstString.suggest_db_conn_program_not_install);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }