示例#1
0
        /// <summary>
        /// Get or add a payload to the context, using the provided payload factory.
        /// </summary>
        /// <param name="payloadFactory">The payload factory, which is only invoked if the payload is not present.</param>
        /// <typeparam name="T">The payload type</typeparam>
        /// <returns></returns>
        public virtual T GetOrAddPayload <T>(PayloadFactory <T> payloadFactory)
            where T : class
        {
            if (this is T context)
            {
                return(context);
            }

            return(PayloadCache.GetOrAddPayload(payloadFactory));
        }
        public TPayload GetOrAddPayload <TPayload>(PayloadFactory <TPayload> payloadFactory)
            where TPayload : class
        {
            var context = this as TPayload;

            if (context != null)
            {
                return(context);
            }

            return(_payloadCache.GetOrAddPayload(payloadFactory));
        }
示例#3
0
        public void BasicTest()
        {
            IPayloadCache p = new PayloadCache();

            p.GetOrAddPayload(() => new Item("bob"));

            Item i;

            Assert.That(p.TryGetPayload(out i), Is.True);

            var p2 = p.CreateScope();

            p.GetOrAddPayload(() => new Item2("bill"));

            Item2 i2;

            Assert.That(p2.TryGetPayload(out i2), Is.False);
            Item i1;

            Assert.That(p2.TryGetPayload(out i1), Is.True);
        }
        public RabbitMqSendContextImpl(IBasicProperties basicProperties, T message, SendSettings sendSettings,
                                       CancellationToken cancellationToken,
                                       string routingKey = "")
        {
            CancellationToken = cancellationToken;

            _payloadCache = new PayloadCache();

            // provide access to the extended settings for RabbitMQ developers
            _payloadCache.GetOrAddPayload <RabbitMqSendContext <T> >(() => this);
            _payloadCache.GetOrAddPayload <RabbitMqSendContext>(() => this);

            Headers         = new RabbitMqSendHeaders(basicProperties);
            BasicProperties = basicProperties;
            Message         = message;
            Exchange        = sendSettings.ExchangeName;
            RoutingKey      = routingKey;

            MessageId = NewId.NextGuid();

            Durable = true;
        }
示例#5
0
        public ServiceBusSendContextImpl(T message, CancellationToken cancellationToken)
        {
            _payloadCache = new PayloadCache();
            _payloadCache.GetOrAddPayload <ServiceBusSendContext <T> >(() => this);

            Headers = new ServiceBusSendHeaders();

            Message            = message;
            _cancellationToken = cancellationToken;

            MessageId = NewId.NextGuid();

            Durable = true;
        }
        TPayload PipeContext.GetOrAddPayload <TPayload>(PayloadFactory <TPayload> payloadFactory)
        {
            TPayload payload;

            if (_payloadCache.TryGetPayload(out payload))
            {
                return(payload);
            }

            if (_connectionContext.TryGetPayload(out payload))
            {
                return(payload);
            }

            return(_payloadCache.GetOrAddPayload(payloadFactory));
        }
示例#7
0
        TPayload TransformContext.GetOrAddPayload <TPayload>(PayloadFactory <TPayload> payloadFactory)
        {
            TPayload payload;

            if (_payloadCache.TryGetPayload(out payload))
            {
                return(payload);
            }

            if (_context.TryGetPayload(out payload))
            {
                return(payload);
            }

            return(_payloadCache.GetOrAddPayload(payloadFactory));
        }
示例#8
0
 public TPayload GetOrAddPayload <TPayload>(PayloadFactory <TPayload> payloadFactory)
     where TPayload : class
 {
     return(_payloadCache.GetOrAddPayload(payloadFactory));
 }