/// <summary> /// Convert a <see cref="ExecutionContext"/> to <see cref="ExecutionContextContract"/>. /// </summary> /// <param name="executionContext"><see cref="ExecutionContext"/> to convert from.</param> /// <returns>Converted <see cref="ExecutionContextContract"/>.</returns> public static ExecutionContextContract ToProtobuf(this ExecutionContext executionContext) { var message = new ExecutionContextContract { MicroserviceId = executionContext.Microservice.Value.ToProtobuf(), TenantId = executionContext.Tenant.Value.ToProtobuf(), CorrelationId = executionContext.CorrelationId.Value.ToProtobuf(), Environment = executionContext.Environment.Value, Version = executionContext.Version.ToProtobuf() }; if (executionContext.SpanId.HasValue) { var span = new byte[8]; executionContext.SpanId.Value.CopyTo(span); message.SpanId = ByteString.CopyFrom(span); } message.Claims.AddRange(executionContext.Claims.ToProtobuf()); return(message); }
protected static ConsumerRequest CreateRequest() { var execution_context = new Dolittle.Execution.Contracts.ExecutionContext { MicroserviceId = Guid.Parse("a2002eca-502f-41ca-bcaa-59149f6d44e6").ToProtobuf(), CorrelationId = Guid.Parse("11f3f1c1-340b-4d08-8a3a-9dae16cb2dbb").ToProtobuf(), TenantId = Guid.Parse("0dfdd63a-570c-4d17-b9c0-db34f1cb5bbc").ToProtobuf(), Environment = "env", Version = Version.NotSet.ToProtobuf(), }; execution_context.Claims.AddRange(Claims.Empty.ToProtobuf()); return(new ConsumerRequest { Event = new EventHorizonEvent { StreamSequenceNumber = 1, Event = new EventHorizonCommittedEvent() { Content = "content", EventLogSequenceNumber = 4, EventSourceId = "some event source", External = true, ExecutionContext = execution_context, ExternalEventLogSequenceNumber = 6, ExternalEventReceived = Timestamp.FromDateTimeOffset(DateTimeOffset.Now), Occurred = Timestamp.FromDateTimeOffset(DateTimeOffset.Now), Public = false, EventType = new Artifact { Generation = 4, Id = Guid.Parse("19ced99f-376e-413c-b368-05edfc2f1067").ToProtobuf() }, EventSourceIdLegacy = Guid.Parse("c84b4055-a084-4eae-a7b3-3124b462c880").ToProtobuf() }, } }); }
/// <summary> /// Tries to create an <see cref="ExecutionContext"/> from the <see cref="ContractsExecutionContext"/> present in a <see cref="CallRequestContext"/>. /// </summary> /// <param name="creator">This execution context creator.</param> /// <param name="requested">The execution context to use - typically from a Client request.</param> /// <returns>A <see cref="Try{TResult}"/> with a new <see cref="ExecutionContext"/> with the requested fields, if successful.</returns> public static Try <ExecutionContext> TryCreateUsing(this ICreateExecutionContexts creator, ContractsExecutionContext requested) => creator.TryCreateUsing(requested.ToExecutionContext());
/// <summary> /// Convert a <see cref="ExecutionContextContract"/> to <see cref="ExecutionContext"/>. /// </summary> /// <param name="executionContext"><see cref="ExecutionContextContract"/> to convert from.</param> /// <returns>Converted <see cref="ExecutionContext"/>.</returns> public static ExecutionContext ToExecutionContext(this ExecutionContextContract executionContext) =>