Esempio n. 1
0
 public NmsConnection(Uri uri, Apache.NMS.AcknowledgementMode acknowledgementMode, NmsCredentials credentials, params object[] connectionFactoryConstructorParameters)
 {
     var factory = NMSConnectionFactory.CreateConnectionFactory(uri, connectionFactoryConstructorParameters);
     this.connection = (credentials == null)
         ? factory.CreateConnection()
         : factory.CreateConnection(credentials.Username, credentials.Password);
     this.id = idCounter++;
     this.WireUpEvents();
 }
Esempio n. 2
0
 public NmsConnection(IConnectionFactory connectionFactory, Apache.NMS.AcknowledgementMode acknowledgementMode, NmsCredentials credentials)
 {
     this.connection = (credentials == null)
         ? connectionFactory.CreateConnection()
         : connectionFactory.CreateConnection(credentials.Username, credentials.Password);
     this.acknowledgementMode = acknowledgementMode;
     this.id = idCounter++;
     this.WireUpEvents();
 }
Esempio n. 3
0
        public NmsConnectionPool()
        {
            this.Init();

            var config = (EasyNmsSection)ConfigurationManager.GetSection("easyNms");
            this.settings = new NmsConnectionPoolSettings()
            {
                ConnectionCount = config.ConnectionPool.NumberOfConnections,
                MaximumSessionsPerConnection = config.ConnectionPool.MaxSessionsPerConnection,
                MinimumSessionsPerConnection = config.ConnectionPool.MinSessionsPerConnection,
                AcknowledgementMode = config.ConnectionPool.AcknowledgementMode,
                AutoGrowSessions = config.ConnectionPool.AutoGrowSessions
            };

            Type epManagerType = null;
            try
            {
                epManagerType = Type.GetType(config.ConnectionPool.EndPointManager.Type);
                if (epManagerType.GetInterface("INmsEndPointManager") == null)
                    throw new ConfigurationErrorsException("The type '" + config.ConnectionPool.EndPointManager.Type + "' does not implement INmsEndPointManager.");
            }
            catch (Exception)
            {
                throw new ConfigurationErrorsException("Could not find type '" + config.ConnectionPool.EndPointManager.Type + "'.");
            }

            endpointManager = (INmsEndPointManager)Activator.CreateInstance(epManagerType);
            if (config.ConnectionPool.EndPointManager.Properties != null && config.ConnectionPool.EndPointManager.Properties.Count > 0)
            {
                foreach (var pInfo in epManagerType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
                {
                    foreach (PropertyElement prop in config.ConnectionPool.EndPointManager.Properties)
                    {
                        if (prop.Name == pInfo.Name)
                        {
                            var conv = TypeDescriptor.GetConverter(pInfo.PropertyType);
                            if (conv.CanConvertFrom(typeof(string)))
                            {
                                var value = conv.ConvertFrom(prop.Value);
                                pInfo.SetValue(endpointManager, value, null);
                            }
                        }
                    }
                }
            }

            foreach (EndPointElement ep in config.ConnectionPool.EndPoints)
            {
                NmsCredentials creds = null;
                if (ep.Credentials != null && (ep.Credentials.Username != string.Empty || ep.Credentials.Password != string.Empty))
                    creds = new NmsCredentials(ep.Credentials.Username, ep.Credentials.Password);

                var newep = new NmsEndPoint(ep.Uri, creds);
                endpointManager.AddEndPoint(newep);
            }
        }