コード例 #1
0
        private RegistrationStatus RegisterAccount(ComplexUserAccount newAccount, out ComplexUserAccount registeredAcc)
        {
            lock (Locker)
            {
                registeredAcc = null;

                try
                {
                    UserAccountModel   trimmedAccount    = new AccountValidator(newAccount).Trim();
                    ComplexUserAccount trimmedComplexAcc = trimmedAccount.ToComplex();
                    trimmedComplexAcc.PasswordDatas.AddRange(newAccount.PasswordDatas);

                    trimmedComplexAcc.RegistrationTime = DateTime.Now;

                    AccountDbInteracter.Instance.AddOrUpdate(trimmedComplexAcc);

                    stateService.RegisterNewUserState(trimmedComplexAcc);
                    passwordService.SaveOrUpdatePassword(newAccount.PasswordDatas[0], false);

                    registeredAcc = trimmedComplexAcc;

                    return(RegistrationStatus.Registered);
                }
                catch (Exception ex)
                {
                    string message = $"Failed to register account '{newAccount.Name}': {ex.Message}";
                    logger.Error(ex, "Failed to register account");
                    message.WriteToConsole(ConsoleColor.Red);

                    return(RegistrationStatus.Error);
                }
            }
        }