Esempio n. 1
0
        public async Task <IActionResult> Get(string request)
        {
            if (string.IsNullOrEmpty(request))
            {
                return(BadRequest());
            }

            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            //1
            //builder.AddActivity("DownloadImage", new Uri("rabbitmq://localhost/execute_downloadimage"), new
            //{
            //    ImageUri = new Uri("http://images.google.com/someImage.jpg")
            //});
            //2
            //builder.AddActivity("DownloadImage", new Uri("rabbitmq://localhost/execute_downloadimage"));
            //builder.AddVariable("ImageUri", "http://images.google.com/someImage.jpg");
            //3: si el ProcessImage no depende del fin de DownloadImage
            builder.AddActivity("DownloadImage", new Uri("rabbitmq://localhost/execute_downloadimage"));
            builder.AddActivity("ProcessImage", new Uri("rabbitmq://localhost/execute_processimage"));
            builder.AddVariable("ImageUri", "http://images.google.com/someImage.jpg");

            builder.AddActivity("FilterImage", new Uri("rabbitmq://localhost/execute_filterimage"));
            builder.AddVariable("WorkPath", "\\dfs\\work");
            //Events
            //1
            //builder.AddSubscription(new Uri("rabbitmq://localhost/log-events"), RoutingSlipEvents.All);
            //2 modo flags
            builder.AddSubscription(new Uri("rabbitmq://localhost/log-events"),
                                    RoutingSlipEvents.Completed | RoutingSlipEvents.Faulted);
            //builder.AddSubscription(new Uri("rabbitmq://localhost/log-events"),
            //    RoutingSlipEvents.Completed, RoutingSlipEventContents.None);
            //3
            builder.AddSubscription(new Uri("rabbitmq://localhost/log-events"), RoutingSlipEvents.Completed);
            builder.AddSubscription(new Uri("rabbitmq://localhost/log-events"), RoutingSlipEvents.Faulted);
            builder.AddSubscription(new Uri("rabbitmq://localhost/log-events"), RoutingSlipEvents.CompensationFailed);

            builder.AddSubscription(new Uri("rabbitmq://localhost/log-events"), RoutingSlipEvents.ActivityCompleted);
            builder.AddSubscription(new Uri("rabbitmq://localhost/log-events"), RoutingSlipEvents.ActivityFaulted);
            builder.AddSubscription(new Uri("rabbitmq://localhost/log-events"), RoutingSlipEvents.ActivityCompensated);
            builder.AddSubscription(new Uri("rabbitmq://localhost/log-events"), RoutingSlipEvents.ActivityCompensationFailed);
            // 4 custom public interface OrderProcessingCompleted
            //builder.AddSubscription(new Uri("rabbitmq://localhost/order-events"),
            //    RoutingSlipEvents.Completed,
            //    x => x.Send<OrderProcessingCompleted>(new
            //    {
            //        OrderId = "BFG-9000",
            //        OrderApproval = "ComeGetSome"
            //    }));
            var routingSlip = builder.Build();

            await _bus.Execute(routingSlip);

            return(Ok(new { routingSlip.TrackingNumber }));
        }
Esempio n. 2
0
        private static RoutingSlip BuildRoutingSlip(ConsumeContext <ProcessBurgerOrder> context, Guid trackingId)
        {
            var builder = new RoutingSlipBuilder(trackingId);

            builder.AddVariable("OrderId", context.Message.OrderId);
            builder.AddVariable("CorrelationId", context.CorrelationId);

            // minor: abstract out this
            var activityName   = typeof(ProcessBurgerOrderActivity).Name;
            var queueName      = $"{activityName.Replace("Activity", string.Empty)}_execute";
            var executeAddress = new Uri($"queue:{queueName}");

            builder.AddActivity(activityName, executeAddress);

            // Completed
            builder
            .AddSubscription(
                context.SourceAddress,
                RoutingSlipEvents.Completed,
                x => x.Send <BurgerOrderProcessed>(
                    new
            {
                context.Message.CorrelationId,
                context.Message.OrderId,
                context.Message.OrderDate
            })
                );

            // Faulted
            builder
            .AddSubscription(
                context.SourceAddress,
                RoutingSlipEvents.ActivityFaulted,
                x => x.Send <BurgerOrderFaulted>(
                    new
            {
                context.Message.CorrelationId,
                context.Message.OrderId,
                context.Message.OrderDate
            })
                );

            return(builder.Build());
        }
        public async Task Execute(ConsumeContext <IOffice365VerifyDomainCommand> context)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());
            var command = context.Message;

            builder.AddActivity(Office365ServiceConstants.ActivityVerifyCustomerDomain,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IVerifyCustomerDomainActivity)),
                                _activityOffice365CustomerArgumentsMapper.MapVerifyCustomerDomain(command));

            builder.AddActivity(Office365ServiceConstants.ActivityCreateTempAdminUser,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreateTempPartnerPlatformAdminUserActivity)),
                                _activityOffice365CustomerArgumentsMapper.MapCreateTempAdminUser(command));

            builder.AddActivity(Office365ServiceConstants.ActivityAssignUserRoles,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IAssignUserRolesActivity)),
                                _activityOffice365CustomerArgumentsMapper.MapAssignUserRoles(command));

            builder.AddActivity(Office365ServiceConstants.ActivityFederateCustomerDomain,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IFederateCustomerDomainActivity)),
                                _activityOffice365CustomerArgumentsMapper.MapFederateCustomerDomain(command));

            builder.AddActivity(Office365ServiceConstants.ActivityVerifyCustomerDomainDatabaseStatus,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IVerifyCustomerDomainDatabaseStatusActivity)),
                                _activityOffice365CustomerArgumentsMapper.MapVerifyCustomerDomainDatabaseStatus(command));

            builder.AddActivity(Office365ServiceConstants.ActivityFederateCustomerDomainDatabaseStatus,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IFederateCustomerDomainDatabaseStatusActivity)),
                                _activityOffice365CustomerArgumentsMapper.MapFederateCustomerDomainDatabaseStatus(command));

            builder.AddActivity(Office365ServiceConstants.ActivityHardDeletePartnerPlatformUser,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IHardDeletePartnerPlatformUserActivity)),
                                _activityOffice365CustomerArgumentsMapper.MapDeleteTempAdminUser(command));

            builder.AddVariable("domainName", context.Message.DomainName);
            builder.AddVariable("workflowActivityType", WorkflowActivityType.VerifyAndFederateOffice365Domain.ToString());

            builder.AddSubscription(Office365ServiceConstants.QueueOffice365RoutingSlipEventUri,
                                    RoutingSlipEvents.Faulted |
                                    RoutingSlipEvents.Completed |
                                    RoutingSlipEvents.ActivityCompleted |
                                    RoutingSlipEvents.ActivityFaulted |
                                    RoutingSlipEvents.ActivityCompensated |
                                    RoutingSlipEvents.ActivityCompensationFailed);

            var routingSlip = builder.Build();

            await context.Send <IRoutingSlipStarted>(Office365ServiceConstants.QueueOffice365RoutingSlipStartedUri, new
            {
                builder.TrackingNumber,
                CreateTimestamp      = DateTime.UtcNow,
                Arguments            = context.Message,
                WorkflowActivityType = WorkflowActivityType.VerifyAndFederateOffice365Domain.ToString()
            });

            await context.Execute(routingSlip);
        }
Esempio n. 4
0
        public async Task <Guid> StartAsync()
        {
            var queueUri = new Uri(_busControl.Address, Assembly.GetEntryAssembly().GenerateRoutingSlipFailureQueueName());

            _routingSlip.AddSubscription(queueUri,
                                         RoutingSlipEvents.Faulted | RoutingSlipEvents.ActivityCompensationFailed |
                                         RoutingSlipEvents.ActivityFaulted | RoutingSlipEvents.CompensationFailed);

            await _busControl.Execute(_routingSlip.Build());

            return(_routingSlip.TrackingNumber);
        }
Esempio n. 5
0
        public async Task Should_immediately_complete_an_empty_list()
        {
            Task <ConsumeContext <RoutingSlipCompleted> > completed = SubscribeHandler <RoutingSlipCompleted>();

            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            builder.AddSubscription(Bus.Address, RoutingSlipEvents.All);

            await Bus.Execute(builder.Build());

            await completed;
        }
Esempio n. 6
0
        public async Task Consume(ConsumeContext <BookingModel> context)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            builder.AddActivity("BookFlight", new Uri("queue:book-flight_execute"),
                                new BookFlightArgument
            {
                Message = context.Message.Flight
            });

            builder.AddActivity("BookHotel", new Uri("queue:book-hotel_execute"),
                                new BookHotelArgument
            {
                Message = context.Message.Hotel
            });

            //Retry activity has applied in its file
            builder.AddActivity("BookCar", new Uri("queue:book-car_execute"),
                                new BookCarArgument
            {
                Message = context.Message.Car
            });

            await builder.AddSubscription(context.SourceAddress,
                                          RoutingSlipEvents.Faulted | RoutingSlipEvents.Supplemental,
                                          RoutingSlipEventContents.None, x => x.Send(new BookingFaulted {
                BookingId = context.Message.BookingId
            }));

            await builder.AddSubscription(context.SourceAddress,
                                          RoutingSlipEvents.Completed | RoutingSlipEvents.Supplemental,
                                          RoutingSlipEventContents.None, x => x.Send(new BookingFinalized {
                BookingId = context.Message.BookingId
            }));


            var routingSlip = builder.Build();

            await context.Execute(routingSlip);
        }
Esempio n. 7
0
        public async Task Consume(ConsumeContext <FullfillOrder> context)
        {
            if (context.Message.CustomerNumber.StartsWith("INVALID"))
            {
                throw new InvalidOperationException("We tried, but customer is invalid");
            }

            if (context.Message.CustomerNumber.StartsWith("MAYBE"))
            {
                throw new ApplicationException("We randomly exploded, so bad, much tear.");
            }

            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            builder.AddActivity("AllocateInventory",
                                new Uri("queue:allocate-inventory_execute"), new
            {
                ItemNumber = "ITEM123",
                Quantity   = 10.0m
            });

            builder.AddActivity("PaymentActivity",
                                new Uri("queue:payment_execute"), new
            {
                CardNumber = context.Message.PaymentCardNumber ?? "5999-1234-1234-1234",
                Amount     = 99.95m
            });

            await builder.AddSubscription(context.SourceAddress,
                                          RoutingSlipEvents.Faulted | RoutingSlipEvents.Supplemental,
                                          RoutingSlipEventContents.None, x => x.Send <OrderFulFillmentFaulted>(new { context.Message.OrderId }));

            await builder.AddSubscription(context.SourceAddress,
                                          RoutingSlipEvents.Completed | RoutingSlipEvents.Supplemental,
                                          RoutingSlipEventContents.None, x => x.Send <OrderFulFillmentCompleted>(new { context.Message.OrderId }));

            builder.AddVariable("orderId", context.Message.OrderId);
            var routingSlip = builder.Build();
            await context.Execute(routingSlip);
        }
        public async Task Execute(ConsumeContext <IOffice365CreateCustommerCommand> context)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());
            var createOffice365CustommerCommand = context.Message;

            builder.AddActivity(Office365ServiceConstants.ActivityCreateOffice365PartnerPlatformCustomer,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreatePartnerPlatformCustomerActivity)),
                                _activityOffice365CustomerArgumentsMapper.MapCreatePartnerPlatformCustomerArguments(createOffice365CustommerCommand));

            builder.AddActivity(Office365ServiceConstants.ActivityCreateOffice365DatabaseCustomer,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreateDatabaseCustomerActivity)),
                                _activityOffice365CustomerArgumentsMapper.MapCreateDatabaseCustomerArguments(createOffice365CustommerCommand));

            builder.AddActivity(Office365ServiceConstants.ActivityAddOffice365CustomerDomainToPartnerPortal,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IAddCustomerDomainPartnerPortalActivity)),
                                _activityOffice365CustomerArgumentsMapper.MapAddCustomerDomainPartnerPortalArguments(createOffice365CustommerCommand));

            builder.AddActivity(Office365ServiceConstants.ActivityAddOffice365CustomerDomainToDatabase,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IAddCustomerDomainToDatabaseActivity)),
                                _activityOffice365CustomerArgumentsMapper.MapAddCustomerDomainToDatabaseArguments(createOffice365CustommerCommand));

            builder.AddActivity(Office365ServiceConstants.ActivityGetOffice365CustomerTxtRecords,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IGetCustomerDomainTxtRecordsActivity)),
                                _activityOffice365CustomerArgumentsMapper.MapGetCustomerTxtRecords(createOffice365CustommerCommand));

            builder.AddActivity(Office365ServiceConstants.ActivitySendOffice365CustomerTxtRecords,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(ISendCustomerDomainTxtRecordsActivity)),
                                _activityOffice365CustomerArgumentsMapper.MapSendCustomerTxtRecords(createOffice365CustommerCommand));

            builder.AddVariable("companyId", context.Message.CompanyId);
            builder.AddVariable("workflowActivityType", WorkflowActivityType.Office365AddAdditionalDomain.ToString());

            builder.AddSubscription(Office365ServiceConstants.QueueOffice365RoutingSlipEventUri,
                                    RoutingSlipEvents.Completed |
                                    RoutingSlipEvents.Faulted |
                                    RoutingSlipEvents.ActivityCompleted |
                                    RoutingSlipEvents.ActivityFaulted |
                                    RoutingSlipEvents.ActivityCompensated |
                                    RoutingSlipEvents.ActivityCompensationFailed);

            var routingSlip = builder.Build();

            await context.Send <IRoutingSlipStarted>(Office365ServiceConstants.QueueOffice365RoutingSlipStartedUri, new
            {
                builder.TrackingNumber,
                CreateTimestamp      = DateTime.UtcNow,
                Arguments            = context.Message,
                WorkflowActivityType = WorkflowActivityType.CreateOffice365Customer.ToString()
            });

            await context.Execute(routingSlip);
        }
Esempio n. 9
0
        public async Task Consume(ConsumeContext <IFulfillVacationBooking> context)
        {
            this._logger.LogInformation($"{nameof(FulfillVacationBookingConsumer)} building & executing Routing Slip" +
                                        $"\r\nPayload: {context.Message}");

            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            builder.AddActivity("BookHotel",
                                new Uri("queue:book-hotel_execute"), context.Message.FlightBookingInformation);

            builder.AddActivity("BookFlight",
                                new Uri("queue:book-flight_execute"), context.Message.HotelBookingInformation);

            if (context.Message.VacationExtras.CarRental != null)
            {
                builder.AddActivity("RentCar",
                                    new Uri("queue:rent-car_execute"), context.Message.VacationExtras.CarRental);
            }

            await builder.AddSubscription(context.SourceAddress,
                                          RoutingSlipEvents.Completed | RoutingSlipEvents.Supplemental, RoutingSlipEventContents.None,
                                          x => x.Send <IVacationBookingFulfillmentCompleted>(new
            {
                context.Message.VacationId,
                Timestamp = DateTime.UtcNow
            }));

            await builder.AddSubscription(context.SourceAddress,
                                          RoutingSlipEvents.Faulted | RoutingSlipEvents.Supplemental, RoutingSlipEventContents.None,
                                          x => x.Send <IVacationBookingFulfillmentFailed>(new
            {
                context.Message.VacationId,
                Reason = "Some reason"
            }));

            var routingSlip = builder.Build();

            await context.Execute(routingSlip);
        }
        public Task Consume(ConsumeContext <OrderSubmitted> context)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            builder.AddActivity(this.activitiesConfig.ReserveProduct.ActivityName,
                                this.activitiesConfig.ReserveProduct.ExecuteEndpointUri,
                                new
            {
                context.Message.Quantity,
                context.Message.ProductName
            });

            if (!string.IsNullOrWhiteSpace(context.Message.CouponCode))
            {
                builder.AddActivity(this.activitiesConfig.ApplyCoupon.ActivityName,
                                    this.activitiesConfig.ApplyCoupon.ExecuteEndpointUri,
                                    new { context.Message.CouponCode, context.Message.Quantity });
            }

            builder.AddActivity(this.activitiesConfig.ProcessPayment.ActivityName,
                                this.activitiesConfig.ProcessPayment.ExecuteEndpointUri);

            builder.AddVariable(nameof(OrderSubmitted.OrderId), context.Message.OrderId);

            builder.AddSubscription(new Uri("rabbitmq://localhost/orders"),
                                    RoutingSlipEvents.Completed,
                                    sendEndpoint => sendEndpoint.Send(new OrderProcessingCompleted
            {
                OrderId = context.Message.OrderId
            }));

            builder.AddSubscription(new Uri("rabbitmq://localhost/orders"),
                                    RoutingSlipEvents.Faulted);

            RoutingSlip routingSlip = builder.Build();

            return(context.Execute(routingSlip));
        }
Esempio n. 11
0
        public async Task Execute(ConsumeContext <IOffice365TransitionCommand> context)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());
            var command = context.Message;

            builder.AddActivity(Office365ServiceConstants.ActivityCreateOffice365DatabaseCustomer,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreateDatabaseCustomerActivity)), _mapper.MapCreateDatabaseCustomerArguments(command));

            builder.AddActivity(Office365ServiceConstants.ActivityAddMultiDomainToDatabase,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IAddMultiDomainToDatabaseActivity)), _mapper.MapAddMultiDomainToDatabaseArguments(command));

            builder.AddActivity(Office365ServiceConstants.ActivityMultiPartnerPlatformCustomerSubscription,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IMultiPartnerPlatformCustomerSubscriptionActivity)), _mapper.MapMultiPartnerPlatformCustomerSubscriptionArguments(command));

            builder.AddActivity(Office365ServiceConstants.ActivityMultiDatabaseCustomerSubscription,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IMultiDatabaseCustomerSubscriptionActivity)), _mapper.MapMultiDatabaseCustomerSubscriptionArguments(command));

            builder.AddActivity(Office365ServiceConstants.ActivityDatabaseProvisionedStatusProvisioned,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IDatabaseProvisionedStatusProvisionedActivity)), _mapper.MapDatabaseProvisionedStatusProvisionedArguments(command));

            builder.AddActivity(Office365ServiceConstants.ActivityTransitionDispatchCreatingUsers,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(ITransitionDispatchCreatingUsersActivity)), _mapper.MapTransitionDispatchCreatingUserArguments(command));

            builder.AddSubscription(Office365ServiceConstants.QueueOffice365RoutingSlipEventUri,
                                    RoutingSlipEvents.Completed |
                                    RoutingSlipEvents.Faulted |
                                    RoutingSlipEvents.ActivityCompleted |
                                    RoutingSlipEvents.ActivityFaulted |
                                    RoutingSlipEvents.ActivityCompensated |
                                    RoutingSlipEvents.ActivityCompensationFailed);

            var routingSlip = builder.Build();

            await context.Send <IRoutingSlipStarted>(Office365ServiceConstants.QueueOffice365RoutingSlipStartedUri, new
            {
                builder.TrackingNumber,
                CreateTimestamp      = DateTime.UtcNow,
                Arguments            = context.Message,
                WorkflowActivityType = WorkflowActivityType.Office365Transition.ToString()
            });

            await context.Send <IOffice365TransitionReportCommand>(Office365ServiceConstants.QueueOffice365TransitioReportUri, new
            {
                command.CompanyId,
                command.ProductItems
            });

            await context.Execute(routingSlip);
        }
Esempio n. 12
0
        public async Task Consume(ConsumeContext <FullfillOrderMessage> context)
        {
            var Baskets = dbContext.OrderItems.Where(x => x.OrderId == context.Message.OrderId)
                          .Select(p => new { ProductId = p.ProductId, Count = p.Count }).ToList();

            logger.LogInformation($"Fullfilled order {context.Message.OrderId}");
            var builder        = new RoutingSlipBuilder(NewId.NextGuid());
            var submitOrderUrl = QueueNames.GetActivityUri(nameof(SubmitOrderActivity));

            builder.AddActivity("SubmitOrder", submitOrderUrl, new
            {
                context.Message.OrderId
            });;
            builder.AddActivity("Payment", QueueNames.GetActivityUri(nameof(PaymentActivity)), new {
                context.Message.OrderId,
                context.Message.CustomerId,
                context.Message.Credit
            });

            builder.AddActivity("TakeProduct", QueueNames.GetActivityUri(nameof(TakeProductActivity)), new
            {
                context.Message.OrderId,
                Baskets
            });
            builder.AddVariable("OrderId", context.Message.OrderId);
            await builder.AddSubscription(context.SourceAddress,
                                          RoutingSlipEvents.Faulted | RoutingSlipEvents.Supplemental,
                                          RoutingSlipEventContents.None, x => x.Send <OrderFulfillFaulted>(new { context.Message.OrderId }));

            await builder.AddSubscription(context.SourceAddress,
                                          RoutingSlipEvents.Completed | RoutingSlipEvents.Supplemental,
                                          RoutingSlipEventContents.None, x => x.Send <OrderFullfillCompleted>(new { context.Message.OrderId }));

            var routingSlip = builder.Build();
            await context.Execute(routingSlip).ConfigureAwait(false);
        }
Esempio n. 13
0
        public async Task Should_use_scope()
        {
            var trackingNumber = NewId.NextGuid();
            var builder        = new RoutingSlipBuilder(trackingNumber);

            builder.AddSubscription(Bus.Address, RoutingSlipEvents.All);

            builder.AddActivity("TestActivity", _executeAddress, new { Value = "Hello" });

            await Bus.Execute(builder.Build());

            var result = await ExecuteTaskCompletionSource.Task;

            Assert.IsNotNull(result);
        }
Esempio n. 14
0
        public async Task Execute(ConsumeContext <ICreateCompanyCommand> context)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());
            var createCompanyCommand = context.Message;

            builder.AddActivity(CompanyServiceConstants.ActivityCreateAdCompany, _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreateActiveDirectoryComapnyActivity)), _activityCompanyArgumentsMapper.MapActiveDirectoryCompanyArguments(createCompanyCommand));

            builder.AddActivity(CompanyServiceConstants.ActivityCreateDatabaseCompany, _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreateDatabaseCompanyActivity)), _activityCompanyArgumentsMapper.MapDatabaseCompanyArguments(createCompanyCommand));

            builder.AddActivity(CompanyServiceConstants.ActivityAssignCatalog, _activityConfigurator.GetActivityExecuteUri(context, typeof(IAssignCatalogActivity)), _activityCompanyArgumentsMapper.MapAssignCatalogArguments(createCompanyCommand));

            if (createCompanyCommand.Company.Type == CompanyType.Reseller)
            {
                builder.AddActivity(CompanyServiceConstants.ActivityAddCallbackRedirectUri,
                                    _activityConfigurator.GetActivityExecuteUri(context, typeof(IAddCallbackRedirectUriActivity)),
                                    new
                {
                    Uri = createCompanyCommand.Company.ControlPanelSiteUrl,
                    createCompanyCommand.ClientDbId
                });
            }

            builder.AddActivity(UserServiceConstants.ActivityCreateAdUser, _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreateActiveDirectoryUserActivity)), _activityUserArgumentsMapper.MapActiveDirectoryUserArguments(createCompanyCommand));

            builder.AddActivity(UserServiceConstants.ActivityCreateIsUser, _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreateIdentityServerUserActivity)), _activityUserArgumentsMapper.MapIdentityServerUserArguments(createCompanyCommand));

            builder.AddActivity(CompanyServiceConstants.ActivityCompanyCreated, _activityConfigurator.GetActivityExecuteUri(context, typeof(ICompanyCreatedActivity)), _activityCompanyArgumentsMapper.MapCreatedComapnySendEmailArguments(createCompanyCommand));

            builder.AddSubscription(CompanyServiceConstants.RoutingSlipEventObserverUri,
                                    RoutingSlipEvents.Completed |
                                    RoutingSlipEvents.Faulted |
                                    RoutingSlipEvents.ActivityCompleted |
                                    RoutingSlipEvents.ActivityFaulted |
                                    RoutingSlipEvents.ActivityCompensated |
                                    RoutingSlipEvents.ActivityCompensationFailed);

            var routingSlip = builder.Build();

            await context.Send <IRoutingSlipStarted>(CompanyServiceConstants.RoutingSlipCompanyStartedEventUri, new
            {
                builder.TrackingNumber,
                CreateTimestamp      = DateTime.UtcNow,
                Arguments            = context.Message,
                WorkflowActivityType = WorkflowActivityType.CreateCompany.ToString()
            });

            await context.Execute(routingSlip);
        }
Esempio n. 15
0
        public async Task Should_publish_the_completed_event()
        {
            Task <ConsumeContext <RoutingSlipCompleted> > completed = SubscribeHandler <RoutingSlipCompleted>();

            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            builder.AddSubscription(Bus.Address, RoutingSlipEvents.All);

            var testActivity = GetActivityContext <TestActivity>();

            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new { Value = "Hello" });

            await Bus.Execute(builder.Build());

            await completed;
        }
Esempio n. 16
0
        public async Task Should_complete_the_routing_slip()
        {
            var completed = SubscribeHandler <RoutingSlipCompleted>();

            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            builder.AddSubscription(Bus.Address, RoutingSlipEvents.Completed);
            builder.AddActivity("Ping", new Uri("loopback://localhost/Ping_execute"));
            builder.AddActivity("PingSecond", new Uri("loopback://localhost/PingSecond_execute"));

            await Bus.Execute(builder.Build());

            var routingSlipCompleted = await completed;

            Assert.That(routingSlipCompleted.Message.TrackingNumber, Is.EqualTo(builder.TrackingNumber));
        }
Esempio n. 17
0
        public void Should_serialize_and_deserialize_properly()
        {
            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            builder.AddActivity("a", new Uri("loopback://locahost/execute_a"));

            builder.AddSubscription(new Uri("loopback://localhost/events"), RoutingSlipEvents.Completed | RoutingSlipEvents.Faulted);

            var routingSlip = builder.Build();

            var jsonString = routingSlip.ToJsonString();

            var loaded = RoutingSlipExtensions.GetRoutingSlip(jsonString);

            Assert.AreEqual(RoutingSlipEvents.Completed | RoutingSlipEvents.Faulted, loaded.Subscriptions[0].Events);
        }
Esempio n. 18
0
        public static async Task EnviaLancamento(IBus bus, int conta, string desc, decimal valor)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            builder.AddActivity("GeraLancamento", GetQueueUri(bus, ContaCorrenteQueues.ActivityQueue),
                                new GeraLancamento(conta, valor));

            builder.AddActivity("EnvioSPB", GetQueueUri(bus, SPBQueues.CommandQueue),
                                new EnviaTransacao(conta, valor, desc));


            builder.AddSubscription(GetQueueUri(bus, "routingSlipLogs"), RoutingSlipEvents.All);

            var routingSlip = builder.Build();

            await bus.Execute(routingSlip);
        }
        public async Task Consume(ConsumeContext <TRequest> context)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            builder.AddSubscription(context.ReceiveContext.InputAddress, RoutingSlipEvents.ActivityCompleted | RoutingSlipEvents.ActivityFaulted);

            builder.AddVariable("RequestId", context.RequestId);
            builder.AddVariable("ResponseAddress", context.ResponseAddress);
            builder.AddVariable("FaultAddress", context.FaultAddress);
            builder.AddVariable("Request", context.Message);

            await BuildRoutingSlip(builder, context);

            var routingSlip = builder.Build();

            await context.Execute(routingSlip).ConfigureAwait(false);
        }
Esempio n. 20
0
        public async Task Should_register_and_execute_the_activity()
        {
            _completed         = SubscribeHandler <RoutingSlipCompleted>();
            _activityCompleted = SubscribeHandler <RoutingSlipActivityCompleted>();

            _trackingNumber = NewId.NextGuid();
            var builder = new RoutingSlipBuilder(_trackingNumber);

            builder.AddSubscription(Bus.Address, RoutingSlipEvents.All);

            builder.AddActivity("TestActivity", _executeAddress, new { Value = "Hello" });

            await Bus.Execute(builder.Build());

            await _completed;
            await _activityCompleted;
        }
Esempio n. 21
0
        public async Task Should_publish_the_completed_event()
        {
            _completed         = SubscribeHandler <RoutingSlipCompleted>();
            _activityCompleted = SubscribeHandler <RoutingSlipActivityCompleted>();

            _trackingNumber = NewId.NextGuid();
            var builder = new RoutingSlipBuilder(_trackingNumber);

            builder.AddSubscription(Bus.Address, RoutingSlipEvents.ActivityCompleted, RoutingSlipEventContents.None);

            var testActivity = GetActivityContext <TestActivity>();

            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new { Value = "Hello" });

            builder.AddVariable("Variable", "Knife");

            await Bus.Execute(builder.Build());
        }
        public async Task Execute(BehaviorContext <FutureState, T> context, Behavior <FutureState, T> next)
        {
            ConsumeEventContext <FutureState, T> consumeContext = context.CreateConsumeContext();

            // this will need to be done by a consumer at some point, to handle retry/fault handling

            var trackingNumber = context.Instance.CorrelationId;

            var builder = new RoutingSlipBuilder(trackingNumber);

            builder.AddSubscription(consumeContext.ReceiveContext.InputAddress, RoutingSlipEvents.Completed | RoutingSlipEvents.Faulted);

            await _planner.PlanItinerary(consumeContext.Data, builder).ConfigureAwait(false);

            var routingSlip = builder.Build();

            await consumeContext.Execute(routingSlip).ConfigureAwait(false);
        }
        public async Task Should_receive_the_response()
        {
            _completed         = SubscribeHandler <RoutingSlipCompleted>();
            _activityCompleted = SubscribeHandler <RoutingSlipActivityCompleted>();

            _trackingNumber = NewId.NextGuid();

            var builder = new RoutingSlipBuilder(_trackingNumber);

            builder.AddSubscription(Bus.Address, RoutingSlipEvents.All);

            builder.AddActivity("SendRequestActivity", _executeAddress, new { });

            await Bus.Execute(builder.Build());

            await _completed;
            await _activityCompleted;
        }
        async Task Execute(FutureConsumeContext <T> consumeContext)
        {
            // this will need to be done by a consumer at some point, to handle retry/fault handling

            var trackingNumber = NewId.NextGuid();

            var builder = new RoutingSlipBuilder(trackingNumber);

            builder.AddVariable(nameof(consumeContext.FutureId), consumeContext.FutureId);

            builder.AddSubscription(consumeContext.ReceiveContext.InputAddress, RoutingSlipEvents.Completed | RoutingSlipEvents.Faulted);

            await _planner.PlanItinerary(consumeContext.Message, builder).ConfigureAwait(false);

            var routingSlip = builder.Build();

            await consumeContext.Execute(routingSlip).ConfigureAwait(false);
        }
Esempio n. 25
0
        public async Task Execute(ConsumeContext <IOffice365HardDeleteUserCommand> context)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());
            var command = context.Message;

            builder.AddActivity(Office365ServiceConstants.ActivityHardDeleteDatabaseUser,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IDeleteDatabaseUserActivity)),
                                new
            {
                command.UserPrincipalName,
                WorkflowActivityType = WorkflowActivityType.Office365HardDeleteUser,
                WorkflowStep         = WorkflowActivityStep.Office365HardDeleteDatabaseUser
            });

            builder.AddActivity(Office365ServiceConstants.ActivityHardDeletePartnerPlatformUser,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IHardDeletePartnerPlatformUserActivity)),
                                new
            {
                command.Office365CustomerId,
                command.UserPrincipalName,
                WorkflowActivityType = WorkflowActivityType.Office365HardDeleteUser,
                WorkflowStep         = WorkflowActivityStep.Office365HardDeletePartnerPortalUser
            });

            builder.AddSubscription(Office365ServiceConstants.QueueOffice365RoutingSlipEventUri,
                                    RoutingSlipEvents.Completed |
                                    RoutingSlipEvents.Faulted |
                                    RoutingSlipEvents.ActivityCompleted |
                                    RoutingSlipEvents.ActivityFaulted |
                                    RoutingSlipEvents.ActivityCompensated |
                                    RoutingSlipEvents.ActivityCompensationFailed);

            var routingSlip = builder.Build();

            await context.Send <IRoutingSlipStarted>(Office365ServiceConstants.QueueOffice365RoutingSlipStartedUri, new
            {
                builder.TrackingNumber,
                CreateTimestamp      = DateTime.UtcNow,
                Arguments            = context.Message,
                WorkflowActivityType = WorkflowActivityType.Office365HardDeleteUser.ToString()
            });

            await context.Execute(routingSlip);
        }
Esempio n. 26
0
        public async Task Execute(ConsumeContext <IOffice365UserChangeLicenseCommand> context)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());
            var command = context.Message;

            builder.AddActivity(Office365ServiceConstants.ActivityRemoveLicensePartnerPortalUser,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IRemoveLicensePartnerPortalUserActivity)),
                                _mapper.MapRemoveLicensePartnerPortalUserArguments(command));

            builder.AddActivity(Office365ServiceConstants.ActivityRemoveLicenseDatabaseUser,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IRemoveLicenseDatabaseUserActivity)),
                                _mapper.MapRemoveLicenseDatabaseUserArguments(command));

            builder.AddActivity(Office365ServiceConstants.ActivityAssignLicenseOffice365PartnerPlatformUser,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IAssignLicenseToPartnerPlatformUserActivity)),
                                _mapper.MapAssignLicenseOffice365PartnerPlatformUserArguments(command));

            builder.AddActivity(Office365ServiceConstants.ActivityAssignLicenseOffice365DatabaseUser,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IAssignLicenseToDatabaseUserActivity)),
                                _mapper.MapAssignLicenseOffice365DatabaseUserArguments(command));

            if (command.UserRoles.Any())
            {
                builder.AddActivity(Office365ServiceConstants.ActivityGetUserRoles,
                                    _activityConfigurator.GetActivityExecuteUri(context, typeof(IGetUserRolesActivity)), _mapper.MapGetUserRolesArguments(command));

                builder.AddActivity(Office365ServiceConstants.ActivityRemoveUserRoles,
                                    _activityConfigurator.GetActivityExecuteUri(context, typeof(IRemoveUserRolesActivity)), _mapper.MapRemoveUserRolesArguments(command));

                builder.AddActivity(Office365ServiceConstants.ActivityAssignUserRoles,
                                    _activityConfigurator.GetActivityExecuteUri(context, typeof(IAssignUserRolesActivity)), _mapper.MapAssignUserRolesArguments(command));
            }

            builder.AddSubscription(Office365ServiceConstants.RoutingSlipEventObserverUri,
                                    RoutingSlipEvents.ActivityCompleted |
                                    RoutingSlipEvents.ActivityFaulted |
                                    RoutingSlipEvents.ActivityCompensated |
                                    RoutingSlipEvents.ActivityCompensationFailed);

            var routingSlip = builder.Build();

            await context.Execute(routingSlip);
        }
Esempio n. 27
0
        public async Task Should_register_and_execute_the_activity()
        {
            _completed         = SubscribeHandler <RoutingSlipCompleted>();
            _activityCompleted = SubscribeHandler <RoutingSlipActivityCompleted>();

            _trackingNumber = NewId.NextGuid();
            var builder = new RoutingSlipBuilder(_trackingNumber);

            builder.AddSubscription(Bus.Address, RoutingSlipEvents.All);

            builder.AddActivity("SetVariableActivity", new Uri("loopback://localhost/custom-setvariable-execute"), new
            {
                Key   = "Hello",
                Value = "Hello"
            });

            await Bus.Execute(builder.Build());

            await _completed;
            await _activityCompleted;
        }
Esempio n. 28
0
        public async Task Execute(FutureConsumeContext <TInput> context)
        {
            var trackingNumber = NewId.NextGuid();

            var builder = new RoutingSlipBuilder(trackingNumber);

            builder.AddVariable(nameof(FutureConsumeContext.FutureId), context.FutureId);

            builder.AddSubscription(context.ReceiveContext.InputAddress, RoutingSlipEvents.Completed | RoutingSlipEvents.Faulted);

            await _buildItinerary(context, builder).ConfigureAwait(false);

            var routingSlip = builder.Build();

            await context.Execute(routingSlip).ConfigureAwait(false);

            if (TrackRoutingSlip)
            {
                context.Instance.Pending.Add(trackingNumber);
            }
        }
Esempio n. 29
0
        public async Task Execute(ConsumeContext <IOffice365UserChangeRolesCommand> context)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());
            var command = context.Message;

            builder.AddActivity(Office365ServiceConstants.ActivityGetUserRoles,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IGetUserRolesActivity)),
                                _mapper.MapGetUserRolesArguments(command));

            builder.AddActivity(Office365ServiceConstants.ActivityRemoveUserRoles,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IRemoveUserRolesActivity)),
                                _mapper.MapRemoveUserRolesArguments(command));

            builder.AddActivity(Office365ServiceConstants.ActivityAssignUserRoles,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IAssignUserRolesActivity)),
                                _mapper.MapAssignUserRolesArguments(command));

            builder.AddVariable("userPrincipalName", context.Message.UserPrincipalName);
            builder.AddVariable("workflowActivityType", WorkflowActivityType.Office365UserChangeRoles.ToString());

            builder.AddSubscription(Office365ServiceConstants.QueueOffice365RoutingSlipEventUri,
                                    RoutingSlipEvents.Completed |
                                    RoutingSlipEvents.Faulted |
                                    RoutingSlipEvents.ActivityCompleted |
                                    RoutingSlipEvents.ActivityFaulted |
                                    RoutingSlipEvents.ActivityCompensated |
                                    RoutingSlipEvents.ActivityCompensationFailed);

            var routingSlip = builder.Build();

            await context.Send <IRoutingSlipStarted>(Office365ServiceConstants.QueueOffice365RoutingSlipStartedUri, new
            {
                builder.TrackingNumber,
                CreateTimestamp      = DateTime.UtcNow,
                Arguments            = context.Message,
                WorkflowActivityType = WorkflowActivityType.Office365UserChangeRoles.ToString()
            });

            await context.Execute(routingSlip);
        }
Esempio n. 30
0
        private RoutingSlip VoluntarilyCloseAccount(string username)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            builder.AddActivity(
                nameof(GenerateFinalProratedInvoice),
                new Uri("rabbitmq://localhost/generatefinalinvoice"),
                new { Username = username });

            builder.AddActivity(
                nameof(ChargeAllOpenInvoices),
                new Uri("rabbitmq://localhost/chargeallopeninvoices"),
                new { Username = username });

            builder.AddActivity(
                nameof(CloseAccount),
                new Uri("rabbitmq://localhost/closeaccount"),
                new { Username = username });

            builder.AddSubscription(new Uri("rabbitmq://localhost/RoutingSlipEvents"), RoutingSlipEvents.All);
            return(builder.Build());
        }