public async Task Execute(ConsumeContext <IDeleteUserCommand> context)
        {
            var builder           = new RoutingSlipBuilder(NewId.NextGuid());
            var deleteUserCommand = context.Message;

            builder.AddActivity(UserServiceConstants.ActivityDeleteAdUser, _activityConfigurator.GetActivityExecuteUri(context, typeof(IDeleteActiveDirectoryUserActivity)), _activityArgumentsMapper.MapDeleteActiveDirectoryUserArguments(deleteUserCommand));
            builder.AddActivity(UserServiceConstants.ActivityDeleteIsUser, _activityConfigurator.GetActivityExecuteUri(context, typeof(IDeleteIdentityServerUserActivity)), _activityArgumentsMapper.MapDeleteIdentityServerUserArguments(deleteUserCommand));

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

            var user = _userService.GetUser(context.Message.UserId);
            await builder.AddSubscription(Office365ServiceConstants.QueueOffice365UserRemoveLicenseUri,
                                          RoutingSlipEvents.Completed,
                                          x => x.Send <IOffice365UserRemoveLicenseCommand>(new
            {
                context.Message.CompanyId,
                UserPrincipalName = user.Email
            }));

            var routingSlip = builder.Build();

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

            var updateUserCommand = context.Message;

            builder.AddActivity(UserServiceConstants.ActivityUpdateAdUser, _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateActiveDirectoryUserActivity)), _activityArgumentsMapper.MapActiveDirectoryUserArguments(updateUserCommand));

            builder.AddActivity(UserServiceConstants.ActivityUpdateIsUser, _activityConfigurator.GetActivityExecuteUri(context, typeof(IUpdateIdentityServerUserActivity)), _activityArgumentsMapper.MapIdentityServerUserArguments(updateUserCommand));

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

            var routingSlip = builder.Build();

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

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

            builder.AddActivity(Office365ServiceConstants.ActivityAddOffice365CustomerDomainToPartnerPortal,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IAddCustomerDomainPartnerPortalActivity)),
                                _mapper.MapAddCustomerDomainPartnerPortalArguments(command));

            builder.AddActivity(Office365ServiceConstants.ActivityAddOffice365CustomerDomainToDatabase,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IAddCustomerDomainToDatabaseActivity)),
                                _mapper.MapAddCustomerDomainToDatabaseArguments(command));

            builder.AddActivity(Office365ServiceConstants.ActivityGetOffice365CustomerTxtRecords,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IGetCustomerDomainTxtRecordsActivity)),
                                _mapper.MapGetCustomerTxtRecords(command));

            builder.AddActivity(Office365ServiceConstants.ActivitySendOffice365CustomerTxtRecords,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(ISendCustomerDomainTxtRecordsActivity)),
                                _mapper.MapSendCustomerTxtRecords(command));

            builder.AddVariable("domain", context.Message.Domain);
            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.Office365AddAdditionalDomain.ToString()
            });

            await context.Execute(routingSlip);
        }
Exemplo n.º 4
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);
        }
        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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }
        public async Task Consume(ConsumeContext <IOffice365UserCreateCommand> context)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());
            var command = context.Message;

            var user = _userService.GetUser(command.UserPrincipalName);

            if (user == null)
            {
                throw new Exception($"User {command.UserPrincipalName} does not exist in system");
            }

            builder.AddActivity(Office365ServiceConstants.ActivityCreateOffice365PartnerPlatformUser,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreatePartnerPlatformUserActivity)),
                                new
            {
                command.CompanyId,
                command.UserPrincipalName,
                user.DisplayName,
                user.FirstName,
                user.LastName,
                command.UsageLocation,
                user.City,
                user.Country,
                user.PhoneNumber,
                PostalCode = user.ZipCode,
                user.State,
                command.Password,
                user.StreetAddress,
                WorkflowActivityType = WorkflowActivityType.Office365CreateUser,
                WorkflowStep         = WorkflowActivityStep.Office365CreatePartnerPlatformUser
            });

            builder.AddActivity(Office365ServiceConstants.ActivityCreateOffice365DatabaseUser,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreateDatabaseUserActivity)),
                                new
            {
                command.UserPrincipalName,
                WorkflowActivityType = WorkflowActivityType.Office365CreateUser,
                WorkflowStep         = WorkflowActivityStep.Office365CreateDatabaseUser
            });

            if (command.UserRoles.Any())
            {
                builder.AddActivity(Office365ServiceConstants.ActivityAssignUserRoles,
                                    _activityConfigurator.GetActivityExecuteUri(context, typeof(IAssignUserRolesActivity)),
                                    new
                {
                    command.UserPrincipalName,
                    command.UserRoles,
                    WorkflowActivityType = WorkflowActivityType.Office365CreateUser,
                    WorkflowStep         = WorkflowActivityStep.Office365AssignUserRoles
                });
            }

            builder.AddActivity(Office365ServiceConstants.ActivitySendOffice365UserSetupEmail,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(ISendUserSetupEmailActivity)),
                                new
            {
                command.UserPrincipalName,
                WorkflowActivityType = WorkflowActivityType.Office365CreateUser,
                WorkflowStep         = WorkflowActivityStep.Office365SendUserSetupEmail
            });

            var routingSlip = builder.Build();

            await context.Send <IRoutingSlipStarted>(Office365ServiceConstants.QueueOffice365RoutingSlipStartedUri, new
            {
                builder.TrackingNumber,
                CreateTimestamp      = DateTime.UtcNow,
                Arguments            = context.Message,
                WorkflowActivityType = WorkflowActivityType.Office365CreateUser.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);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
        public async Task Execute(ConsumeContext <IOffice365ResendTxtRecordsCommand> context)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());
            var resendTxtRecordsCommand = context.Message;

            builder.AddActivity(Office365ServiceConstants.ActivityGetOffice365CustomerTxtRecords, _activityConfigurator.GetActivityExecuteUri(context, typeof(IGetCustomerDomainTxtRecordsActivity)), _activityOffice365CustomerArgumentsMapper.MapGetCustomerTxtRecords(resendTxtRecordsCommand));
            builder.AddActivity(Office365ServiceConstants.ActivitySendOffice365CustomerTxtRecords, _activityConfigurator.GetActivityExecuteUri(context, typeof(ISendCustomerDomainTxtRecordsActivity)), _activityOffice365CustomerArgumentsMapper.MapSendCustomerTxtRecords(resendTxtRecordsCommand));

            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.ResendOffice365DomainTxtRecords.ToString()
            });

            await context.Execute(routingSlip);
        }
Exemplo n.º 14
0
        public async Task Execute(ConsumeContext <IOffice365TransitionUserAndLicensesCommand> context)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());
            var command = context.Message;

            this.Log().Info($"01 - User: {command.UserPrincipalName}");
            this.Log().Info($"Admin: {command.Admin}");
            this.Log().Info($"RemoveLicenses: {command.RemoveLicenses}");
            this.Log().Info($"CloudPlusUserExist: {command.CloudPlusUserExist}");
            this.Log().Info($"IsNewLicenses: {command.Admin}");

            if (!command.CloudPlusUserExist)
            {
                this.Log().Info($"02 - Enter in CloudPlusExist: {command.UserPrincipalName}");

                builder.AddActivity(UserServiceConstants.ActivityCreateAdUser,
                                    _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreateActiveDirectoryUserActivity)),
                                    _mapper.MapCreateAdUserArguments(command));

                builder.AddActivity(UserServiceConstants.ActivityCreateIsUser,
                                    _activityConfigurator.GetActivityExecuteUri(context, typeof(ICreateIdentityServerUserActivity)),
                                    _mapper.MapCreateIsUserArguments(command));
            }

            this.Log().Info($"03 - Create Office 365 Database User: {command.UserPrincipalName}");

            builder.AddActivity(Office365ServiceConstants.SetImmutableId,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(ISetImmutableIdActivity)),
                                new
            {
                command.Office365CustomerId,
                command.UserPrincipalName
            });

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

            if (!command.KeepLicences)
            {
                if (command.Admin)
                {
                    this.Log().Info($"04 - Enter in Admin: {command.UserPrincipalName}");

                    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));
                }

                this.Log().Info($"05 - Remove All Licenses Partner Portal User: {command.UserPrincipalName}");

                builder.AddActivity(Office365ServiceConstants.ActivityRemoveAllLicensesPartnerPortalUser,
                                    _activityConfigurator.GetActivityExecuteUri(context,
                                                                                typeof(IRemoveAllLicensesPartnerPortalUserActivity)),
                                    _mapper.MapRemoveAllLicensesPartnerPortalUserArguments(command));

                if (command.IsNewLicenses)
                {
                    this.Log().Info($"06 - Enter in IsNewLicenses: {command.UserPrincipalName}");

                    if (command.CloudPlusProductIdentifier != null)
                    {
                        builder.AddActivity(Office365ServiceConstants.ActivityAssignLicenseOffice365PartnerPlatformUser,
                                            _activityConfigurator.GetActivityExecuteUri(context,
                                                                                        typeof(IAssignLicenseToPartnerPlatformUserActivity)),
                                            _mapper.MapAssignLicenseOffice365PartnerPlatformUserArguments(command));

                        builder.AddActivity(Office365ServiceConstants.ActivityAssignLicenseOffice365DatabaseUser,
                                            _activityConfigurator.GetActivityExecuteUri(context,
                                                                                        typeof(IAssignLicenseToDatabaseUserActivity)),
                                            _mapper.MapAssignLicenseOffice365DatabaseUserArguments(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.Office365TransitionUserAndLicenses.ToString()
            });

            await context.Execute(routingSlip);
        }
Exemplo n.º 15
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);
        }
        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);
        }
        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 Consume(ConsumeContext <IOffice365UserChangeLicenseCommand> context)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());
            var command = context.Message;

            builder.AddActivity(Office365ServiceConstants.ActivityRemoveLicensePartnerPortalUser,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IRemoveLicensePartnerPortalUserActivity)),
                                new
            {
                command.UserPrincipalName,
                command.Office365CustomerId,
                CloudPlusProductIdentifier = command.RemoveCloudPlusProductIdentifier,
                WorkflowActivityType       = WorkflowActivityType.Office365UserChangeLicense,
                WorkflowStep = WorkflowActivityStep.Office365RemoveLicensePartnerPortalUser
            });

            builder.AddActivity(Office365ServiceConstants.ActivityRemoveLicenseDatabaseUser,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IRemoveLicenseDatabaseUserActivity)),
                                new
            {
                command.UserPrincipalName,
                command.Office365CustomerId,
                CloudPlusProductIdentifier = command.RemoveCloudPlusProductIdentifier,
                WorkflowActivityType       = WorkflowActivityType.Office365UserChangeLicense,
                WorkflowStep = WorkflowActivityStep.Office365RemoveLicenseDatabaseUser
            });

            builder.AddActivity(Office365ServiceConstants.ActivityAssignLicenseOffice365PartnerPlatformUser,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IAssignLicenseToPartnerPlatformUserActivity)),
                                new
            {
                command.UserPrincipalName,
                command.Office365CustomerId,
                CloudPlusProductIdentifier = command.AssignCloudPlusProductIdentifier,
                WorkflowActivityType       = WorkflowActivityType.Office365UserChangeLicense,
                WorkflowStep = WorkflowActivityStep.Office365AssignLicenseToPartnerPlatformUser
            });

            builder.AddActivity(Office365ServiceConstants.ActivityAssignLicenseOffice365DatabaseUser,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IAssignLicenseToDatabaseUserActivity)),
                                new
            {
                command.UserPrincipalName,
                command.Office365CustomerId,
                CloudPlusProductIdentifier = command.AssignCloudPlusProductIdentifier,
                WorkflowActivityType       = WorkflowActivityType.Office365UserChangeLicense,
                WorkflowStep = WorkflowActivityStep.Office365AssignLicenseToDatabaseUser
            });

            builder.AddActivity(Office365ServiceConstants.ActivityGetUserRoles,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IGetUserRolesActivity)),
                                new
            {
                command.CompanyId,
                command.UserPrincipalName,
                command.Office365CustomerId,
                WorkflowActivityType = WorkflowActivityType.Office365UserChangeLicense,
                WorkflowStep         = WorkflowActivityStep.Office365GetUserRoles
            });

            builder.AddActivity(Office365ServiceConstants.ActivityRemoveUserRoles,
                                _activityConfigurator.GetActivityExecuteUri(context, typeof(IRemoveUserRolesActivity)),
                                new
            {
                command.UserPrincipalName,
                command.Office365CustomerId,
                WorkflowActivityType = WorkflowActivityType.Office365UserChangeLicense,
                WorkflowStep         = WorkflowActivityStep.Office365RemoveUserRoles
            });

            if (command.UserRoles.Any())
            {
                builder.AddActivity(Office365ServiceConstants.ActivityAssignUserRoles,
                                    _activityConfigurator.GetActivityExecuteUri(context, typeof(IAssignUserRolesActivity)),
                                    new
                {
                    command.UserRoles,
                    command.Office365CustomerId,
                    command.UserPrincipalName,
                    WorkflowActivityType = WorkflowActivityType.Office365UserChangeLicense,
                    WorkflowStep         = WorkflowActivityStep.Office365AssignUserRoles
                });
            }

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

            await context.Execute(routingSlip);
        }