コード例 #1
0
        private void GetSessionInfo(LoveHateTrackStream stream)
        {
            Task
            .Factory
            .StartNew(state =>
            {
                var s = (LoveHateTrackStream)state;

                SessionInfoResponse response;
                if (s.TryGetSessionInfo(out response))
                {
                    SessionInfo = response;
                }
                else
                {
                    SessionInfo = null;
                }
            }, stream)
            .ContinueWith(task =>
            {
                if (task.Exception != null)
                {
                    Logger.Log(task.Exception.ToString(), Category.Exception, Priority.Medium);
                }
            });
        }
コード例 #2
0
        public JsonResult GetSessionInfo()
        {
            var response = new SessionInfoResponse();

            var userAgent = HttpContext.Request.Headers["User-Agent"].ToString();

            var userAgentModel = new UserAgent.UserAgent(userAgent);

            var sessionRequest = new SessionRequest()
            {
                Type    = 1,
                Browser = new Browser
                {
                    Name    = userAgentModel.Browser.Name,
                    Version = userAgentModel.Browser.Version
                },
                Connection = new Connection
                {
                    IpAddress = HttpContext.Connection.RemoteIpAddress.ToString(),
                    Port      = HttpContext.Connection.RemotePort
                }
            };

            var sessionInfo = _sessionManager.GetSessionInfo(sessionRequest);

            response.Success = sessionInfo.Status == ResponseStatus.Success;

            if (sessionInfo.Status == ResponseStatus.Success)
            {
                response.DeviceId  = sessionInfo.Data.DeviceId;
                response.SessionId = sessionInfo.Data.SessionId;
            }
            else if (sessionInfo.DisplayMessage)
            {
                response.Message = sessionInfo.Message;
            }

            return(Json(response));
        }
コード例 #3
0
        public bool TryGetSessionInfo(out SessionInfoResponse response)
        {
            if (string.IsNullOrEmpty(_sessionId))
            {
                response = null;
                return(false);
            }

            using (var session = new EchoNestSession(EchoNestModule.ApiKey))
            {
                response = session.Query <SessionInfo>().Execute(new SessionInfoArgument
                {
                    SessionId = _sessionId
                });

                if (response.Status.Code == ResponseCode.Success)
                {
                    return(true);
                }
            }

            return(false);
        }