예제 #1
0
        /// <summary>
        /// 取得資料。(奧訊)
        /// </summary>
        /// <param name="html">下載的內容</param>
        /// <param name="find1">關鍵字1</param>
        /// <param name="find2">關鍵字2</param>
        /// <param name="isAcH">是否主客互換</param>
        /// <returns></returns>
        protected Dictionary<string, BasicInfo> GetDataByBet007Basketball(string html, string find1 = null, string find2 = null, bool isAcH = false, string url = null)
        {
            // 沒有資料就離開
            if (string.IsNullOrEmpty(html)) { return null; }

            Dictionary<string, BasicInfo> result = new Dictionary<string, BasicInfo>();
            BasicInfo gameInfo = null;
            DateTime gameDate = this.GameDate;

            XmlAdapter xmlAdapter = null;

            try
            {
                xmlAdapter = new XmlAdapter(html, false);
            }
            catch
            {
                string msg = String.Format("解析網頁資料錯誤。{0}Url: {1}{0}Content: {2}{0}", Environment.NewLine, (url ?? String.Empty), html);
                //throw new Exception(msg, e);
                this.Logs.Error(msg);
                return null;
            }

            if (xmlAdapter == null) { return null; }

            xmlAdapter.GoToNode("c");

            // 所有比賽集合
            List<string> gameRecord = xmlAdapter.GetAllSubColumns("h");

            // 目標比賽集合
            List<string> targetGames = new List<string>();
            foreach (string gameRow in gameRecord)
            {
                if (!String.IsNullOrEmpty(find1) || !String.IsNullOrEmpty(find2))
                {
                    if (gameRow.IndexOf(find1) >= 0 || gameRow.IndexOf(find2) >= 0)
                    {
                        targetGames.Add(gameRow);
                    }
                }
                else
                {
                    // 沒有關鍵字 取全部資料
                    targetGames.Add(gameRow);
                }
            }

            // 有找到目標比賽才繼續執行
            if (targetGames.Count > 0)
            {
                foreach (string game in targetGames)
                {
                    #region 取出資料

                    // 0:賽事ID/3:聯盟(簡,繁)/4:分幾節進行/6:開賽時間/7:狀態/8:小節剩餘時間/10:主隊名(簡,繁,英)/12:客隊名(簡,繁,英)/15:主隊總分/16:客隊總分
                    // 17:主隊1節得分/18:客隊1節得分/19:主隊2節得分/20:客隊2節得分/21:主隊3節得分/22:客隊3節得分/23:主隊4節得分/24:客隊4節得分
                    // 26:主隊ot1得分/27:客隊ot1得分/28:主隊ot2得分/29:客隊ot2得分/30:主隊ot3得分/31:客隊ot3得分
                    string[] data = game.Split('^');

                    #endregion

                    DateTime gameTime = DateTime.Parse(data[6].Replace("<br>", " "));

                    gameInfo = null;
                    gameInfo = new BasicInfo(this.AllianceID, this.GameType, gameTime, data[0], true);
                    gameInfo.AllianceName = data[3].Split(',')[1];
                    gameInfo.Away = GetBet007Team(data[12]);
                    gameInfo.Home = GetBet007Team(data[10]);
                    gameInfo.AcH = isAcH;

                    #region 比賽狀態
                    // 局數
                    int innings = 0;
                    // 比賽狀態
                    string state = data[7];
                    // 剩餘時間
                    string remainingTime = data[8].Trim();
                    // 分節數 ( 2: 上下半場, 4: 4 小節 )
                    int classType = Int32.Parse(data[4]);

                    switch (state)
                    {
                        case "1":
                        case "2":
                        case "3":
                        case "4":
                        case "5":
                        case "6":
                        case "7":
                            innings = Int32.Parse(state);
                            innings = (innings > 4) ? 4 : innings; // 超過4局, 表示 OT, 取4局
                            gameInfo.Status = "0".Equals(remainingTime) ? "結束" : remainingTime; // 剩餘時間
                            gameInfo.GameStates = "S";
                            gameInfo.StateValue = Convert.ToInt32(state);
                            break;
                        case "50":
                            // 中場 (上下半場: 1局, 4小節: 2局)
                            innings = (classType == 2) ? 1 : 2;
                            gameInfo.Status = "中場休息";
                            gameInfo.GameStates = "S";
                            break;
                        case "-1":
                            innings = 4;
                            gameInfo.Status = "結束";
                            gameInfo.GameStates = "E";
                            gameInfo.StateValue = 8;
                            break;
                        case "-2": // 待定
                            gameInfo.Status = "";
                            gameInfo.TrackerText = "只顯示最終比分";
                            gameInfo.Record = "只顯示最終比分";
                            gameInfo.GameStates = "X";
                            break;
                        case "-3":
                            innings = 4;
                            gameInfo.Status = "中止";
                            gameInfo.GameStates = "P";
                            break;
                        case "-4":
                            innings = 4;
                            gameInfo.Status = "取消";
                            gameInfo.GameStates = "C";
                            break;
                        case "-5":
                            innings = 4;
                            gameInfo.Status = "延遲";
                            gameInfo.GameStates = "D";
                            break;
                    }
                    #endregion

                    #region 分數

                    // 算四小節分數
                    for (int i = 0; i < innings; i++)
                    {
                        string ptHome = data[17 + 2 * i].Trim();
                        string ptAway = data[18 + 2 * i].Trim();

                        if (!String.IsNullOrEmpty(ptAway) && !String.IsNullOrEmpty(ptHome))
                        {
                            gameInfo.AwayBoard.Add(ptAway);
                            gameInfo.HomeBoard.Add(ptHome);
                        }
                    }

                    // 取得 OT 數
                    string otCount = data[25].Trim();
                    if (!String.IsNullOrEmpty(otCount))
                    {
                        // 取得 OT 比分
                        int inningOT = Int32.Parse(otCount);
                        for (int i = 0; i < inningOT; i++)
                        {
                            string otHome = StringHelper.IsNullOrEmptyToZero(data[26 + 2 * i]);
                            string otAway = StringHelper.IsNullOrEmptyToZero(data[27 + 2 * i]);

                            gameInfo.AwayBoard.Add(otAway);
                            gameInfo.HomeBoard.Add(otHome);
                        }
                    }

                    // 總分
                    gameInfo.AwayPoint = StringHelper.IsNullOrEmptyToZero(data[16]);
                    gameInfo.HomePoint = StringHelper.IsNullOrEmptyToZero(data[15]);

                    #endregion
                    gameInfo.Display = 1;
                    // 加入
                    result[gameInfo.WebID] = gameInfo;
                }
            }
            else
                return null;

            return result;
        }
예제 #2
0
        /// <summary>
        /// 取得即時比分資料。(奧訊)
        /// </summary>
        /// <param name="html">下載的內容</param>
        /// <returns></returns>
        protected Dictionary<string, BasicInfo> GetChangeByBet007Basketball(string html, string url = null)
        {
            // 沒有資料就離開
            if (string.IsNullOrEmpty(html))
                return null;

            Dictionary<string, BasicInfo> result = new Dictionary<string, BasicInfo>();
            BasicInfo gameInfo = null;
            DateTime gameDate = this.GameDate;

            XmlAdapter xmlAdapter = null;

            try
            {
                xmlAdapter = new XmlAdapter(html, false);
            }
            catch (Exception e)
            {
                string msg = String.Format("解析網頁資料錯誤。{0}Url: {1}{0}Content: {2}{0}", Environment.NewLine, (url ?? String.Empty), html);
                throw new Exception(msg, e);
            }

            if (xmlAdapter == null) { return null; }

            xmlAdapter.GoToNode("c");

            // 所有比賽集合
            List<string> gameRecord = xmlAdapter.GetAllSubColumns("h");

            foreach (string game in gameRecord)
            {
                #region 取出資料

                // 0:賽事ID/1:狀態/2:小節剩餘時間/3:主隊總分/4:客隊總分
                // 5:主隊1節得分/6:客隊1節得分/7:主隊2節得分/8:客隊2節得分/9:主隊3節得分/10:客隊3節得分/11:主隊4節得分/12:客隊4節得分/13:加時數
                // 15:分節數/16:主隊ot1得分/17:客隊ot1得分/18:主隊ot2得分/19:客隊ot2得分/20:主隊ot3得分/21:客隊ot3得分
                string[] data = game.Split('^');

                #endregion

                gameInfo = null;
                gameInfo = new BasicInfo(this.AllianceID, this.GameType, gameDate, data[0], true);

                #region 比賽狀態
                // 局數
                int innings = 0;
                // 比賽狀態
                string state = data[1];
                // 剩餘時間
                string remainingTime = data[2].Trim();
                // 分節數 ( 2: 上下半場, 4: 4 小節 )
                int classType = Int32.Parse(data[15]);
                switch (state)
                {

                    case "1":
                    case "2":
                    case "3":
                    case "4":
                    case "5":
                    case "6":
                    case "7":
                        innings = Int32.Parse(state);
                        innings = (innings > 4) ? 4 : innings; // 超過4局, 表示 OT, 取4局
                        gameInfo.Status = "0".Equals(remainingTime) ? "結束" : remainingTime; // 剩餘時間
                        gameInfo.GameStates = "S";
                        break;
                    case "50":
                        // 中場 (上下半場: 1局, 4小節: 2局)
                        innings = (classType == 2) ? 1 : 2;
                        gameInfo.Status = "中場休息";
                        gameInfo.GameStates = "S";
                        break;
                    case "-1":
                        innings = 4;
                        gameInfo.Status = "結束";
                        gameInfo.GameStates = "E";
                        break;
                    case "-2": // 待定
                        gameInfo.Status = "";
                        gameInfo.TrackerText = "只顯示最終比分";
                        gameInfo.Record = "只顯示最終比分";
                        gameInfo.GameStates = "X";
                        break;
                    case "-3":
                        innings = 4;
                        gameInfo.Status = "中止";
                        gameInfo.GameStates = "P";
                        break;
                    case "-4":
                        innings = 4;
                        gameInfo.Status = "取消";
                        gameInfo.GameStates = "C";
                        break;
                    case "-5":
                        innings = 4;
                        gameInfo.Status = "延遲";
                        gameInfo.GameStates = "D";
                        break;
                }
                #endregion

                #region 分數

                // 算四小節分數
                for (int i = 0; i < innings; i++)
                {
                    string ptHome = data[5 + 2 * i].Trim();
                    string ptAway = data[6 + 2 * i].Trim();

                    if (!String.IsNullOrEmpty(ptAway) && !String.IsNullOrEmpty(ptHome))
                    {
                        gameInfo.AwayBoard.Add(ptAway);
                        gameInfo.HomeBoard.Add(ptHome);
                    }
                }

                // 取得 OT 數
                string otCount = data[13].Trim();
                if (!String.IsNullOrEmpty(otCount))
                {
                    // 取得 OT 比分
                    int inningOT = Int32.Parse(otCount);
                    for (int i = 0; i < inningOT; i++)
                    {
                        string otHome = StringHelper.IsNullOrEmptyToZero(data[16 + 2 * i]);
                        string otAway = StringHelper.IsNullOrEmptyToZero(data[17 + 2 * i]);

                        gameInfo.AwayBoard.Add(otAway);
                        gameInfo.HomeBoard.Add(otHome);
                    }
                }

                // 總分
                gameInfo.AwayPoint = StringHelper.IsNullOrEmptyToZero(data[4]);
                gameInfo.HomePoint = StringHelper.IsNullOrEmptyToZero(data[3]);

                #endregion

                gameInfo.Display = 1;
                // 加入
                result[gameInfo.WebID] = gameInfo;
            }

            return result;
        }
예제 #3
0
파일: Bet007.cs 프로젝트: chanhan/subao_ap
        /// <summary>
        /// 取得奧訊賽程
        /// </summary>
        /// <param name="allianceID"></param>
        /// <param name="gameType"></param>
        /// <param name="lsID"></param>
        /// 
        /// <param name="acH"></param>
        /// <returns></returns>
        private Dictionary<string, GameInfo> GetSchedulesByBet007(int allianceID, string gameType, string lsID, bool acH = false)
        {
            DateTime sDate = txtBet007SDate.Value;
            DateTime eDate = txtBet007EDate.Value;
            DateTime currentDate = sDate;

            WebClient client = new WebClient();
            client.Encoding = Encoding.GetEncoding("gb2312");
            string result = string.Empty;
            string sourceId = GetGameUseSourceID(allianceID, gameType);

            Dictionary<string, GameInfo> schedules = new Dictionary<string, GameInfo>();

            // 尋覽指定日期區間取得資料
            while (currentDate.Date.CompareTo(eDate.Date) <= 0)
            {
                // 下載資料
                try
                {
                    result = client.DownloadString(new Uri(string.Format(@"http://dxbf.bet007.com/nba_date.aspx?time={0}", currentDate.ToString("yyyy-MM-dd"))));
                }
                catch
                {
                    result = client.DownloadString(new Uri(string.Format(@"http://dxbf.titan007.com/nba_date.aspx?time={0}", currentDate.ToString("yyyy-MM-dd"))));
                }

                if (!string.IsNullOrEmpty(result))
                {
                    // 處理 XML
                    XmlAdapter xmlAdapter = new XmlAdapter(result, false);
                    xmlAdapter.GoToNode("c", "m");

                    // 取得所有比賽集合
                    List<string> gameRecord = xmlAdapter.GetAllSubColumns("h");
                    if (gameRecord.Count == 0)
                        return null;

                    // 尋覽取回的資料集
                    foreach (var game in gameRecord)
                    {
                        // 切割資料欄位
                        string[] gameCell = game.Split('^');
                        // 判斷聯盟ID是否等於指定的聯盟
                        if (gameCell[37] == lsID)
                        {
                            GameInfo schedule = null;

                            // 比賽ID
                            string webId = gameCell[0];

                            // 比賽時間
                            DateTime gameTime = DateTime.Parse(gameCell[42] + "年" + gameCell[4].Replace("<br>", " "));

                            schedule = new GameInfo(allianceID, gameType, gameTime, webId);
                            schedule.AcH = acH; // 主客調換

                            // 主隊
                            string homeName =  gameCell[8].Split(',')[2];
                            schedule.Home = homeName.Substring(0, (homeName.IndexOf("[") >= 0) ? homeName.IndexOf("[") : homeName.Length);

                            // 客隊
                            string awayName = gameCell[10].Split(',')[2];
                            schedule.Away = awayName.Substring(0, (awayName.IndexOf("[") >= 0) ? awayName.IndexOf("[") : awayName.Length);

                            // 指定來源
                            schedule.SourceID = sourceId;

                            // 加入賽事
                            schedules[schedule.WebID] = schedule;
                        }
                        else
                            continue;
                    }
                }

                currentDate = currentDate.AddDays(1);
            }

            return schedules;
        }