public object Any(GetSessionInfo request) { var response = Global.RequestsProcessor.Any(request); TransferHeader(request, response); return(response); }
public void GetSessionInfo_Success(string name) { RunInitSql(name, "ConnectionStringAccounts"); // 1. initializing the session InitSession request = new InitSession() { AccountKey = ConfigurationManager.AppSettings["AccountKey"], RequestID = "D3770630-9532-457D-8EBB-DBF99F6A23D3", SessionToken = null }; InitSessionResponse response = Post <InitSession, InitSessionResponse>("InitSession", request); string sessionToken = response.SessionToken; // 2. getting session information GetSessionInfo getSesionInfo = PrepareRequest <GetSessionInfo>(name); getSesionInfo.SessionToken = sessionToken; GetSessionInfoResponse sessionInfo = Post <GetSessionInfo, GetSessionInfoResponse>("GetSessionInfo", getSesionInfo); RunFinalizeSql(name, "ConnectionStringAccounts"); Assert.AreEqual(sessionInfo.Success, true, "Session was not found"); Assert.AreNotEqual(sessionInfo.Payload.SessionStart, DateTime.MinValue, "SessionStart time was not provided"); Assert.IsEmpty(sessionInfo.Errors, "Errors are not empty"); }
private EErrorCodes ValidateSession(string sessionToken) { EErrorCodes result = EErrorCodes.InvalidSession; if (sessionToken == ConfigurationManager.AppSettings["ServiceSessionToken"]) { result = EErrorCodes.Success; } else { eventRespReceived = new AutoResetEvent(false); // this event will be raised when response received sinfo = new GetSessionInfo(); sinfo.SessionToken = sessionToken; sinfo.CheckActive = true; int waitTimeout = Int32.Parse(ConfigurationManager.AppSettings["MQWaitTimeout"]); // sending message to queue string payload = JsonSerializer.SerializeToString(sinfo); string type = "GetSessionInfo"; Global.MQClient.NewChannelMessages += NewMessagesHandlerSender; Global.MQClient.Push(Global.AccountsChannel, type, payload); _logger.Log(EErrorType.Info, string.Format("GetSessionInfo: {0}", sinfo.RequestID)); // receiving message eventRespReceived.WaitOne(waitTimeout); Global.MQClient.NewChannelMessages -= NewMessagesHandlerSender; if (sinfoResponse != null) { if (!sinfoResponse.Success) { _logger.Log(EErrorType.Warning, string.Format("sinfoResponse error: {0}, {1}", sinfo.RequestID, sinfoResponse.Errors[0].Code)); } result = sinfoResponse.Success ? EErrorCodes.Success : sinfoResponse.Errors[0].Code; } else { _logger.Log(EErrorType.Warning, string.Format("MQCommunicationError: {0}", sinfo.RequestID)); result = EErrorCodes.MQCommunicationError; } } return(result); }
public void Connect() { var api = new IceWarpRpcApi(); var authResult = Authenticate(api); var sessionInfo = new GetSessionInfo { SessionId = authResult.SessionId }; var sessionInfoResult = api.Execute(_url, sessionInfo); Assert.NotNull(sessionInfoResult); Assert.NotNull(sessionInfoResult.HttpRequestResult); Assert.True(sessionInfoResult.HttpRequestResult.Success); LogOut(api, authResult.SessionId); }
public void GetSessionInfo_InvalidSession(string name) { RunInitSql(name, "ConnectionStringAccounts"); GetSessionInfo getSesionInfo = PrepareRequest <GetSessionInfo>(name); getSesionInfo.SessionToken = ConfigurationManager.AppSettings["InvalidSessionToken"]; GetSessionInfoResponse sessionInfo = Post <GetSessionInfo, GetSessionInfoResponse>("GetSessionInfo", getSesionInfo); RunFinalizeSql(name, "ConnectionStringAccounts"); Assert.AreEqual(sessionInfo.Success, false, "Session with invalid token was unpetedly found"); Assert.IsNotEmpty(sessionInfo.Errors, "Errors are empty"); Assert.AreEqual(sessionInfo.Errors[0].Code, EErrorCodes.InvalidSession, "Wrong error code returned"); }
public void GetSessionInfo_Closed(string name) { RunInitSql(name, "ConnectionStringAccounts"); // 1. initializing the session InitSession initReq = new InitSession() { AccountKey = ConfigurationManager.AppSettings["AccountKey"], RequestID = "D3770630-9532-457D-8EBB-DBF99F6A23D3", SessionToken = null }; InitSessionResponse initResp = Post <InitSession, InitSessionResponse>("InitSession", initReq); string sessionToken = initResp.SessionToken; // 2. closing session CloseSession closeReq = new CloseSession() { SessionToken = sessionToken }; CloseSessionResponse closeRes = Post <CloseSession, CloseSessionResponse>("CloseSession", closeReq); // 3. getting session information GetSessionInfo getSesionInfo = PrepareRequest <GetSessionInfo>(name); getSesionInfo.SessionToken = sessionToken; GetSessionInfoResponse sessionInfo = Post <GetSessionInfo, GetSessionInfoResponse>("GetSessionInfo", getSesionInfo); RunFinalizeSql(name, "ConnectionStringAccounts"); Assert.AreEqual(sessionInfo.Success, true, "Session was not found"); Assert.AreNotEqual(sessionInfo.Payload.SessionStart, DateTime.MinValue, "SessionStart time was not provided"); Assert.AreNotEqual(sessionInfo.Payload.SessionEnd, DateTime.MinValue, "SessionEnd time was not provided"); Assert.IsNotEmpty(sessionInfo.Errors, "Errors are empty"); Assert.AreEqual(sessionInfo.Errors[0].Type, EErrorType.Warning, "Warning of closed session is expected"); Assert.AreEqual(sessionInfo.Errors[0].Code, EErrorCodes.SessionClosed, "Invalid code returned"); }
public object Get(GetSessionInfo request) { List <Dictionary <string, object> > report = new List <Dictionary <string, object> >(); AuthorizationInfo user_info = _ac.GetAuthorizationInfo(Request); UserPolicy policy = _userManager.GetUserPolicy(user_info.User); if (!policy.IsAdministrator) { return(report); } foreach (SessionInfo session in _sessionManager.Sessions) { Dictionary <string, object> data = new Dictionary <string, object>(); data.Add("TranscodingInfo", session.TranscodingInfo); data.Add("PlayState", session.PlayState); data.Add("NowPlayingItem", session.NowPlayingItem); data.Add("device_name", session.DeviceName); data.Add("client_name", session.Client); data.Add("app_icon", session.AppIconUrl); data.Add("app_version", session.ApplicationVersion); data.Add("has_user", session.HasUser); data.Add("user_id", session.UserId); data.Add("user_name", session.UserName); data.Add("has_image", session.UserPrimaryImageTag); data.Add("remote_address", session.RemoteEndPoint); TimeSpan ts = DateTime.UtcNow.Subtract(session.LastActivityDate.DateTime); data.Add("last_active", ts.ToString(@"dd\.hh\:mm\:ss")); report.Add(data); } return(report); }
private EErrorCodes ValidateSession(string sessionToken) { EErrorCodes result = EErrorCodes.InvalidSession; if (sessionToken == ConfigurationManager.AppSettings["ServiceSessionToken"]) { result = EErrorCodes.Success; } else { GetSessionInfo sinfo = new GetSessionInfo(); sinfo.SessionToken = sessionToken; sinfo.CheckActive = true; DMFX.Client.Accounts.ServiceClient accnts = new Client.Accounts.ServiceClient(); GetSessionInfoResponse sInfoResp = accnts.PostGetSessionInfo(sinfo); result = sInfoResp.Success ? EErrorCodes.Success : sInfoResp.Errors[0].Code; } return(result); }
public void GetSessionInfo() { string expected = File.ReadAllText(Path.Combine(_requestsTestDataPath, "GetSessionInfo.xml")); var request = new GetSessionInfo() { SessionId = "sid" }; var xml = request.ToXml().InnerXmlFormatted(); Assert.AreEqual(expected, xml); XmlDocument doc = new XmlDocument(); doc.LoadXml(File.ReadAllText(Path.Combine(_responsesTestDataPath, "GetSessionInfo.xml"))); var response = request.FromHttpRequestResult(new HttpRequestResult { Response = doc.InnerXml }); Assert.AreEqual("result", response.Type); Assert.AreEqual("*****@*****.**", response.Email); Assert.AreEqual("testing.co.uk", response.Domain); Assert.AreEqual(TAdminType.DomainAdmin, response.AdminType); }
public GetSessionInfoResponse PostGetSessionInfo(GetSessionInfo request) { var response = Post <GetSessionInfo, GetSessionInfoResponse>("GetSessionInfo", request); return(response); }
public ResponseBase Any(GetSessionInfo request) { _logger.Log(EErrorType.Info, " ****** Call start: GetSessionInfo"); GetSessionInfoResponse response = new GetSessionInfoResponse(); try { Interfaces.DAL.SessionInfo sinfo = new Interfaces.DAL.SessionInfo(); sinfo.SessionId = !string.IsNullOrEmpty(request.SessionToken) ? request.SessionToken : string.Empty; _logger.Log(EErrorType.Info, string.Format("_dal.GetSessionInfo({0}, {1})", sinfo.SessionId, request.CheckActive)); sinfo = _dal.GetSessionInfo(sinfo, request.CheckActive); if (sinfo != null) { response.Payload.SessionStart = sinfo.SessionStart; response.Payload.SessionEnd = sinfo.SessionEnd; if (!request.CheckActive) { // checking all sessions - just returning the warning that this session was closed if (response.Payload.SessionEnd > DateTime.MinValue) { response.Errors.Add(new Error() { Code = EErrorCodes.SessionClosed, Message = "Session with given token was closed", Type = EErrorType.Warning }); } response.Success = true; } else { // checking for active session! // if expiration date >= now - closing the session and returning error; in other case returning true _logger.Log(EErrorType.Info, string.Format("Expires: {0}, Now: {1}", sinfo.SessionExpires, DateTime.UtcNow)); if (sinfo.SessionExpires <= DateTime.UtcNow) { _logger.Log(EErrorType.Info, string.Format("Closing session {0}", sinfo.SessionId)); sinfo.SessionEnd = DateTime.UtcNow; _dal.CloseSession(sinfo); response.Errors.Add(new Error() { Code = EErrorCodes.SessionClosed, Message = "Session with given token expired and was closed", Type = EErrorType.Error }); response.Success = false; } else { response.Success = true; } } } else { response.Errors.Add(new Error() { Code = EErrorCodes.InvalidSession, Message = "Invalid session token", Type = EErrorType.Error }); } } catch (Exception ex) { _logger.Log(ex); response.Success = false; response.Errors.Add(new Error() { Code = EErrorCodes.GeneralError, Type = EErrorType.Error, Message = string.Format("Unexpected error: {0}", ex.Message) }); } _logger.Log(EErrorType.Info, " ****** Call end: GetSessionInfo"); return(response); }