Exemple #1
0
        public async Task <IHttpActionResult> PutSession(string op = "", int aid = 0)
        {
            try
            {
                var token   = GetHeaderSessionToken();
                var guid    = Session.Convert(token);
                var session = SessionsCacheSettings.IsSessionCacheEnabled
                    ? _sessionsCache.Get(token) as Session
                    : null;

                if (session == null)
                {
                    session = await _repo.ExtendSession(guid);

                    if (session == null)
                    {
                        throw new KeyNotFoundException();
                    }

                    _sessionsCache.Add(token, session, DateTimeOffset.UtcNow.Add(SessionsCacheSettings.SessionCacheExpiration));
                    InsertSession(session);
                }

                var response = Request.CreateResponse(HttpStatusCode.OK, session);
                response.Headers.Add("Session-Token", token);

                return(ResponseMessage(response));
            }
            catch (ArgumentNullException)
            {
                return(BadRequest());
            }
            catch (FormatException)
            {
                return(BadRequest());
            }
            catch (KeyNotFoundException)
            {
                return(NotFound());
            }
            catch (Exception ex)
            {
                await _log.LogError(WebApiConfig.LogSourceSessions, ex);

                return(InternalServerError());
            }
        }