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 static object CreateChildAdapter(this IDictionaryAdapter parent, Type type, XmlAdapter adapter, IDictionary dictionary)
		{
			if (null == dictionary)
				dictionary = new Hashtable();

			var descriptor = parent.Meta.CreateDescriptor();
		    parent.This.Descriptor.CopyBehaviors(descriptor);
		    descriptor.AddBehavior(adapter);

		    return parent.This.Factory.GetAdapter(type, dictionary, descriptor);
		}
Ejemplo n.º 3
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.º 4
0
 private void SaveConfig(string configFile, ConfigurationManager config)
 {
     try
     {
         using (var stream = CreateFile(configFile))
             using (var adapter = new XmlAdapter(stream))
             {
                 config.Save(adapter);
             }
     }
     catch (Exception exc)
     {
         if (exc.IsCritical())
         {
             throw;
         }
         LoggingService.Global.Error(exc);
     }
 }
Ejemplo n.º 5
0
		public override void SetValue(IXmlNode node, IDictionaryAdapter parent, IXmlAccessor accessor, ref object value)
		{
			// Require a dictionary adapter
			var source = value as IDictionaryAdapter;
			if (source == null)
				throw Error.NotDictionaryAdapter("value");

			// Detect assignment of own value
			var sourceAdapter = XmlAdapter.For(source, false);
			if (sourceAdapter != null && node.PositionEquals(sourceAdapter.Node))
				return;

			// Create a fresh component
			var targetAdapter = new XmlAdapter(node.Save(), XmlAdapter.For(parent).References);
			if (sourceAdapter != null)
				targetAdapter.References.UnionWith(sourceAdapter.References);
			var component = (IDictionaryAdapter) parent.CreateChildAdapter(node.ClrType, targetAdapter);

			// Copy value onto fresh component
			source.CopyTo(component);
			value = component;
		}
Ejemplo n.º 6
0
        public static void Sample_ReadXml_WriteSqlite_Address()
        {
            string sampleDataPath = @"..\..\Samples\";
            var    watch          = new Stopwatch();

            using (var reader = new XmlAdapter())
            {
                reader.FileName = sampleDataPath + @"GetAddressResponse.xml";
                reader.XPath    = "/GetAddressResponse/GetAddressResult/result/address";

                using (var writer = new SqliteAdapter())
                {
                    writer.FileName = sampleDataPath + @"flatxml.sqlite";
                    writer.CreateNewFile();

                    if (!writer.Connect())
                    {
                        throw new Exception("No connection");
                    }

                    watch.Start();
                    int lineCount = 0;

                    reader.ReadData(30)
                    .ForEach(x =>
                    {
                        Console.WriteLine("Tablename=" + x.TableName + ", Count=" + x.Rows.Count);
                        lineCount += x.Rows.Count;
                    })
                    .Do(x => writer.WriteData(x));

                    writer.Disconnect();

                    watch.Stop();
                    Console.WriteLine("lineCount=" + lineCount + ", Time=" + watch.Elapsed);
                    Console.ReadLine();
                }
            }
        }
Ejemplo n.º 7
0
        private ConfigurationManager LoadConfig(string configFile, string configName)
        {
            ConfigurationManager config = null;

            if (FileExists(configFile))
            {
                try
                {
                    using (var stream = OpenFile(configFile))
                    {
                        if (stream.Length != 0)
                        {
                            using (var adapter = new XmlAdapter(stream))
                            {
                                try
                                {
                                    config = new ConfigurationManager(adapter);
                                }
                                catch (Exception exc) when(!exc.IsCritical())
                                {
                                    LoggingService.Global.Error(exc);
                                }
                            }
                        }
                    }
                }
                catch (Exception exc) when(!exc.IsCritical())
                {
                    LoggingService.Global.Error(exc);
                }
            }
            if (config == null)
            {
                config = new ConfigurationManager(configName);
            }
            return(config);
        }
Ejemplo n.º 8
0
        public void DeserializeFromString(string xml)
        {
            InitializeOptionsList();

            var buffer = Encoding.UTF8.GetBytes(xml);

            using (var memoryStream = new MemoryStream(buffer))
            {
                var adapter = new XmlAdapter(memoryStream);
                var service = new OptionsDeserializationService(adapter);
                XmlSerializerExtensions.Adapter = adapter;

                adapter.Reader.ReadToFollowing(_options[0].GetType().Name);

                foreach (var option in _options)
                {
                    var optionTree = adapter.Reader.ReadSubtree();
                    optionTree.Read();
                    service.DecodeObject(optionTree, option);
                    optionTree.Close();
                    adapter.Reader.Read();
                }
            }
        }
Ejemplo n.º 9
0
        public void Test_Rss_Focus()
        {
            DataTable rssFeeds = null;
            var       request  = WebRequest.Create("http://rss.focus.de/fol/XML/rss_folnews.xml") as HttpWebRequest;

            if (request != null)
            {
                using (var response = request.GetResponse() as HttpWebResponse)
                {
                    using (var responseStream = response.GetResponseStream())
                    {
                        using (var reader = new XmlAdapter(responseStream))
                        {
                            reader.XPath = "/rss/channel/item";

                            rssFeeds = reader.ReadAllData();
                        }
                    }
                }
            }

            Assert.IsNotNull(rssFeeds);
            Assert.IsTrue(rssFeeds.Rows.Count > 0);
        }
Ejemplo n.º 10
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.º 11
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.º 12
0
 private static IVirtual AsVirtual(object source)
 {
     return(XmlAdapter.For(source));
 }
Ejemplo n.º 13
0
		public override object GetValue(IXmlNode node, IDictionaryAdapter parent, IXmlAccessor accessor)
		{
			var adapter = new XmlAdapter(node.Save(), XmlAdapter.For(parent).References);
			return parent.CreateChildAdapter(node.ClrType, adapter);
		}
Ejemplo n.º 14
0
		public override object GetStub(IXmlNode node, IDictionaryAdapter parent, IXmlAccessor accessor)
		{
			// TODO: Refactor
			var adapter = new XmlAdapter(node, XmlAdapter.For(parent).References);
			return parent.CreateChildAdapter(accessor.ClrType, adapter);
		}
Ejemplo n.º 15
0
        // 接收到資料
        private static void ProcessData(string msg, Socket handler)
        {
            try
            {
                // 讀取設定
                XmlAdapter xmlAdapter = new XmlAdapter(msg, true);
                string cmd = xmlAdapter.ReadXmlNode("Command");
                string name = xmlAdapter.ReadXmlNode("Process");
                string date = xmlAdapter.ReadXmlNode("Date");
                string curkey = "";
                bool isNotSameDate = false;//開賽時間不同
                DateTime gameTime = DateTime.Now;

                //設定當前指定跟分的索引
                curkey = name.Replace("(", "").Replace(")", "").ToUpper();
                if (formMain.CurProcessType.ContainsKey(curkey))
                    name = formMain.CurProcessType[curkey];//ex:將(MLB) 指定成(MLB-ESPN)
                if (curkey.IndexOf("-") != -1)
                    curkey = curkey.Substring(0, curkey.IndexOf("-"));

                if (string.IsNullOrEmpty(date))//若無使定開賽時間則取緩存
                {
                    if (formMain.CurProcessTime.ContainsKey(curkey))
                        date = formMain.CurProcessTime[curkey];//取得當前比賽的指定時間
                }
                else
                {
                    if (DateTime.TryParse(date, out gameTime))
                    {

                        if (formMain.CurProcessTime.ContainsKey(curkey) == false || //指定開賽時間不存在
                            (formMain.CurProcessTime.ContainsKey(curkey) && gameTime > DateTime.Parse(formMain.CurProcessTime[curkey])))//新的開賽時間與舊開賽時間比舊的開賽時間較新
                        {
                            isNotSameDate = true;
                            formMain.CurProcessTime[curkey] = date;//設定當前比賽的指定時間
                        }
                    }
                }

                // 判斷命令
                if (cmd == "open")
                {
                    // 執行程式清單
                    foreach (Dictionary<string, string> process in formMain.ProcessList)
                    {
                        if (process["Name"] == name)//多來源的當前指定來源
                        {
                            formMain.CheckTypeProcess(process);

                            process.OpenProcess(gameTime.ToString("yyyy/MM/dd_HH:mm"));//日期合法代入日期參數
                        }
                    }
                }
                else if (cmd == "kill")
                {
                    // 執行程式清單
                    foreach (Dictionary<string, string> process in formMain.ProcessList)
                    {
                        if (process["Name"].ToUpper().IndexOf(curkey) == 1)//模糊比對  ex: (Football)  <-> FOOTBALL
                        {
                            // 關閉程式
                            process.KillProcess();
                        }
                    }
                }
                else if (cmd == "run")//只有Monitor會送出此請求
                {

                    // 執行程式清單
                    foreach (Dictionary<string, string> process in formMain.ProcessList)
                    {
                        if (process["Name"] == name)
                        {
                            // 找到程式但開賽時間不同
                            if (process.FindProcess())
                            {
                                if (isNotSameDate == true)
                                {
                                    process.KillProcess();
                                    process.OpenProcess(gameTime.ToString("yyyy/MM/dd_HH:mm"));//日期合法代入日期參數
                                }
                            }
                            else// 沒有找到程式 直接開啟
                                process.OpenProcess(gameTime.ToString("yyyy/MM/dd_HH:mm"));//日期合法代入日期參數
                        }
                    }
                }

                //更新介面狀態
                formMain.UpdateStatus();
            }
            catch (Exception ex)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("ProcessData Error!!");
                sb.AppendLine("msg: " + msg);
                sb.AppendLine("Message: " + ex.Message);
                sb.AppendLine("StackTrace:");
                sb.AppendLine(ex.StackTrace);

                ServerError.Error(sb.ToString());
            }
        }
Ejemplo n.º 16
0
		public static object CreateChildAdapter(this IDictionaryAdapter parent, Type type, XmlAdapter adapter)
		{
			return CreateChildAdapter(parent, type, adapter, null);
		}
Ejemplo n.º 17
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));
        }
Ejemplo n.º 18
0
 private ConfigurationManager LoadConfig(string configFile, string configName)
 {
     ConfigurationManager config = null;
     if(FileExists(configFile))
     {
         try
         {
             using(var stream = OpenFile(configFile))
             {
                 if(stream.Length != 0)
                 {
                     using(var adapter = new XmlAdapter(stream))
                     {
                         try
                         {
                             config = new ConfigurationManager(adapter);
                         }
                         catch(Exception exc)
                         {
                             if(exc.IsCritical())
                             {
                                 throw;
                             }
                             LoggingService.Global.Error(exc);
                         }
                     }
                 }
             }
         }
         catch(Exception exc)
         {
             if(exc.IsCritical())
             {
                 throw;
             }
             LoggingService.Global.Error(exc);
         }
     }
     if(config == null)
     {
         config = new ConfigurationManager(configName);
     }
     return config;
 }
Ejemplo n.º 19
0
        public static void DeserializeOptions(string xml, DatabaseSchemaView dbView, ISupportOptions withOptions)
        {
            var buffer = Encoding.UTF8.GetBytes(xml);

            using (var memoryStream = new MemoryStream(buffer))
            {
                var adapter = new XmlAdapter(memoryStream);
                var service = new OptionsDeserializationService(adapter);
                XmlSerializerExtensions.Adapter = adapter;

                var metadataService = new MetadataDeserializationService(adapter);

                adapter.Reader.ReadToFollowing(Constants.BehaviorOptionsTag);
                var behaviorOptionsTree = adapter.Reader.ReadSubtree();
                behaviorOptionsTree.Read();
                service.DecodeObject(behaviorOptionsTree, withOptions.BehaviorOptions);
                behaviorOptionsTree.Close();
                adapter.Reader.Read();

                var dbViewOptionsTree = adapter.Reader.ReadSubtree();
                dbViewOptionsTree.Read();
                service.DecodeObject(dbViewOptionsTree, dbView.Options);
                dbViewOptionsTree.Close();
                adapter.Reader.Read();

                var designPaneOptionsTree = adapter.Reader.ReadSubtree();
                designPaneOptionsTree.Read();
                service.DecodeObject(designPaneOptionsTree, withOptions.DesignPaneOptions);
                designPaneOptionsTree.Close();
                adapter.Reader.Read();

                var visualOptionsTree = adapter.Reader.ReadSubtree();
                visualOptionsTree.Read();
                service.DecodeObject(visualOptionsTree, withOptions.VisualOptions);
                visualOptionsTree.Close();
                adapter.Reader.Read();

                var addObjectDialogOptionsTree = adapter.Reader.ReadSubtree();
                addObjectDialogOptionsTree.Read();
                service.DecodeObject(addObjectDialogOptionsTree, withOptions.AddObjectDialogOptions);
                addObjectDialogOptionsTree.Close();
                adapter.Reader.Read();

                var dataSourceOptionsTree = adapter.Reader.ReadSubtree();
                dataSourceOptionsTree.Read();
                service.DecodeObject(dataSourceOptionsTree, withOptions.DataSourceOptions);
                dataSourceOptionsTree.Close();
                adapter.Reader.Read();

                var metadataLoadingOptionsTree = adapter.Reader.ReadSubtree();
                metadataLoadingOptionsTree.Read();
                metadataService.DecodeMetadataLoadingOptions(metadataLoadingOptionsTree, withOptions.MetadataLoadingOptions);
                metadataLoadingOptionsTree.Close();
                adapter.Reader.Read();

                var metadataStructureOptionsTree = adapter.Reader.ReadSubtree();
                metadataStructureOptionsTree.Read();
                service.DecodeObject(metadataStructureOptionsTree, withOptions.MetadataStructureOptions);
                metadataStructureOptionsTree.Close();
                adapter.Reader.Read();

                var queryColumnListTree = adapter.Reader.ReadSubtree();
                queryColumnListTree.Read();
                service.DecodeObject(queryColumnListTree, withOptions.QueryColumnListOptions);
                queryColumnListTree.Close();
                adapter.Reader.Read();

                var queryNavBarTree = adapter.Reader.ReadSubtree();
                queryNavBarTree.Read();
                service.DecodeObject(queryNavBarTree, withOptions.QueryNavBarOptions);
                queryNavBarTree.Close();
                adapter.Reader.Read();

                var userInterfaceOptionsTree = adapter.Reader.ReadSubtree();
                userInterfaceOptionsTree.Read();
                service.DecodeObject(userInterfaceOptionsTree, withOptions.UserInterfaceOptions);
                userInterfaceOptionsTree.Close();
                adapter.Reader.Read();

                var sqlFormattingOptionsTree = adapter.Reader.ReadSubtree();
                sqlFormattingOptionsTree.Read();
                service.DecodeObject(sqlFormattingOptionsTree, withOptions.SqlFormattingOptions);
                sqlFormattingOptionsTree.Close();
                adapter.Reader.Read();

                var sqlGenerationOptionsTree = adapter.Reader.ReadSubtree();
                sqlGenerationOptionsTree.Read();
                service.DecodeObject(sqlGenerationOptionsTree, withOptions.SqlGenerationOptions);
                sqlGenerationOptionsTree.Close();
                adapter.Reader.Read();
            }
        }
Ejemplo n.º 20
0
		private void AddValue(Entry entry, Type type, object value, XmlAdapter xmlAdapter)
		{
			if (xmlAdapter == null)
				xmlAdapter = XmlAdapter.For(value, false);

			AddValueCore(entry, type, value, true);

			if (xmlAdapter != null)
				AddValueCore(entry, typeof(XmlAdapter), xmlAdapter, true);
		}
Ejemplo n.º 21
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.º 22
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.º 23
0
 private void SaveConfig(string configFile, ConfigurationManager config)
 {
     try
     {
         using(var stream = CreateFile(configFile))
         using(var adapter = new XmlAdapter(stream))
         {
             config.Save(adapter);
         }
     }
     catch(Exception exc)
     {
         if(exc.IsCritical())
         {
             throw;
         }
         LoggingService.Global.Error(exc);
     }
 }