Пример #1
0
        public HttpResponseMessage OpenSession(int id)
        {
            Session newSession = new Session()
            {
                UserId    = id,
                OpenedDt  = DateTime.Now,
                ExpiresDt = DateTime.Now + TimeSpan.FromHours(1)
            };
            string newSessionId = sessionContext.RegisterSession(newSession);

            HttpResponseMessage response = new HttpResponseMessage();

            if (!string.IsNullOrEmpty(newSessionId))
            {
                OpenSessionResponse openResp = new OpenSessionResponse()
                {
                    SessionId = newSessionId
                };
                response.StatusCode = HttpStatusCode.Created;
                response.Content    = new StringContent(JsonConvert.SerializeObject(openResp));
            }
            else
            {
                response.StatusCode = HttpStatusCode.InternalServerError;
            }

            return(response);
        }
Пример #2
0
        public IActionResult OpenSession(int id)
        {
            Session newSession = new Session()
            {
                UserId    = id,
                OpenedDt  = DateTime.Now,
                ExpiresDt = DateTime.Now + TimeSpan.FromHours(1)
            };
            string newSessionId = sessionContext.RegisterSession(newSession);

            IActionResult response = null;

            if (!string.IsNullOrEmpty(newSessionId))
            {
                OpenSessionResponse openResp = new OpenSessionResponse()
                {
                    SessionId = newSessionId
                };

                logger.LogInformation($"Session opened OK: {newSessionId}");

                response = Created("api/v1/session/" + newSessionId, JsonConvert.SerializeObject(openResp));
            }
            else
            {
                logger.LogWarning($"Session opened failed (sessionContext.RegisterSession): {newSessionId}");
                response = StatusCode((int)HttpStatusCode.InternalServerError);
            }

            return(response);
        }
Пример #3
0
        string openSession(int userId)
        {
            string sessionId = null;

            HttpClient         client = new HttpClient();
            HttpRequestMessage msg    = new HttpRequestMessage(HttpMethod.Get,
                                                               String.Format(ConfigurationManager.AppSettings["SessionApi"],
                                                                             String.Format("session/{0}/open", userId)
                                                                             ));

            HttpResponseMessage resp            = client.SendAsync(msg).Result;
            OpenSessionResponse openSessionResp = JsonConvert.DeserializeObject <OpenSessionResponse>(resp.Content.ReadAsStringAsync().Result);

            sessionId = openSessionResp.SessionId;

            return(sessionId);
        }