private object GetChannel(XElement element) { string channelType = GetAttribute(element, "Type"); string name = GetAttribute(element, "Name"); IObjectWithName channel = null; if (channelType == "TcpServerChannel") { int port = int.Parse(GetAttribute(element, "LocalPort")); TcpServerChannel tcpServerChannel = new TcpServerChannel(name, port); channel = tcpServerChannel; } else if (channelType == "TcpClientChannel") { TcpClientChannel tcpClientChannel = null; string ip = GetAttribute(element, "RemoteIP"); int port = int.Parse(GetAttribute(element, "RemotePort")); IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse(ip), port); if (element.Attribute("RetryInterval") != null && !string.IsNullOrEmpty(element.Attribute("RetryInterval").Value)) { int retryInterval = int.Parse(GetAttribute(element, "RetryInterval")); tcpClientChannel = new TcpClientChannel(name, ipEndPoint, retryInterval); } else { tcpClientChannel = new TcpClientChannel(name, ipEndPoint); } channel = tcpClientChannel; } else if (channelType == "UdpChannel") { UdpChannel udpChannel = null; int remotePort = int.Parse(GetAttribute(element, "RemotePort")); int localPort = int.Parse(GetAttribute(element, "LocalPort")); if (element.Attribute("LocalIP") != null && !string.IsNullOrEmpty(element.Attribute("LocalIP").Value)) { string localIP = GetAttribute(element, "LocalIP"); udpChannel = new UdpChannel(name, remotePort, localPort, IPAddress.Parse(localIP)); } else { udpChannel = new UdpChannel(name, remotePort, localPort); } channel = udpChannel; } else if (channelType == "HttpReaderChannel") { HttpReaderChannel httpReaderChannel = null; int remotePort = int.Parse(GetAttribute(element, "RemotePort")); string remoteIP = GetAttribute(element, "RemoteIP"); string requestUrl = GetAttribute(element, "RequestUrl"); string userName = string.Empty; string password = string.Empty; if (element.Attribute("UserName") != null && !string.IsNullOrEmpty(element.Attribute("UserName").Value)) { userName = GetAttribute(element, "UserName"); } if (element.Attribute("Password") != null && !string.IsNullOrEmpty(element.Attribute("Password").Value)) { password = GetAttribute(element, "Password"); } httpReaderChannel = new HttpReaderChannel(name, remoteIP, remotePort, requestUrl, userName, password); channel = httpReaderChannel; } else { throw new UnknownElementException("Unknown channel type:" + channelType); } _adapterObjects[_currentAdapterName].Add(channel.Name, channel); return(channel); }
private object GetChannel(XElement element) { string channelType = GetAttribute(element, "Type"); string name = GetAttribute(element, "Name"); IObjectWithName channel = null; if (channelType == "TcpServerChannel") { int port = int.Parse(GetAttribute(element, "LocalPort")); TcpServerChannel tcpServerChannel = new TcpServerChannel(name, port); channel = tcpServerChannel; } else if (channelType == "TcpClientChannel") { TcpClientChannel tcpClientChannel = null; string ip = GetAttribute(element, "RemoteIP"); int port = int.Parse(GetAttribute(element, "RemotePort")); IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse(ip), port); if (element.Attribute("RetryInterval") != null && !string.IsNullOrEmpty(element.Attribute("RetryInterval").Value)) { int retryInterval = int.Parse(GetAttribute(element, "RetryInterval")); tcpClientChannel = new TcpClientChannel(name, ipEndPoint, retryInterval); } else { tcpClientChannel = new TcpClientChannel(name, ipEndPoint); } channel = tcpClientChannel; } else if (channelType == "UdpChannel") { UdpChannel udpChannel = null; int remotePort = int.Parse(GetAttribute(element, "RemotePort")); int localPort = int.Parse(GetAttribute(element, "LocalPort")); if (element.Attribute("LocalIP") != null && !string.IsNullOrEmpty(element.Attribute("LocalIP").Value)) { string localIP = GetAttribute(element, "LocalIP"); udpChannel = new UdpChannel(name, remotePort, localPort, IPAddress.Parse(localIP)); } else { udpChannel = new UdpChannel(name, remotePort, localPort); } channel = udpChannel; } else if (channelType == "HttpReaderChannel") { HttpReaderChannel httpReaderChannel = null; int remotePort = int.Parse(GetAttribute(element, "RemotePort")); string remoteIP = GetAttribute(element, "RemoteIP"); string requestUrl = GetAttribute(element, "RequestUrl"); string userName = string.Empty; string password = string.Empty; if (element.Attribute("UserName") != null && !string.IsNullOrEmpty(element.Attribute("UserName").Value)) { userName = GetAttribute(element, "UserName"); } if (element.Attribute("Password") != null && !string.IsNullOrEmpty(element.Attribute("Password").Value)) { password = GetAttribute(element, "Password"); } httpReaderChannel = new HttpReaderChannel(name, remoteIP, remotePort, requestUrl, userName, password); channel = httpReaderChannel; } else { throw new UnknownElementException("Unknown channel type:" + channelType); } _adapterObjects[_currentAdapterName].Add(channel.Name, channel); return channel; }