コード例 #1
0
        RoutingSlip CreateRoutingSlip(ConsumeContext <ProcessRegistration> context)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            if (!string.IsNullOrWhiteSpace(context.Message.ParticipantLicenseNumber))
            {
                builder.AddActivity("LicenseVerificiation", context.GetDestinationAddress("execute-licenseverification"), new
                {
                    LicenseNumber = context.Message.ParticipantLicenseNumber,
                    EventType     = "Road",
                    Category      = context.Message.ParticipantCategory
                });

                builder.AddSubscription(context.SourceAddress, RoutingSlipEvents.ActivityFaulted, RoutingSlipEventContents.None, "LicenseVerificiation",
                                        x => x.Send <RegistrationLicenseVerificationFailed>(new
                {
                    context.Message.SubmissionId
                }));
            }

            builder.AddActivity("EventRegistration", context.GetDestinationAddress("execute-eventregistration"), new
            {
                context.Message.ParticipantEmailAddress,
                context.Message.ParticipantLicenseNumber,
                context.Message.ParticipantCategory,
                context.Message.EventId,
                context.Message.RaceId
            });

            var paymentInfo = _paymentInfoService.GetPaymentInfo(context.Message.ParticipantEmailAddress, context.Message.CardNumber);

            builder.AddActivity("ProcessPayment", context.GetDestinationAddress("execute-processpayment"), paymentInfo);

            builder.AddSubscription(context.SourceAddress, RoutingSlipEvents.ActivityFaulted, RoutingSlipEventContents.None, "ProcessPayment",
                                    x => x.Send <RegistrationPaymentFailed>(new
            {
                context.Message.SubmissionId
            }));


            builder.AddSubscription(context.SourceAddress, RoutingSlipEvents.Completed, x => x.Send <RegistrationCompleted>(new
            {
                context.Message.SubmissionId
            }));


            return(builder.Build());
        }
コード例 #2
0
        public async Task Consume(ConsumeContext <ProcessBatchJob> context)
        {
            using (_log.BeginScope("ProcessBatchJob {BatchJobId}, {OrderId}", context.Message.BatchJobId, context.Message.OrderId))
            {
                var builder = new RoutingSlipBuilder(NewId.NextGuid());


                switch (context.Message.Action)
                {
                case BatchAction.CancelOrders:
                    builder.AddActivity(
                        "CancelOrder",
                        context.GetDestinationAddress("cancel-order_execute"),
                        new
                    {
                        context.Message.OrderId,
                        Reason = "Product discontinued"
                    });

                    await builder.AddSubscription(
                        context.SourceAddress,
                        RoutingSlipEvents.ActivityFaulted,
                        RoutingSlipEventContents.None,
                        "CancelOrder",
                        x => x.Send <BatchJobFailed>(new
                    {
                        context.Message.BatchJobId,
                        context.Message.BatchId,
                        context.Message.OrderId
                    }));

                    break;

                case BatchAction.SuspendOrders:
                    builder.AddActivity(
                        "SuspendOrder",
                        context.GetDestinationAddress("suspend-order_execute"),
                        new
                    {
                        context.Message.OrderId
                    });

                    await builder.AddSubscription(
                        context.SourceAddress,
                        RoutingSlipEvents.ActivityFaulted,
                        RoutingSlipEventContents.None,
                        "SuspendOrder",
                        x => x.Send <BatchJobFailed>(new
                    {
                        context.Message.BatchJobId,
                        context.Message.BatchId,
                        context.Message.OrderId
                    }));

                    break;

                default:
                    break;
                }

                await builder.AddSubscription(
                    context.SourceAddress,
                    RoutingSlipEvents.Completed,
                    x => x.Send <BatchJobCompleted>(new
                {
                    context.Message.BatchJobId,
                    context.Message.BatchId
                }));

                await context.Execute(builder.Build());
            }
        }