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; } }
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; } }
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; } }
public static void SetPartitionKey(this SendContext context, string partitionKey) { ServiceBusSendContext sendContext; if (context.TryGetPayload(out sendContext)) { sendContext.PartitionKey = partitionKey; } }
public static void SetReplyToSessionId(this SendContext context, string sessionId) { ServiceBusSendContext sendContext; if (context.TryGetPayload(out sendContext)) { sendContext.ReplyToSessionId = sessionId; } }
/// <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; }
/// <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; }
/// <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; }
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)); }
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; } }