public async Task Consume(ConsumeContext <IOffice365GetUserRolesRequest> context)
        {
            var messages = context.Message;

            var office365Customer = await _office365DbCustomerService.GetOffice365CustomerAsync(messages.CompanyId);

            var roles = await _office365ApiService.GetUserRoles(new Office365UserRolesModel
            {
                UserPrincipalName   = messages.UserPrincipalName,
                Office365CustomerId = office365Customer.Office365CustomerId
            });

            context.Respond(new Office365GetUserRolesResponse
            {
                UserRoles = roles
            });
        }
Ejemplo n.º 2
0
        public async Task <ExecutionResult> Execute(ExecuteContext <IGetUserRolesArguments> context)
        {
            var arguments = context.Arguments;

            var office365Customer = await _office365DbCustomerService.GetOffice365CustomerAsync(arguments.CompanyId);

            var roles = await _office365ApiService.GetUserRoles(new Office365UserRolesModel
            {
                Office365CustomerId = office365Customer.Office365CustomerId,
                UserPrincipalName   = arguments.UserPrincipalName
            });

            return(context.CompletedWithVariables(new
            {
                office365Customer.Office365CustomerId,
                CurrentAssignedRoles = roles
            }));
        }
        public async Task Consume(ConsumeContext <IOffice365UserMultiEditCommand> context)
        {
            var messages          = context.Message;
            var office365Customer = await _office365DbCustomerService.GetOffice365CustomerAsync(messages.CompanyId);

            var subscription = await _office365DbSubscriptionService.GetSubscriptionByProductIdentifierAsync(
                office365Customer.Office365CustomerId, messages.CloudPlusProductIdentifier);

            if (subscription == null || subscription.SubscriptionState != Office365SubscriptionState.OperationInProgress)
            {
                await _multiUserEditWorkflow.Execute(context);
            }
            else
            {
                context.Headers.TryGetHeader("MT-Redelivery-Count", out var redeliverCount);
                if (redeliverCount == null || Convert.ToInt32(redeliverCount) < 100) // ????
                {
                    context.Redeliver(TimeSpan.FromSeconds(15));
                }
            }
        }
        public async Task Execute(ConsumeContext <IOffice365UserAssignLicenseCommand> context)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());
            var command = context.Message;

            var customer = await _office365DbCustomerService.GetOffice365CustomerAsync(command.CompanyId);

            var o365UserId =
                await _office365UserService.GetOffice365UserIdAsync(command.UserPrincipalName,
                                                                    customer.Office365CustomerId);

            var o365DbUser = await _office365DbUserService.GetOffice365DatabaseUserAsync(command.UserPrincipalName);

            builder.AddVariable("Office365CustomerId", customer.Office365CustomerId);

            if (o365UserId == null)
            {
                builder.AddActivity(Office365ServiceConstants.ActivityCreateOffice365PartnerPlatformUser,
                                    _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreatePartnerPlatformUserActivity)),
                                    _activityOffice365UserArgumentsMapper.MapCreatePartnerPlatformUserArguments(command));
            }

            if (o365DbUser == null)
            {
                if (o365UserId != null)
                {
                    builder.AddVariable("Office365UserId", o365UserId);
                }

                builder.AddActivity(Office365ServiceConstants.ActivityCreateOffice365DatabaseUser,
                                    _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreateDatabaseUserActivity)),
                                    _activityOffice365UserArgumentsMapper.MapCreateOffice365DatabaseUserArguments(command));
            }

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

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

            if (command.UserRoles.Any())
            {
                builder.AddActivity(Office365ServiceConstants.ActivityAssignUserRoles,
                                    _activityConfigurator.GetActivityExecuteUri(context, typeof(IAssignUserRolesActivity)),
                                    _activityOffice365UserArgumentsMapper.MapAssignUserRolesArguments(command));
            }

            builder.AddActivity(Office365ServiceConstants.ActivitySendOffice365UserSetupEmail,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(ISendUserSetupEmailActivity)),
                                _activityOffice365UserArgumentsMapper.MapSendOffice365UserSetupEmailArguments(command));

            builder.AddVariable("userPrincipalName", context.Message.UserPrincipalName);
            builder.AddVariable("workflowActivityType", WorkflowActivityType.Office365UserAssignLicense.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.Office365UserAssignLicense.ToString()
            });

            await context.Execute(routingSlip);
        }
        public async Task Execute(ConsumeContext <IOffice365FederateDomainRequest> context)
        {
            var builder      = new RoutingSlipBuilder(NewId.NextGuid());
            var command      = context.Message;
            var o365Customer = await _office365DbCustomerService.GetOffice365CustomerAsync(command.CompanyId);

            builder.AddActivity(Office365ServiceConstants.ActivityCreateTempAdminUser,
                                _activityConfigurator.GetActivityExecuteUri(context,
                                                                            typeof(ICreateTempPartnerPlatformAdminUserActivity)),
                                new
            {
                o365Customer.Office365CustomerId,
                WorkflowActivityType = WorkflowActivityType.FederateOffice365Domain,
                WorkflowStep         = WorkflowActivityStep.Office365CreateTempPartnerPlatformAdminUser
            });

            builder.AddActivity(Office365ServiceConstants.ActivityAssignUserRoles,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IAssignUserRolesActivity)),
                                new
            {
                o365Customer.Office365CustomerId,
                WorkflowActivityType = WorkflowActivityType.FederateOffice365Domain,
                WorkflowStep         = WorkflowActivityStep.Office365AssignUserRoles
            });

            builder.AddActivity(Office365ServiceConstants.ActivityFederateCustomerDomain,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IFederateCustomerDomainActivity)),
                                new
            {
                o365Customer.Office365CustomerId,
                command.DomainName,
                WorkflowActivityType = WorkflowActivityType.FederateOffice365Domain,
                WorkflowStep         = WorkflowActivityStep.Office365FederateCustomerDomain
            });

            builder.AddActivity(Office365ServiceConstants.ActivityFederateCustomerDomainDatabaseStatus,
                                _activityConfigurator.GetActivityExecuteUri(context,
                                                                            typeof(IFederateCustomerDomainDatabaseStatusActivity)),
                                new
            {
                o365Customer.Office365CustomerId,
                command.DomainName,
                WorkflowActivityType = WorkflowActivityType.FederateOffice365Domain,
                WorkflowStep         = WorkflowActivityStep.Office365FederateCustomerDomainDatabaseStatus
            });

            builder.AddActivity(Office365ServiceConstants.ActivityHardDeletePartnerPlatformUser,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IHardDeletePartnerPlatformUserActivity)),
                                new
            {
                o365Customer.Office365CustomerId,
                SwallowException     = true,
                WorkflowActivityType = WorkflowActivityType.FederateOffice365Domain,
                WorkflowStep         = WorkflowActivityStep.Office365HardDeletePartnerPortalUser
            });

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

            await builder.AddSubscription(context.ResponseAddress, RoutingSlipEvents.Completed, endpoint =>
                                          endpoint.Send(new Office365FederateDomainResponse {
                IsDomainFederated = true
            },
                                                        sendContext => sendContext.RequestId = context.RequestId));

            await builder.AddSubscription(context.ResponseAddress, RoutingSlipEvents.Faulted, endpoint =>
                                          endpoint.Send(new Office365FederateDomainResponse {
                IsDomainFederated = false
            },
                                                        sendContext => sendContext.RequestId = context.RequestId));

            var routingSlip = builder.Build();

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

            await context.Execute(routingSlip);
        }
Ejemplo n.º 6
0
        public async Task Consume(ConsumeContext <IUserManageSubscriptionAdnChangeLicenseConsumerCommand> context)
        {
            var message           = context.Message;
            var builder           = new RoutingSlipBuilder(NewId.NextGuid());
            var office365Customer = await _office365DbCustomerService.GetOffice365CustomerAsync(message.CompanyId);

            var subscriptionToRemove = await _office365DbSubscriptionService.GetSubscriptionByProductIdentifierAsync(
                office365Customer.Office365CustomerId, message.RemoveCloudPlusProductIdentifier);

            var subscriptionToAdd = await _office365DbSubscriptionService.GetSubscriptionByProductIdentifierAsync(
                office365Customer.Office365CustomerId, message.AssignCloudPlusProductIdentifier);

            builder.AddActivity("UpdateDatabaseSubscriptionState", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateDatabaseSubscriptionStateActivity)), new
            {
                SubscriptionState = Office365SubscriptionState.OperationInProgress,
                subscriptionToRemove.Office365SubscriptionId
            });
            // TODO: Add activity to spend subscription if quantity 1 instead of changing quantity ??


            builder.AddActivity("UpdateDatabaseSubscriptionQuantity", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateDatabaseSubscriptionQuantityActivity)), new
            {
                QuantityChange = -1,
                subscriptionToRemove.Office365SubscriptionId
            });

            builder.AddActivity("UpdatePartnerPlatformSubscriptionQuantity", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdatePartnerPlatformSubscriptionQuantityActivity)), new
            {
                QuantityChange = -1,
                subscriptionToRemove.Office365CustomerId,
                subscriptionToRemove.Office365SubscriptionId
            });

            builder.AddActivity("UpdateDatabaseSubscriptionState", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateDatabaseSubscriptionStateActivity)), new
            {
                SubscriptionState = Office365SubscriptionState.AvailableForOperations,
                subscriptionToRemove.Office365SubscriptionId
            });

            if (subscriptionToAdd == null)
            {
                builder.AddActivity("CreateDatabaseSubscription", _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreateDatabaseSubscriptionActivity)), new
                {
                    office365Customer.Office365CustomerId,
                    CloudPlusProductIdentifier = message.AssignCloudPlusProductIdentifier,
                    Quantity = 1
                });

                builder.AddActivity("CreateOrder", _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreateOrderActivity)), new
                {
                    CloudPlusProductIdentifier = message.AssignCloudPlusProductIdentifier,
                    office365Customer.Office365CustomerId,
                    Quantity = 1
                });

                builder.AddActivity("UpdateDatabaseSubscription", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateDatabaseSubscriptionActivity)), new
                {
                    CloudPlusProductIdentifier = message.AssignCloudPlusProductIdentifier,
                    office365Customer.Office365CustomerId
                });

                builder.AddActivity("UpdateDatabaseSubscriptionState", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateDatabaseSubscriptionStateActivity)), new
                {
                    SubscriptionState = Office365SubscriptionState.AvailableForOperations
                });
            }
            else
            {
                builder.AddActivity("UpdateDatabaseSubscriptionState", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateDatabaseSubscriptionStateActivity)), new
                {
                    SubscriptionState = Office365SubscriptionState.OperationInProgress,
                    subscriptionToAdd.Office365SubscriptionId
                });

                builder.AddActivity("UpdateDatabaseSubscriptionQuantity", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateDatabaseSubscriptionQuantityActivity)), new
                {
                    QuantityChange = 1,
                    subscriptionToAdd.Office365SubscriptionId
                });

                builder.AddActivity("UpdatePartnerPlatformSubscriptionQuantity", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdatePartnerPlatformSubscriptionQuantityActivity)), new
                {
                    QuantityChange = 1,
                    subscriptionToAdd.Office365CustomerId,
                    subscriptionToAdd.Office365SubscriptionId
                });

                builder.AddActivity("UpdateDatabaseSubscriptionState", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateDatabaseSubscriptionStateActivity)), new
                {
                    SubscriptionState = Office365SubscriptionState.AvailableForOperations,
                    subscriptionToAdd.Office365SubscriptionId
                });
            }

            // TODO: Add activities for user licencse add/remove

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

            var routingSlip = builder.Build();

            await context.Execute(routingSlip);
        }
        public async Task Consume(ConsumeContext <IUserManageSubscriptionAndAssignLicenseCommand> context)
        {
            var message           = context.Message;
            var builder           = new RoutingSlipBuilder(NewId.NextGuid());
            var office365Customer = await _office365DbCustomerService.GetOffice365CustomerAsync(message.CompanyId);

            var subscription = await _office365DbSubscriptionService.GetSubscriptionByProductIdentifierAsync(
                office365Customer.Office365CustomerId, message.CloudPlusProductIdentifier);

            if (subscription == null)
            {
                builder.AddActivity("CreateDatabaseSubscription", _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreateDatabaseSubscriptionActivity)), new
                {
                    office365Customer.Office365CustomerId,
                    message.CloudPlusProductIdentifier,
                    Quantity = 1
                });

                builder.AddActivity("CreateOrder", _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreateOrderActivity)), new
                {
                    message.CloudPlusProductIdentifier,
                    office365Customer.Office365CustomerId,
                    Quantity = 1
                });

                builder.AddActivity("UpdateDatabaseSubscription", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateDatabaseSubscriptionActivity)), new
                {
                    message.CloudPlusProductIdentifier,
                    office365Customer.Office365CustomerId
                });

                builder.AddActivity("UpdateDatabaseSubscriptionState", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateDatabaseSubscriptionStateActivity)), new
                {
                    SubscriptionState = Office365SubscriptionState.AvailableForOperations
                });
            }
            else
            {
                builder.AddActivity("UpdateDatabaseSubscriptionState", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateDatabaseSubscriptionStateActivity)), new
                {
                    SubscriptionState = Office365SubscriptionState.OperationInProgress,
                    subscription.Office365SubscriptionId
                });

                builder.AddActivity("UpdateDatabaseSubscriptionQuantity", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateDatabaseSubscriptionQuantityActivity)), new
                {
                    QuantityChange = 1,
                    subscription.Office365SubscriptionId
                });

                builder.AddActivity("UpdatePartnerPlatformSubscriptionQuantity", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdatePartnerPlatformSubscriptionQuantityActivity)), new
                {
                    QuantityChange = 1,
                    subscription.Office365CustomerId,
                    subscription.Office365SubscriptionId
                });

                builder.AddActivity("UpdateDatabaseSubscriptionState", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateDatabaseSubscriptionStateActivity)), new
                {
                    SubscriptionState = Office365SubscriptionState.AvailableForOperations,
                    subscription.Office365SubscriptionId
                });
            }

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

            await builder.AddSubscription(Office365ServiceConstants.QueueOffice365UserAssignLicenseUri,
                                          RoutingSlipEvents.Completed,
                                          x => x.Send <IOffice365UserAssignLicenseCommand>(new
            {
                message.CompanyId,
                message.CloudPlusProductIdentifier,
                message.UserPrincipalName,
                message.DisplayName,
                message.FirstName,
                message.LastName,
                UsageLocation = "US",
                message.City,
                message.Country,
                message.PhoneNumber,
                message.PostalCode,
                message.State,
                message.StreetAddress,
                message.UserRoles
            }));

            var routingSlip = builder.Build();

            await context.Execute(routingSlip);
        }
Ejemplo n.º 8
0
        public async Task Execute(ConsumeContext <IOffice365UserMultiEditCommand> context)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            var message = context.Message;

            var users = _userService.GetUsers(message.CompanyId).ToList();

            var office365Customer = await _office365DbCustomerService.GetOffice365CustomerAsync(message.CompanyId);

            var office365Users = await _office365DbUserService.GetAllCustomerUsersWithLicensesAndOfferAsync(office365Customer.Id);

            var subscription = await _office365DbSubscriptionService.GetSubscriptionByProductIdentifierAsync(
                office365Customer.Office365CustomerId, message.CloudPlusProductIdentifier);

            if (subscription == null)
            {
                builder.AddActivity("CreateDatabaseSubscription", _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreateDatabaseSubscriptionActivity)), new
                {
                    office365Customer.Office365CustomerId,
                    message.CloudPlusProductIdentifier,
                    Quantity = message.UserPrincipalNames.Count()
                });

                builder.AddActivity("CreateOrder", _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreateOrderActivity)), new
                {
                    message.CloudPlusProductIdentifier,
                    office365Customer.Office365CustomerId,
                    Quantity = message.UserPrincipalNames.Count()
                });

                builder.AddActivity("UpdateDatabaseSubscription", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateDatabaseSubscriptionActivity)), new
                {
                    message.CloudPlusProductIdentifier,
                    office365Customer.Office365CustomerId
                });

                builder.AddActivity("UpdateDatabaseSubscriptionState", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateDatabaseSubscriptionStateActivity)), new
                {
                    SubscriptionState = Office365SubscriptionState.AvailableForOperations
                });
            }
            else
            {
                builder.AddActivity("UpdateDatabaseSubscriptionState", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateDatabaseSubscriptionStateActivity)), new
                {
                    SubscriptionState = Office365SubscriptionState.OperationInProgress,
                    subscription.Office365SubscriptionId
                });

                builder.AddActivity("UpdateDatabaseSubscriptionQuantity", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateDatabaseSubscriptionQuantityActivity)), new
                {
                    QuantityChange = message.UserPrincipalNames.Count(),
                    subscription.Office365SubscriptionId
                });

                builder.AddActivity("UpdatePartnerPlatformSubscriptionQuantity", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdatePartnerPlatformSubscriptionQuantityActivity)), new
                {
                    QuantityChange = message.UserPrincipalNames.Count(),
                    subscription.Office365CustomerId,
                    subscription.Office365SubscriptionId
                });

                builder.AddActivity("UpdateDatabaseSubscriptionState", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateDatabaseSubscriptionStateActivity)), new
                {
                    SubscriptionState = Office365SubscriptionState.AvailableForOperations,
                    subscription.Office365SubscriptionId
                });
            }

            var subscriptionsToChange = new Dictionary <string, int>();
            var usersToAssignLicences = new List <UserModel>();
            var usersToChangeRoles    = new List <UserModel>();

            foreach (var principalName in message.UserPrincipalNames)
            {
                var user = users.FirstOrDefault(u => u.UserName == principalName);

                // If there is no user, pass this iteration
                if (user == null)
                {
                    continue;
                }

                var office365User = office365Users.FirstOrDefault(u => u.UserPrincipalName == principalName);

                if (office365User == null)
                {
                    usersToAssignLicences.Add(user);
                }
                else
                {
                    if (office365User.Office365UserState == Office365UserState.Inactive)
                    {
                        continue;
                    }

                    var license = office365User.Licenses.FirstOrDefault(l =>
                                                                        l.Office365Offer.CloudPlusProductIdentifier == message.CloudPlusProductIdentifier);

                    if (license != null)
                    {
                        var subscriptionToDecrease =
                            await _office365DbSubscriptionService.GetSubscriptionByProductIdentifierAsync(
                                office365Customer.Office365CustomerId,
                                license.Office365Offer.CloudPlusProductIdentifier);

                        if (subscriptionsToChange.ContainsKey(subscriptionToDecrease.Office365SubscriptionId))
                        {
                            subscriptionsToChange[subscriptionToDecrease.Office365SubscriptionId]++;
                        }
                        else
                        {
                            subscriptionsToChange.Add(subscriptionToDecrease.Office365SubscriptionId, 1);
                        }
                    }
                    else
                    {
                        usersToChangeRoles.Add(user);
                    }
                }
            }

            //foreach (var subscriptionToChange in subscriptionsToChange)
            //{
            //    builder.AddActivity("UpdateDatabaseSubscriptionState", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateDatabaseSubscriptionActivity)), new
            //    {
            //        SubscriptionState = Office365SubscriptionState.OperationInProgress,
            //        Office365SubscriptionId = subscriptionToChange.Key
            //    });

            //    builder.AddActivity("UpdateDatabaseSubscriptionQuantity", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateDatabaseSubscriptionQuantityActivity)), new
            //    {
            //        QuantityChange = subscriptionToChange.Value * -1,
            //        Office365SubscriptionId = subscriptionToChange.Key
            //    });

            //    builder.AddActivity("UpdatePartnerPlatformSubscriptionQuantity", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdatePartnerPlatformSubscriptionQuantityActivity)), new
            //    {
            //        QuantityChange = subscriptionToChange.Value * -1,
            //        office365Customer.Office365CustomerId,
            //        Office365SubscriptionId = subscriptionToChange.Key
            //    });

            //    builder.AddActivity("UpdateDatabaseSubscriptionState", _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateDatabaseSubscriptionActivity)), new
            //    {
            //        SubscriptionState = Office365SubscriptionState.AvailableForOperations,
            //        Office365SubscriptionId = subscriptionToChange.Key
            //    });
            //}

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


            foreach (var usersToAssignLicence in usersToAssignLicences)
            {
                await builder.AddSubscription(Office365ServiceConstants.QueueOffice365UserAssignLicenseUri,
                                              RoutingSlipEvents.Completed,
                                              x => x.Send <IOffice365UserAssignLicenseCommand>(new
                {
                    message.CompanyId,
                    message.CloudPlusProductIdentifier,
                    UserPrincipalName = usersToAssignLicence.UserName,
                    usersToAssignLicence.DisplayName,
                    usersToAssignLicence.FirstName,
                    usersToAssignLicence.LastName,
                    UsageLocation = "US",
                    usersToAssignLicence.City,
                    usersToAssignLicence.Country,
                    usersToAssignLicence.PhoneNumber,
                    PostalCode = usersToAssignLicence.ZipCode,
                    usersToAssignLicence.State,
                    usersToAssignLicence.StreetAddress,
                    message.UserRoles
                }));
            }

            var routingSlip = builder.Build();

            await context.Execute(routingSlip);
        }