private static object[] GetFactoryParams(XmlSetting paramEntry) { if (null == paramEntry) { return(null); } ArrayList factoryParams = new ArrayList(); foreach (XmlSetting paramNode in paramEntry.Select("param")) { string paramType = paramNode.ReadSetting("@type"); string paramValue = paramNode.ReadSetting("@value"); switch (paramType) { case "string": factoryParams.Add(paramValue); break; case "int": factoryParams.Add(int.Parse(paramValue)); break; } } if (factoryParams.Count > 0) { return(factoryParams.ToArray()); } return(null); }
static DispatchImpl ReadDispatch(XmlSetting xmlSetting, int level, log4net.ILog logger) { if (null == xmlSetting) { return(null); } string value = xmlSetting.ReadSetting("@value", null); string alias = xmlSetting.ReadSetting("@alias", null); string key = xmlSetting.ReadSetting("@key", null); if (string.IsNullOrEmpty(value) && string.IsNullOrEmpty(key)) { return(null); } DispatchImpl impl = new DispatchImpl(); impl.Result.Key = key; impl.Result.Value = value; impl.Result.Alias = alias; impl.Result.Separator = xmlSetting.ReadSetting("@separator", null); impl.Result.Dynamic = xmlSetting.ReadSetting("@dynamic", null); logger.Logger.Log(typeof(Dispatcher), log4net.Core.Level.Verbose, string.Format("{0} key={1},value={2},alias={3},separator={4},dynamic={5}" , new string(' ', level) , impl.Result.Key , impl.Result.Value , impl.Result.Alias , impl.Result.Separator , impl.Result.Dynamic), null); if (string.IsNullOrEmpty(key)) { return(impl); } foreach (XmlSetting child in xmlSetting.Select("*")) { DispatchImpl ch = ReadDispatch(child, ++level, logger); if (null == ch) { continue; } impl.Childs[ch.Result.Value] = ch; } return(impl); }
public static InternalSession CreateInternalSession(XmlSetting entry) { string nm = entry.ReadSetting("@Name", ""); string brokerUri = entry.ReadSetting("@value"); object[] factoryParams = GetFactoryParams(entry.SelectOne("FactoryParams")); string clientId = entry.ReadSetting("ClientId/@value", null); // GetNodeValueAttribute(uriNode, "clientId", "NMSTestClientId"); string userName = entry.ReadSetting("UserName/@value"); //GetNodeValueAttribute(uriNode, "userName", "guest"); string passWord = entry.ReadSetting("PassWord/@value"); //GetNodeValueAttribute(uriNode, "passWord", "guest"); //string queueName = entry.ReadSetting("QueueName/@value"); //GetNodeValueAttribute(uriNode, "QueueName", "QueueName"); int timeout = 0; if (!int.TryParse(entry.ReadSetting("Timeout/@value", null), out timeout)) { timeout = 5; } try { Apache.NMS.NMSConnectionFactory nmsFactory = (null == factoryParams) ? new Apache.NMS.NMSConnectionFactory(brokerUri) : new Apache.NMS.NMSConnectionFactory(brokerUri, factoryParams); IConnection newConnection = nmsFactory.ConnectionFactory.CreateConnection(userName, passWord); if (newConnection == null) { throw new ApplicationException(string.Format("创建到 {0} 的连接失败!", brokerUri)); } newConnection.RequestTimeout = TimeSpan.FromSeconds(timeout); if (!string.IsNullOrEmpty(clientId)) { newConnection.ClientId = clientId; } return(new InternalSession(nm, newConnection , entry.ReadSetting("modelDestinationName/@value") , entry.ReadSetting("alertDestinationName/@value") , entry.ReadSetting("perfDestinationName/@value") , entry.ReadSetting("deskDestinationName/@value"))); } catch (Exception e) { return(new InternalSession(nm, new ApplicationException(string.Format("创建到 {0} 的连接失败!", brokerUri), e))); } }
public static void ReadDispatch(XmlSetting xmlSetting, Dispatcher dispatcher, log4net.ILog logger) { dispatcher.Key = xmlSetting.ReadSetting("@key", null); if (string.IsNullOrEmpty(dispatcher.Key)) { return; } foreach (XmlSetting child in xmlSetting.Select("*")) { DispatchImpl ch = ReadDispatch(child, 1, logger); if (null == ch) { continue; } dispatcher.Childs[ch.Result.Value] = ch; } }
public static Session Create(XmlSetting xmlSetting) { InternalSession defaultSession = CreateInternalSession(xmlSetting.SelectOne("/configuration/MQs/DefaultMQ")); Session session = new Session(defaultSession); XmlSetting[] mqSettings = xmlSetting.Select("/configuration/MQs/MQ"); if (null == mqSettings || 0 == mqSettings.Length) { return(session); } foreach (XmlSetting mqSetting in mqSettings) { session.Add(CreateInternalSession(mqSetting)); } return(session); }
public static InternalSession CreateInternalSession(XmlSetting entry) { string nm = entry.ReadSetting("@Name", ""); string brokerUri = entry.ReadSetting("@value"); object[] factoryParams = GetFactoryParams(entry.SelectOne("FactoryParams")); string clientId = entry.ReadSetting("ClientId/@value", null);// GetNodeValueAttribute(uriNode, "clientId", "NMSTestClientId"); string userName = entry.ReadSetting("UserName/@value"); //GetNodeValueAttribute(uriNode, "userName", "guest"); string passWord = entry.ReadSetting("PassWord/@value"); //GetNodeValueAttribute(uriNode, "passWord", "guest"); //string queueName = entry.ReadSetting("QueueName/@value"); //GetNodeValueAttribute(uriNode, "QueueName", "QueueName"); int timeout = 0; if (!int.TryParse(entry.ReadSetting("Timeout/@value", null), out timeout)) timeout = 5; try { Apache.NMS.NMSConnectionFactory nmsFactory = (null == factoryParams) ? new Apache.NMS.NMSConnectionFactory(brokerUri) : new Apache.NMS.NMSConnectionFactory(brokerUri, factoryParams); IConnection newConnection = nmsFactory.ConnectionFactory.CreateConnection(userName, passWord); if (newConnection == null) throw new ApplicationException(string.Format("创建到 {0} 的连接失败!", brokerUri)); newConnection.RequestTimeout = TimeSpan.FromSeconds(timeout); if (!string.IsNullOrEmpty(clientId)) newConnection.ClientId = clientId; return new InternalSession(nm, newConnection , entry.ReadSetting("modelDestinationName/@value") , entry.ReadSetting("alertDestinationName/@value") , entry.ReadSetting("perfDestinationName/@value") , entry.ReadSetting("deskDestinationName/@value")); } catch (Exception e) { return new InternalSession(nm, new ApplicationException(string.Format("创建到 {0} 的连接失败!", brokerUri), e)); } }
public static Session Create(XmlSetting xmlSetting) { InternalSession defaultSession = CreateInternalSession(xmlSetting.SelectOne("/configuration/MQs/DefaultMQ")); Session session = new Session(defaultSession); XmlSetting[] mqSettings = xmlSetting.Select("/configuration/MQs/MQ"); if (null == mqSettings || 0 == mqSettings.Length) return session; foreach (XmlSetting mqSetting in mqSettings) { session.Add(CreateInternalSession(mqSetting)); } return session; }
private static object[] GetFactoryParams(XmlSetting paramEntry) { if (null == paramEntry) return null; ArrayList factoryParams = new ArrayList(); foreach (XmlSetting paramNode in paramEntry.Select("param")) { string paramType = paramNode.ReadSetting("@type"); string paramValue = paramNode.ReadSetting("@value"); switch (paramType) { case "string": factoryParams.Add(paramValue); break; case "int": factoryParams.Add(int.Parse(paramValue)); break; } } if (factoryParams.Count > 0) return factoryParams.ToArray(); return null; }