Exemplo n.º 1
0
        private IRestResponse ChangeState(TimeWarpCommand command, TimeWarpAgent timeWarpAgent)
        {
            var request =
                new RestRequest(
                    string.Format("userstate/?command={0}&agent={1}", (int)command, (int)timeWarpAgent),
                    Method.POST);

            request.AddHeader("login-token", LoginToken);
            var response = Client.Execute(request);

            return(response);
            // Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
        }
Exemplo n.º 2
0
        // PUT api/values/5
        public void Post(HttpRequestMessage request, TimeWarpCommand command, TimeWarpAgent agent = TimeWarpAgent.Unknown)
        {
            long id;

            if (!_authenticationManager.TryAuthenticateForWriteOperation(request.GetToken(), out id))
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
            }

            if (Log.IsDebugEnabled)
            {
                Log.DebugFormat("updating userState for account ({0}) with command ({1})", id, command);
            }

            var requestTime = _nowProvider.Now;

            var account = _accountRepository.Get(id);

            if (account == null)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NoContent));
            }

            switch (command)
            {
            case (TimeWarpCommand.Work):
                _userStateManager.StartWork(account, requestTime, (int)agent);
                break;

            case (TimeWarpCommand.Rest):
                _userStateManager.StartRest(account, requestTime, (int)agent);
                break;

            default:
                throw new InvalidEnumArgumentException("command", (int)command, typeof(TimeWarpCommand));
            }
        }
Exemplo n.º 3
0
        // PUT api/values/5
        public void Post(long id, TimeWarpCommand command)
        {
            var requestTime = _nowProvider.Now;

            var user = _users.Get(id);

            TimeWarpUserState newState;

            switch (command)
            {
            case (TimeWarpCommand.Work):
                newState = user.StartWork(requestTime);
                break;

            case (TimeWarpCommand.Rest):
                newState = user.StartRest(_nowProvider.Now);
                break;

            default:
                throw new InvalidEnumArgumentException("command", (int)command, typeof(TimeWarpCommand));
            }

            _persistence.SaveState(newState);
        }