private void SaveSessionToDatabase(SessionId sessionId, User user, ConnectionTicket ticket) { lock (_lockObj) { try { using (ServerDataContext context = new ServerDataContext()) { ActiveSession session = new ActiveSession { Id = ObjectId.NewId(), SessionId = sessionId.ToString(), UserId = user.Id, ClientComputer = ticket.ClientComputer, Port = ticket.Port }; context.ActiveSessions.Add(session); context.SaveChanges(); } } catch (Exception e) { ApplicationContext.Log.Error(GetType(), e); throw; } } }
public SessionId CreateSession(ConnectionTicket ticket) { ArgumentValidator.IsNotNull("ticket", ticket, "Ticket cannot be null!"); using (ClientProxy clientProxy = CreateClientProxy(ticket)) { try { SessionId sessionId = CreateSessionId(ticket); if (_sessions.ContainsKey(sessionId)) { return(sessionId); } string validationHash = clientProxy.ValidateConnection(Constants.ClientConnectionHash); if (string.Compare(validationHash, Constants.ClientValidResultHash) != 0) { throw new ClientNotValidException(GetType()); } User user; if (!CheckUser(ticket.Username, ticket.SecurityToken, out user)) { throw new UserIsNotValidException(GetType(), ticket.Username); } if (!_sessions.TryAdd(sessionId, new SessionData(sessionId, ticket))) { throw new CannotCreateSessionException(GetType()); } SaveSessionToDatabase(sessionId, user, ticket); InitCheckTimer(); Logger.Info("User {0} has been connected (session: {1}).", ticket.Username, sessionId); return(sessionId); } catch (CommunicationException e) { ApplicationContext.Log.Error(GetType(), e); } catch (ClientNotValidException e) { ApplicationContext.Log.Error(GetType(), e); throw; } catch (Exception e) { ApplicationContext.Log.Error(GetType(), e); } } return(null); }
public SessionId Connect(ConnectionTicket ticket) { LogRequest("Connect", ticket.ClientComputer); return(ServiceContext.SessionManager.CreateSession(ticket)); }
public SessionId Connect(ConnectionTicket ticket) { return(Channel.Connect(ticket)); }
public ClientServiceDescriptor(ConnectionTicket ticket) { _ticket = ticket; }
public SessionData(SessionId sessionId, ConnectionTicket ticket) { SessionId = sessionId; Ticket = ticket; Created = DateTime.Now; }
private ClientProxy CreateClientProxy(ConnectionTicket ticket) { return(new ClientProxy(new ClientServiceDescriptor(ticket))); }
private SessionId CreateSessionId(ConnectionTicket ticket) { return(new SessionId(string.Format("#ses#{0}#{1}#", ticket.ClientComputer, ticket.Username))); }