Ejemplo n.º 1
0
        /// <summary>
        /// Resolves model type descriptor
        /// </summary>
        public TypeDeliveryDescriptor Resolve(Type type, ModelTypeConfigurator defaultConfigurator)
        {
            TypeDeliveryDescriptor descriptor = new TypeDeliveryDescriptor();

            if (defaultConfigurator != null)
            {
                ResolveDefaults(type, descriptor, defaultConfigurator);
            }

            ResolveBase(type, descriptor);
            ResolveDirect(type, descriptor);
            ResolveQueue(type, descriptor);
            ResolveRouter(type, descriptor);

            return(descriptor);
        }
Ejemplo n.º 2
0
        public virtual void Resolve(ModelTypeConfigurator defaultOptions = null)
        {
            if (defaultOptions == null)
            {
                return;
            }

            SendAck    = defaultOptions.AutoAck;
            SendNack   = defaultOptions.AutoNack;
            NackReason = defaultOptions.NackReason;
            Retry      = defaultOptions.Retry;
            DefaultPublishException = defaultOptions.DefaultPublishException;
            PushExceptions          = defaultOptions.PushExceptions;
            DefaultPublishException = defaultOptions.DefaultPublishException;
            PublishExceptions       = defaultOptions.PublishExceptions;

            if (DefaultPushException != null && !typeof(ITransportableException).IsAssignableFrom(DefaultPushException.ModelType))
            {
                throw new InvalidCastException("PushException model type must implement ITransportableException interface");
            }

            foreach (TransportExceptionDescriptor item in PushExceptions)
            {
                if (item != null && !typeof(ITransportableException).IsAssignableFrom(item.ModelType))
                {
                    throw new InvalidCastException("PushException model type must implement ITransportableException interface");
                }
            }

            if (DefaultPublishException != null && !typeof(ITransportableException).IsAssignableFrom(DefaultPublishException.ModelType))
            {
                throw new InvalidCastException("PublishException model type must implement ITransportableException interface");
            }

            foreach (TransportExceptionDescriptor item in PublishExceptions)
            {
                if (item != null && !typeof(ITransportableException).IsAssignableFrom(item.ModelType))
                {
                    throw new InvalidCastException("PublishException model type must implement ITransportableException interface");
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Resolves default values from model type configurator
        /// </summary>
        private void ResolveDefaults(Type type, TypeDeliveryDescriptor descriptor, ModelTypeConfigurator defaultConfigurator)
        {
            if (defaultConfigurator.QueueNameFactory != null)
            {
                descriptor.QueueName    = defaultConfigurator.QueueNameFactory(type);
                descriptor.HasQueueName = true;
            }

            if (defaultConfigurator.QueueStatus.HasValue)
            {
                descriptor.QueueStatus = defaultConfigurator.QueueStatus.Value;
            }

            if (!string.IsNullOrEmpty(defaultConfigurator.Topic))
            {
                descriptor.Topic = defaultConfigurator.Topic;
            }

            if (defaultConfigurator.PutBackDelay.HasValue)
            {
                descriptor.PutBackDelay = defaultConfigurator.PutBackDelay.Value;
            }

            if (defaultConfigurator.DelayBetweenMessages.HasValue)
            {
                descriptor.DelayBetweenMessages = defaultConfigurator.DelayBetweenMessages.Value;
            }

            if (defaultConfigurator.AckDecision.HasValue)
            {
                descriptor.Acknowledge = defaultConfigurator.AckDecision.Value;
            }

            foreach (Func <KeyValuePair <string, string> > func in defaultConfigurator.HeaderFactories)
            {
                descriptor.Headers.Add(func());
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Sets default configuration for all model and consumer types.
 /// The configuration options can be overwritten with attributes.
 /// </summary>
 public HorseConnectorBuilder ConfigureModels(Action <ModelTypeConfigurator> cfg)
 {
     _configurator = new ModelTypeConfigurator();
     cfg(_configurator);
     return(this);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Resolves model type descriptor
 /// </summary>
 public TypeDeliveryDescriptor Resolve <TModel>(ModelTypeConfigurator defaultConfigurator)
 {
     return(Resolve(typeof(TModel), defaultConfigurator));
 }
Ejemplo n.º 6
0
 public override void Resolve(ModelTypeConfigurator defaultOptions = null)
 {
     base.Resolve(defaultOptions);
     ResolveAttributes(_handlerType, typeof(TRequest));
 }
Ejemplo n.º 7
0
 public override void Resolve(ModelTypeConfigurator defaultOptions = null)
 {
     base.Resolve(defaultOptions);
     ResolveAttributes(_consumerType, typeof(TModel));
 }