Beispiel #1
0
        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);
        }
Beispiel #2
0
        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)));
            }
        }
Beispiel #3
0
 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;
     }
 }
Beispiel #4
0
        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));
            }
        }