/// <summary> /// 從\Config\BankConfig.xml載入連線銀行元件設定資料 /// </summary> /// <param name="id">群組的id</param> public void LoadBankConnectionConfig(string id) { if (this.DicALOL.Count == 0) { log.Debug("開始讀取Xml設定檔"); string path = AppDomain.CurrentDomain.BaseDirectory; try { string fullPath = path + "Config\\BankConfig.xml"; log.Debug("Full Path:" + fullPath); XElement xRoot = XElement.Load(fullPath);//load all elements //Enumerable all XElement by the condition IEnumerable <XElement> xElements = xRoot.XPathSelectElements("//Connections[@id='" + id + "']//Connection"); foreach (XElement xe in xElements) { string bankCode = xe.Attribute("BankCode") != null?xe.Attribute("BankCode").Value : "None"; string messageType = xe.Attribute("MessageType") != null?xe.Attribute("MessageType").Value : "None"; bool isSendALOL = (xe.Attribute("SendSocket") != null && xe.Attribute("SendSocket").Value.ToUpper() == "YES") ? true : false; string[] Config = xe.Value.Split(':');//取得設定資料127.0.0.1:999:10000:ASCII:6000:180000 if (Config.Length != 6) { log.Error("BankCode:" + bankCode + "的Xml設定檔未滿6項"); continue; } string ip = Config[0]; int port = Convert.ToInt32(Config[1]); int sendTimeout = Convert.ToInt32(Config[2]); Encoding encode = GetEncoding(Config[3]); int connectTimeout = Convert.ToInt32(Config[4]); int echoTimeout = Convert.ToInt32(Config[5]); log.Debug("BankCode:" + bankCode + " MessageType:" + messageType + " IP:" + ip + " port:" + port + " sendTimeout:" + sendTimeout + " Encode:" + Config[3] + " connectTimeout:" + connectTimeout + " echoTimeout:" + echoTimeout); ALOLAsync aLOLComponent = new ALOLAsync(bankCode, messageType, ip, port, sendTimeout, encode, connectTimeout, echoTimeout); log.Debug("DicALOL(Count:" + this.DicALOL.Count + ")字典集合加入一組連線元件 => key:" + (bankCode + messageType)); if (isSendALOL) { // AP(Client) ==socket==>> (Server)this(Client) ==socket==>> (Server)Bank // <<==socket== <<==socket== this.SendALOL = aLOLComponent; } //add this.DicALOL.Add((bankCode + messageType), aLOLComponent); } } catch (Exception ex) { log.Error("讀取XML異常:" + ex.ToString()); } } }
/// <summary> /// (Old Version)從Xml資源檔載入設定元件資料 /// </summary> public void LoadALOLAsyncConfig(string xmlTagName) { if (this.DicALOL.Count == 0) { log.Debug("開始讀取Xml設定檔"); string path = AppDomain.CurrentDomain.BaseDirectory; XmlDocument xml = new XmlDocument(); try { string fullPath = path + "Config\\BankConfig.xml"; log.Debug("Full Path:" + fullPath); xml.Load(fullPath); XmlNodeList nodes = xml.GetElementsByTagName(xmlTagName); foreach (XmlNode node in nodes) { XmlElement xElement = node as XmlElement; XmlAttributeCollection attrCollection = node.Attributes; //Attributes string bankCode = attrCollection.GetNamedItem("BankCode").Value; string messageType = attrCollection.GetNamedItem("MessageType").Value; string sendSocket = attrCollection.GetNamedItem("SendSocket").Value; xElement.HasAttribute("SendSocket"); if (this.DicALOL.ContainsKey(messageType)) { log.Error("此Key:" + messageType + "已存在於字典檔"); continue; } //var s2 = node.Attributes.Item(1).Value; //InnerXml Data string[] Config = node.InnerXml.Split(':');//取得設定資料127.0.0.1:999:10000:ASCII:6000:180000 string ip = Config[0]; int port = Convert.ToInt32(Config[1]); int sendTimeout = Convert.ToInt32(Config[2]); Encoding encode = GetEncoding(Config[3]); int connectTimeout = Convert.ToInt32(Config[4]); int echoTimeout = Convert.ToInt32(Config[5]); log.Debug("IP:" + ip + " port:" + port + " sendTimeout:" + sendTimeout + " Encode:" + Config[3] + " connectTimeout:" + connectTimeout + " echoTimeout:" + echoTimeout); ALOLAsync ALOLComponent = new ALOLAsync(bankCode, messageType, ip, port, sendTimeout, encode, connectTimeout, echoTimeout); //add //this.AlolList.Add((bankCode + messageType), ALOLComponent); log.Debug("AlolList字典集合加入一組連線元件 => key:" + messageType); this.DicALOL.Add(messageType, ALOLComponent); } } catch (Exception ex) { log.Error("讀取XML異常:" + ex.ToString()); } } }