Ejemplo n.º 1
0
        static void Main()
        {
            #region 讀取設定
            string xmlFile = string.Format(@"{0}\{1}.xml", Application.StartupPath, System.IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath));
            // 取得資料
            if (System.IO.File.Exists(xmlFile))
            {
                try
                {
                    XmlAdapter xmlAdapter = null;
                    // 資料庫
                    xmlAdapter = new XmlAdapter(xmlFile);
                    xmlAdapter.GoToNode("XML", "Database");
                    // 設定
                    frmMain.SqlServer = xmlAdapter.ReadXmlNode("SqlServer");
                    frmMain.SqlDB = xmlAdapter.ReadXmlNode("DB");
                    frmMain.SqlUID = xmlAdapter.ReadXmlNode("UID");
                    frmMain.SqlPWD = xmlAdapter.ReadXmlNode("PWD");
                    // 伺服器
                    xmlAdapter = new XmlAdapter(xmlFile);
                    xmlAdapter.GoToNode("XML", "Server");
                    // 設定
                    frmMain.ServerIp = xmlAdapter.ReadXmlNode("Ip");
                    frmMain.ServerPort = xmlAdapter.ReadXmlNode("Port");
                }
                catch { }
            }
            #endregion

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmMain());
        }
Ejemplo n.º 2
0
        public frmMain()
        {
            InitializeComponent();
            // 設定
            this.Icon = Properties.Resources.Console;
            // 讀取設定檔
            XmlAdapter xmlAdapter;
            // 設定 IP
            xmlAdapter = new XmlAdapter(CONFIG_FILE_PATH);
            xmlAdapter.GoToNode("XML", "Server");
            this.tsptxbServerIp.Text = xmlAdapter.ReadXmlNode("Ip");
            this.tsptxbServerPort.Text = xmlAdapter.ReadXmlNode("Port");
            // 讀取執行程式清單
            xmlAdapter = new XmlAdapter(CONFIG_FILE_PATH);
            xmlAdapter.GoToNode("XML", "Processes");
            // 建立執行程式
            try
            {
                this.ProcessList = xmlAdapter.GetAllSubNodes("Process", "Name", "Path", "Command", "Description", "Default");
            }catch
            {
                MessageBox.Show(this, "載入Process設定檔失敗。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                // 寫入記錄
                ServerWork.Error("載入Process設定檔失敗");
                Application.Exit();
            }

            // 多跟分來源的當前來源
            this.CurProcessType = new Dictionary<string, string>();
            this.CurProcessTime = new Dictionary<string, string>();

            //設定預設值 KEY統一大寫
            foreach (var process in this.ProcessList)
            {
                if (process["Default"] == "true")
                {
                    string key = process["Name"].Replace("(", "").Replace(")", "").ToUpper();
                    if (key.IndexOf("-") != -1)
                        key = key.Substring(0, key.IndexOf("-"));

                    this.CurProcessType.Add(key, process["Name"]);
                }
            }

            logClear = new LogClear();
            Task.Factory.StartNew(() => logClear.Work(), TaskCreationOptions.LongRunning);
        }
Ejemplo n.º 3
0
        public FrmMain()
        {
            InitializeComponent();
            // 設定
            this.Icon = Properties.Resources.Control;
            // 建立記錄檔操作
            //this.FileLog = new SHGG.FileService.ErrorNote(LOG_FILE_PATH);
            // 讀取設定檔
            XmlAdapter xmlAdapter;
            // 讀取伺服器清單
            xmlAdapter = new XmlAdapter(CONFIG_FILE_PATH);
            xmlAdapter.GoToNode("XML", "Servers");
            this.ServersList = xmlAdapter.GetAllSubNodes("Server", "Name", "Ip", "Port");
            // 加入清單
            foreach (Dictionary<string, string> server in this.ServersList)
            {
                this.tspcbbServerIp.Items.Add(string.Format("{0}", server["Name"]));
            }
            // 預設
            this.tspcbbServerIp.SelectedIndex = 0;
            // 讀取執行程式清單
            xmlAdapter = new XmlAdapter(CONFIG_FILE_PATH);
            xmlAdapter.GoToNode("XML", "Processes");
            this.ProcessList = xmlAdapter.GetAllSubNodes("Process", "Name", "Description");

            // WS client timeout 時間
            int timeout;
            if (!Int32.TryParse(ConfigurationManager.AppSettings["WSTimeout"], out timeout))
            {
                timeout = 120;
            }

            // 轉為毫秒
            timeout *= 1000;
            _wsCommon.Timeout = timeout;
        }
Ejemplo n.º 4
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;
        }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
0
        /// <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;
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            bool startToFollow = false;
            ESport sport = ESport.None;
            DateTime gameDate = DateTime.Now.AddDays(-100);

            #region 讀取參數
            string sGameDate = null;
            foreach (string cmd in args)
            {
                if (cmd.ToLower() == "follow")
                    startToFollow = true;
                if (cmd.IndexOf("_") != -1)//有找到特殊的時間參數格式 yyyy/MM/dd_hh:mm
                    sGameDate = cmd.Replace("_", " ");//還原時間格式
                else
                    sport = GetSportType(cmd);
            }

            if (!string.IsNullOrEmpty(sGameDate))//時間參數不為空
                DateTime.TryParse(sGameDate, out gameDate);

            #endregion
            #region 讀取設定
            string xmlFile = string.Format(@"{0}\{1}.xml", Application.StartupPath, System.IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath));
            // 取得資料
            if (System.IO.File.Exists(xmlFile))
            {
                try
                {
                    XmlAdapter xmlAdapter = new XmlAdapter(xmlFile);
                    xmlAdapter.GoToNode("XML", "Database");
                    // 設定
                    frmMain.SqlServer = xmlAdapter.ReadXmlNode("SqlServer");
                    frmMain.SqlDB = xmlAdapter.ReadXmlNode("DB");
                    frmMain.SqlUID = xmlAdapter.ReadXmlNode("UID");
                    frmMain.SqlPWD = xmlAdapter.ReadXmlNode("PWD");

                    bool tmpBool = true;
                    if (bool.TryParse(xmlAdapter.ReadXmlNode("WRITE"), out tmpBool))//是否寫入DB
                        frmMain.WRITE = tmpBool;
                    else
                        frmMain.WRITE = true;

                    //讀取墨西哥棒球 冬季賽季
                    xmlAdapter = new XmlAdapter(xmlFile);
                    xmlAdapter.GoToNode("XML", "BBLMP");
                    frmMain.bblmp_season = xmlAdapter.ReadXmlNode("season");

                    //读取日本篮球帐号密码
                    xmlAdapter = new XmlAdapter(xmlFile);
                    xmlAdapter.GoToNode("XML", "BKBJ");
                    frmMain.bkbj_user = xmlAdapter.ReadXmlNode("user");
                    frmMain.bkbj_pwd = xmlAdapter.ReadXmlNode("pwd");

                    //读取使用代理设定的秒数
                    xmlAdapter = new XmlAdapter(xmlFile);
                    xmlAdapter.GoToNode("XML", "ProxySettings");
                    frmMain.UseProxy = Convert.ToInt32(xmlAdapter.ReadXmlNode("UseProxySeconds"));
                    // WKBL
                    //xmlAdapter = new XmlAdapter(xmlFile);
                    //xmlAdapter.GoToNode("XML", "WKBL");
                    //Sports.BkWKBL.Proxy = xmlAdapter.ReadXmlNode("Proxy");
                }
                catch { }
            }
            #endregion

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmMain(startToFollow, sport, gameDate));
        }