예제 #1
0
        public async Task <ExecutionResult> Execute(ExecuteContext <ICreateTempPartnerPlatformAdminUserArguments> context)
        {
            var args = context.Arguments;

            var customerDefaultMicrosoftDomain = await _office365CustomerService.GetCustomerDefaultDomainAsync(args.Office365CustomerId);

            var tempAdminUser = new Office365SdkUser
            {
                Office365CustomerId = args.Office365CustomerId,
                DisplayName         = NewId.NextGuid().ToString("N"),
                FirstName           = "TempAdmin",
                LastName            = "TempAdmin",
                Password            = _configurationManager.GetByKey("Office365TempPassword"),
                UsageLocation       = "US",
                UserPrincipalName   = $"{NewId.NextGuid():N}@{customerDefaultMicrosoftDomain}"
            };

            await _office365UserService.CreateOffice365UserAsync(tempAdminUser);

            return(context.CompletedWithVariables(new
            {
                AdminUserName = tempAdminUser.UserPrincipalName,
                AdminPassword = tempAdminUser.Password,
                tempAdminUser.UserPrincipalName,
                UserRoles = new List <string>
                {
                    "Company Administrator"
                }
            }));
        }
        public async Task <Office365SdkUser> CreateOffice365UserAsync(Office365SdkUser user)
        {
            var requestSuccess = false;
            var attempts       = 1;

            do
            {
                try
                {
                    var createdUser = await _partnerOperations.UserPartnerOperations.Customers.ById(user.Office365CustomerId).Users.CreateAsync(
                        new CustomerUser
                    {
                        PasswordProfile = new PasswordProfile
                        {
                            Password            = user.Password,
                            ForceChangePassword = false
                        },
                        DisplayName       = user.DisplayName,
                        FirstName         = user.FirstName,
                        LastName          = user.LastName,
                        UserPrincipalName = user.UserPrincipalName,
                        UsageLocation     = user.UsageLocation
                    });

                    await ConfirmUserCreated(user.Office365CustomerId, createdUser.Id);

                    user.Office365UserId = createdUser.Id;

                    requestSuccess = true;

                    return(user);
                }
                catch (Exception ex)
                {
                    this.Log().Error($"Create Office 365 User request failed! Attampt: {attempts}", ex);
                    attempts++;
                    await Task.Delay(3000);
                }
            } while (!requestSuccess && attempts < _retryAttempts);

            throw new Exception("Create Office 365 User!");
        }