示例#1
0
        private static TimeWarpUserState UpdateValuesInDatabase(Account account)
        {
            var repository = new TimeWarpUserStateRepository();
            TimeWarpUserState timeWarpUserState = repository.GetLatestStateByAccountId(account.Id);

            return(timeWarpUserState);
        }
示例#2
0
        public AccountCreationResponse CreateAccount(QuickCreationInfo quickAccountCreationInfo)
        {
            if (!_validator.IsDisplayNameValid(quickAccountCreationInfo.DisplayName))
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    ReasonPhrase = "display name is invalid"
                });
            }

            var randomString = Guid.NewGuid().ToString();

            string fakeEmail       = string.Empty;
            string fakePassword    = randomString;
            var    account         = new Account(0, quickAccountCreationInfo.DisplayName, fakeEmail, AccountType.Quick);
            var    defaultState    = TimeWarpUserState.DefaultState(account);
            var    accountPassword = new AccountPassword(account, fakePassword);

            //save

            _accountRepository.Add(account);
            _passwordRepository.Add(accountPassword);
            _userStateRepository.Add(defaultState);

            string token = _authenticationManager.AddUser(accountPassword);

            if (Log.IsDebugEnabled)
            {
                Log.DebugFormat("account created for {0}", randomString);
            }


            return(new AccountCreationResponse(account.Id, token));
        }
 public void SaveState(TimeWarpUserState newState)
 {
     //this should probably be on a new thread...and exception handling. logging ..etc
     using (var session = new NHibernateSessionPerRequest <TimeWarpUserStateClassMap>())
     {
         var repository = new TimeWarpUserStateRepository(session.GetCurrentSession());
         repository.Add(newState);
     }
 }
示例#4
0
        private static void CreateInitialValuesInDatabase(Account account, TimeWarpUserState state1, TimeWarpUserState state2)
        {
            var accountRepository = new AccountRepository();

            accountRepository.Add(account);

            var repository = new TimeWarpUserStateRepository();

            repository.Add(state1);
            repository.Add(state2);
        }
示例#5
0
        public AccountCreationResponse CreateAccount(FullAccountCreationInfo fullAccountCreationInfo)
        {
            if (!_validator.IsEmailValid(fullAccountCreationInfo.EmailAddress))
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    ReasonPhrase = "email address is invalid"
                });
            }

            if (!_validator.IsDuplicateEmailAddress(fullAccountCreationInfo.EmailAddress))
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    ReasonPhrase = "email address is duplicate"
                });
            }

            if (!_validator.IsDisplayNameValid(fullAccountCreationInfo.DisplayName))
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    ReasonPhrase = "display name is invalid"
                });
            }

            //does email address exist?
            var account         = new Account(0, fullAccountCreationInfo.DisplayName, fullAccountCreationInfo.EmailAddress, AccountType.Full);
            var defaultState    = TimeWarpUserState.DefaultState(account);
            var accountPassword = new AccountPassword(account, fullAccountCreationInfo.Password);

            //save
            _accountRepository.Add(account);
            _passwordRepository.Add(accountPassword);
            _userStateRepository.Add(defaultState);

            string token = _authenticationManager.AddUser(accountPassword);

            if (Log.IsDebugEnabled)
            {
                Log.DebugFormat("account created for {0}", fullAccountCreationInfo.EmailAddress);
            }

            return(new AccountCreationResponse(account.Id, token));
        }
示例#6
0
        public void CanUpdateState()
        {
            var account = TestHelper.AccountMock();
            var state1  = new TimeWarpUserState(account, TimeWarpState.Working, new DateTime(2000, 12, 12, 12, 12, 12),
                                                new TimeSpan(1, 30, 2), 3.0, 4);
            var state2 = new TimeWarpUserState(account, TimeWarpState.Resting, new DateTime(2001, 12, 12, 12, 12, 12),
                                               new TimeSpan(1, 30, 2), 3.0, 3);

            CreateInitialValuesInDatabase(account, state1, state2);

            var timeWarpUserState = UpdateValuesInDatabase(account);

            Assert.IsNotNull(timeWarpUserState);
            Assert.AreEqual(account.Id, timeWarpUserState.Account.Id);
            Assert.AreEqual(account.Name, timeWarpUserState.Account.Name);
            Assert.AreEqual(TimeWarpState.Resting, timeWarpUserState.State);
            Assert.AreEqual(3, timeWarpUserState.AgentType);
        }
示例#7
0
 public static UserStateInfoResponse ConvertToPublicV001(this TimeWarpUserState timeWarpUser, DateTime queryTime)
 {
     return(new UserStateInfoResponse(timeWarpUser.Account.Id, timeWarpUser.Account.Name, queryTime, timeWarpUser.State.ConvertToPublicV001(),
                                      timeWarpUser.PeriodStartTime, timeWarpUser.TimeLeft, timeWarpUser.Progress, timeWarpUser.Account.AccountType == AccountType.Quick, (TimeWarpAgent)timeWarpUser.AgentType));
 }
示例#8
0
 public void SaveState(TimeWarpUserState timeWarpUserState)
 {
     //do nothing.
 }