示例#1
0
        bool TransformContext.TryGetPayload <TPayload>(out TPayload context)
        {
            if (_payloadCache.TryGetPayload(out context))
            {
                return(true);
            }

            return(_context.TryGetPayload(out context));
        }
        ISendScopeContext <T> ISendScopeProvider.GetScope <T>(SendContext <T> context)
            where T : class
        {
            if (context.TryGetPayload <ILifetimeScope>(out _))
            {
                return(new ExistingSendScopeContext <T>(context));
            }

            var parentLifetimeScope = _scopeProvider.GetLifetimeScope(context);

            var lifetimeScope = parentLifetimeScope.BeginLifetimeScope(_name, builder =>
            {
                builder.ConfigureScope(context);
                _configureScope?.Invoke(builder, context);
            });

            try
            {
                SendContext <T> sendContext = lifetimeScope.GetSendScope(context);

                return(new CreatedSendScopeContext <ILifetimeScope, T>(lifetimeScope, sendContext));
            }
            catch
            {
                lifetimeScope.Dispose();

                throw;
            }
        }
示例#3
0
        public ISendScopeContext <T> GetScope <T>(SendContext <T> context)
            where T : class
        {
            if (context.TryGetPayload <IServiceScope>(out _))
            {
                return(new ExistingSendScopeContext <T>(context));
            }

            if (!context.TryGetPayload(out IServiceProvider serviceProvider))
            {
                serviceProvider = _serviceProvider;
            }

            var serviceScope = serviceProvider.CreateScope();

            try
            {
                var sendContext = new SendContextScope <T>(context, serviceScope, serviceScope.ServiceProvider);

                return(new CreatedSendScopeContext <IServiceScope, T>(serviceScope, sendContext));
            }
            catch
            {
                serviceScope.Dispose();

                throw;
            }
        }
示例#4
0
        public async Task Should_contains_scope_on_send()
        {
            await InputQueueSendEndpoint.Send(new SimpleMessageClass("test"));

            SendContext sent = await _taskCompletionSource.Task;

            Assert.IsTrue(sent.TryGetPayload <TScope>(out _));
        }
        /// <summary>
        /// Set the time at which the message should be delivered to the queue
        /// </summary>
        /// <param name="context"></param>
        /// <param name="delay">The time to wait before the message shuould be enqueued</param>
        public static void SetScheduledEnqueueTime(this SendContext context, TimeSpan delay)
        {
            ServiceBusSendContext sendContext;

            if (context.TryGetPayload(out sendContext))
            {
                sendContext.ScheduledEnqueueTimeUtc = DateTime.UtcNow + delay;
            }
        }
示例#6
0
        public static void SetPartitionKey(this SendContext context, string partitionKey)
        {
            ServiceBusSendContext sendContext;

            if (context.TryGetPayload(out sendContext))
            {
                sendContext.PartitionKey = partitionKey;
            }
        }
示例#7
0
        public static void SetReplyToSessionId(this SendContext context, string sessionId)
        {
            ServiceBusSendContext sendContext;

            if (context.TryGetPayload(out sendContext))
            {
                sendContext.ReplyToSessionId = sessionId;
            }
        }
示例#8
0
        /// <summary>
        /// Sets the routing key for this message
        /// </summary>
        /// <param name="context"></param>
        /// <param name="routingKey">The routing key for this message</param>
        public static void SetRoutingKey(this SendContext context, string routingKey)
        {
            RabbitMqSendContext sendContext;

            if (!context.TryGetPayload(out sendContext))
            {
                throw new ArgumentException("The RabbitMqSendContext was not available");
            }

            sendContext.RoutingKey = routingKey;
        }
示例#9
0
        /// <summary>
        /// Sets whether the send should wait for the ack from the broker, or if it should
        /// return immediately after the message is sent by the client.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="awaitAck"></param>
        public static void SetAwaitAck(this SendContext context, bool awaitAck)
        {
            RabbitMqSendContext sendContext;

            if (!context.TryGetPayload(out sendContext))
            {
                throw new ArgumentException("The RabbitMqSendContext was not available");
            }

            sendContext.AwaitAck = awaitAck;
        }
示例#10
0
        /// <summary>
        /// Sets the priority of a message sent to the broker
        /// </summary>
        /// <param name="context"></param>
        /// <param name="priority"></param>
        public static void SetPriority(this SendContext context, byte priority)
        {
            RabbitMqSendContext sendContext;

            if (!context.TryGetPayload(out sendContext))
            {
                throw new ArgumentException("The RabbitMqSendContext was not available");
            }

            sendContext.BasicProperties.Priority = priority;
        }
示例#11
0
        public Task Send(SendContext <T> context, IPipe <SendContext <T> > next)
        {
            if (context.TryGetPayload <ApplicationInsightsPayload>(out _))
            {
                return(next.Send(context));
            }

            context.GetOrAddPayload(() => new ApplicationInsightsPayload());

            return(SendWithTelemetry(context, next));
        }
        /// <summary>
        /// Set the time at which the message should be delivered to the queue
        /// </summary>
        /// <param name="context"></param>
        /// <param name="scheduledTime">The scheduled time for the message</param>
        public static void SetScheduledEnqueueTime(this SendContext context, DateTime scheduledTime)
        {
            ServiceBusSendContext sendContext;

            if (context.TryGetPayload(out sendContext))
            {
                if (scheduledTime.Kind == DateTimeKind.Local)
                {
                    scheduledTime = scheduledTime.ToUniversalTime();
                }

                sendContext.ScheduledEnqueueTimeUtc = scheduledTime;
            }
        }
        Activity StartIfEnabled(DiagnosticSource source, string name, object args, SendContext context)
        {
            if (!source.IsEnabled(name) || context.TryGetPayload <Activity>(out _))
            {
                return(null);
            }

            var activity = new Activity(name)
                           .AddTag(DiagnosticHeaders.MessageId, context.MessageId.ToString())
                           .AddTag(DiagnosticHeaders.InitiatorId, context.InitiatorId.ToString())
                           .AddTag(DiagnosticHeaders.SourceAddress, context.SourceAddress.ToString())
                           .AddTag(DiagnosticHeaders.DestinationAddress, context.DestinationAddress.ToString())
                           .AddBaggage(DiagnosticHeaders.CorrelationId, context.CorrelationId.ToString())
                           .AddBaggage(DiagnosticHeaders.CorrelationConversationId, context.ConversationId.ToString());

            source.StartActivity(activity, args ?? new { });

            Inject(context, activity);

            return(context.AddOrUpdatePayload(() => activity, a => activity));
        }
示例#14
0
        public ISendScopeContext <T> GetScope <T>(SendContext <T> context)
            where T : class
        {
            if (context.TryGetPayload <IKernel>(out _))
            {
                return(new ExistingSendScopeContext <T>(context));
            }

            var scope = _kernel.CreateNewMessageScope(context);

            try
            {
                var sendContext = new SendContextScope <T>(context, _kernel);

                return(new CreatedSendScopeContext <IDisposable, T>(scope, sendContext));
            }
            catch
            {
                scope?.Dispose();
                throw;
            }
        }
        public ISendScopeContext <T> GetScope <T>(SendContext <T> context)
            where T : class
        {
            if (context.TryGetPayload <IContainer>(out _))
            {
                return(new ExistingSendScopeContext <T>(context));
            }

            var nestedContainer = _container?.CreateNestedContainer(context) ?? _context?.CreateNestedContainer(context);

            try
            {
                var sendContext = new SendContextScope <T>(context, nestedContainer);

                return(new CreatedSendScopeContext <IContainer, T>(nestedContainer, sendContext));
            }
            catch
            {
                nestedContainer.Dispose();
                throw;
            }
        }
        public ISendScopeContext <T> GetScope <T>(SendContext <T> context)
            where T : class
        {
            if (context.TryGetPayload <Scope>(out _))
            {
                return(new ExistingSendScopeContext <T>(context));
            }

            var scope = AsyncScopedLifestyle.BeginScope(_container);

            try
            {
                var sendContext = new SendContextScope <T>(context, scope, scope.Container);

                return(new CreatedSendScopeContext <Scope, T>(scope, sendContext));
            }
            catch
            {
                scope.Dispose();

                throw;
            }
        }