public static MessageHandlersOrderConfiguration FromConfiguration()
        {
            var section = ConfigurationManager.GetSection("MessageOrderConfigurationSection") as MessageOrderConfigurationSection;
            if (section == null)
                return new MessageHandlersOrderConfiguration();

            var conf = new MessageHandlersOrderConfiguration();

            var orderList = new List<Order>();

            foreach (MessageOrderElement orderElem in section.Orders)
            {
                var order = new Order
                                {
                                    MessageType = Type.GetType(orderElem.MessageType)
                                };

                orderList.Add(order);

                order.HandlerOrders
                    = orderElem
                        .Handlers
                        .OfType<MessageHandleElement>()
                        .Select(elem => new MessageHandlerOrder
                                            {
                                                HandlerType = Type.GetType(elem.TypeName),
                                                SequenceNo = elem.Order
                                            })
                        .ToList();

            }

            conf._orders.AddRange(orderList);
            return conf;
        }
        public Order GetOrderFor(Type messageType)
        {
            if(_configuration == null)
            {
                lock (_confLock)
                {
                    if (_configuration == null)
                    {
                        _configuration = MessageHandlersOrderConfiguration.FromConfiguration();
                    }
                }
            }

            Order orderFromConfiguration = null;
            Order orderFromCodeConfiguration = null;

            if(_configuration != null)
                orderFromConfiguration = _configuration.Order.SingleOrDefault(o => o.MessageType == messageType);
            if(_codeConfiguration != null)
                orderFromCodeConfiguration = _codeConfiguration.Order.SingleOrDefault(o => o.MessageType == messageType);

            Order result = null;

            if(orderFromCodeConfiguration != null)
            {
                result = orderFromCodeConfiguration;
            }

            if(orderFromConfiguration != null)
            {
                result = orderFromConfiguration;
            }

            return result;
        }
        public static MessageHandlersOrderConfiguration FromCode(params Order[] orders)
        {
            var conf = new MessageHandlersOrderConfiguration();
            if (orders != null && orders.Length > 0)
                conf._orders.AddRange(orders);

            return conf;
        }
示例#4
0
        public Rabbit SetMessageHandlerOrder(MessageHandlersOrderConfiguration configuration)
        {
            if (Log.IsInfoEnabled)
                Log.Info("Setting MessageHandlers' order from code...");

            var messageHandlerOrderProvider = ComponentLocator.Current.Get<IMessageHandlerOrderProvider>();
            if(messageHandlerOrderProvider != null)
            {
                messageHandlerOrderProvider.LoadConfiguration(configuration);
            }

            if (Log.IsInfoEnabled)
                Log.Info("MessageHandlers' order set.");

            return this;
        }
 public void LoadConfiguration(MessageHandlersOrderConfiguration configuration)
 {
     _codeConfiguration = configuration;
 }