コード例 #1
0
ファイル: NmsConnectionPool.cs プロジェクト: cylwit/EasyNMS
        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);
            }
        }
コード例 #2
0
ファイル: NmsConnectionPool.cs プロジェクト: cylwit/EasyNMS
        public NmsConnectionPool(IConnectionFactory connectionFactory, NmsConnectionPoolSettings settings)
            : this()
        {
            this.Init();

            this.connectionFactory = connectionFactory;
            this.settings = settings;

            this.endpointManager = new RoundRobinNmsEndPointManager();
            foreach (var ep in settings.EndPoints)
                this.endpointManager.AddEndPoint(ep);
        }