public void AddEndPoint(NmsEndPoint endPoint)
 {
     lock (this)
     {
         this.allEndPoints.Add(endPoint);
         this.validEndPoints.Add(endPoint);
     }
 }
 public void InvalidateEndPoint(NmsEndPoint endPoint)
 {
     lock (this)
     {
         if (this.validEndPoints.Contains(endPoint))
         {
             this.validEndPoints.Remove(endPoint);
             this.invalidEndPoints.Add(endPoint);
         }
     }
 }
Exemple #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);
            }
        }