Westwind.MessageQueueing.QueueControllerMultiple.Initialize C# (CSharp) 메소드

Initialize() 공개 메소드

Loads configuration settings from configuration file and loads up the Controllers list.
public Initialize ( QueueMessageManagerConfiguration configuration = null, Type managerType = null ) : void
configuration QueueMessageManagerConfiguration
managerType System.Type
리턴 void
        public void Initialize(QueueMessageManagerConfiguration configuration = null, Type managerType = null)
        {            
            base.Initialize(configuration, managerType);

            // ignore controller list if controllers have been 
            // explicitly set
            if (Controllers != null && Controllers.Count > 0)
                return;

            // load up the controllers
            Controllers = new List<QueueController>();

            if (configuration == null)
                configuration = QueueMessageManagerConfiguration.Current;
            if (managerType == null)
                managerType = QueueManagerType ?? typeof(QueueMessageManagerSql);

            if (configuration != null && configuration.Controllers != null)
            {
                // pass configuration to all the child controllers
                foreach (var config in configuration.Controllers)
                {
                    var ctrl = Activator.CreateInstance(GetType()) as QueueController;

                    ctrl.ConnectionString = string.IsNullOrEmpty(config.ConnectionString)
                        ? ConnectionString ?? ""
                        : config.ConnectionString;

                    ctrl.QueueName = config.QueueName;
                    ctrl.ThreadCount = config.ControllerThreads;
                    ctrl.WaitInterval = config.WaitInterval;
                    ctrl.QueueManagerType = managerType;
                    ctrl.OnCreateQueueManager = OnCreateQueueManager;

                    Controllers.Add(ctrl);
                }
            }
        }

Usage Example

        public void MultipleQueueControllerConfigTest()
        {
            var master = new QueueControllerMultiple()
            {
                ConnectionString = "QueueMessageManager"
            };
            master.Initialize();   // read configuration values

            Assert.IsNotNull(master);
            Assert.IsTrue(master.Controllers.Count > 0);

            foreach (var controller in master.Controllers)
            {               
                Console.WriteLine(controller.QueueName + ", " + controller.ThreadCount + ", " + controller.WaitInterval);
            }
        }