예제 #1
0
        public ActionResult LoginFromConsole( )
        {
            var model = DecodeAuthorizationHeaders(Request);

            try
            {
                var result = LoginValidator.Validate(model);
                if (result.IsValid)
                {
                    Response.StatusCode = (int)HttpStatusCode.OK;
                    ActiveSessions.MarkSessionAsAuthenticated(Session.SessionID, model.Email);
                    return(new ContentResult()
                    {
                        Content = Session.SessionID
                    });
                }

                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(new ContentResult()
                {
                    Content = result.Errors.ToArray().Select(e => e.ErrorMessage).ToString()
                });
            }
            catch (Exception ex)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(new ContentResult()
                {
                    Content = ex.Message
                });
            }
        }
예제 #2
0
        public override async Task OnDisconnectedAsync(Exception exception)
        {
            string userName     = Context.User.Identity.Name;
            string connectionId = Context.ConnectionId;

            ActiveConnections.ActiveUsers.Remove(userName);
            ActiveConnections.ActiveSessions.Remove(Context.ConnectionId);

            ActiveSessions activeSessions = new ActiveSessions();

            activeSessions = ActiveConnections.ActiveSessionsList.Where(x => x.ConnectionId == Context.ConnectionId).FirstOrDefault();
            ActiveConnections.ActiveSessionsList.Remove(activeSessions);

            if (!ActiveConnections.ActiveSessionsList.Any(w => w.UserId == activeSessions.UserId) &&
                activeSessions.UserId > 0)
            {
                IpPropertiesModal ipAddressDetails = new IpPropertiesModal();
                ipAddressDetails.UserId                = activeSessions.UserId;
                ipAddressDetails.IpAddress             = activeSessions.IpAddress;
                ipAddressDetails.SessionDisconnectedOn = DateTime.Now;
                ipAddressDetails.CookieUniqueId        = activeSessions.CookieUniqueId;
                _IAppAnalyticsService.UpdatedUserDisConnectionTracking(ipAddressDetails);
            }

            await Groups.RemoveFromGroupAsync(Context.ConnectionId, "SignalR Users");

            await base.OnDisconnectedAsync(exception);
        }
예제 #3
0
        void Session_Closed(object sender, EventArgs e)
        {
            var routedSession = (RoutedSession)sender;

            Debug.WriteLine("Socket session ended: " + routedSession.ClientEndPoint.ToString() + "<--XX-->" + routedSession.Route.ToString());
            ActiveSessions.Remove(routedSession);
        }
예제 #4
0
 public void CloseSession(Session session)
 {
     ActiveSessions.Remove(session);
     session.EndTime  = Clock.Time();
     session.TripTime = session.EndTime - session.StartTime;
     ClosedSessions.Add(session);
 }
예제 #5
0
        public static Session GetOrCreateSession(TSPlayer player)
        {
            if (!ActiveSessions.TryGetValue(player.Name, out var playerSession))
            {
                //session is not active, try to get it from the db
                playerSession = SessionRepository.Load(player.Name);

                if (playerSession == null)
                {
                    //otherwise, create new
                    playerSession = new Session(player);
                }
                else
                {
                    //update all trigger words
                    foreach (var skillName in playerSession.PlayerSkillInfos.Keys)
                    {
                        playerSession.UpdateTriggerWords(skillName);
                    }

                    //have to re-add these
                    playerSession.Player     = player;
                    playerSession.PlayerName = player.Name;
                }

                ActiveSessions.TryAdd(player.Name, playerSession);
            }

            return(playerSession);
        }
예제 #6
0
 public virtual void RemoveSession(UserActiveSessionModel mdl)
 {
     ActiveSessions.Remove(mdl);
     if (DBContext != null)
     {
         DBContext.Sessions.Remove(mdl);
     }
 }
예제 #7
0
 private void OnSessionInactivated(Session session)
 {
     lock (this)
     {
         ActiveSessions.Remove(session);
         InactiveSessions.Add(session);
     }
 }
예제 #8
0
 private void SessionInactivated(Session session)
 {
     lock (Channels)
     {
         ActiveSessions.Remove(session);
         InactiveSessions.Add(session);
     }
 }
        public ISession GetOrCreateSession <TSessionContext>(Type type = null) where TSessionContext : ISessionContext
        {
            // var context = Ioc.Create(typeof(TSessionContext));
            var             _context       = Ioc.Create <ISessionContext>(typeof(TSessionContext));
            ISessionFactory sessionFactory = _sessionFactoryProvider.GetSessionFactory(_context.Name);

            string sessionKey       = _context.Name + "#";
            string connectionString = _context.GetConnectionString();

            if (!ActiveSessions.TryGetValue(sessionKey, out ISession session))
            {
                if (Options.IsTransactional == true)
                {
                    ActiveTransactionInfo activeTransactionInfo = ActiveTransactions.GetOrDefault(connectionString);
                    if (activeTransactionInfo == null)
                    {
                        session = DbConnection != null
                            ? sessionFactory.WithOptions().Connection(DbConnection).OpenSession()
                            : sessionFactory.OpenSession();

                        ITransaction transaction = Options.IsolationLevel.HasValue
                            ? session.BeginTransaction(Options.IsolationLevel.Value.ToSystemDataIsolationLevel())
                            : session.BeginTransaction();

                        activeTransactionInfo = new ActiveTransactionInfo(transaction, session.Connection, session);
                        ActiveTransactions[connectionString] = activeTransactionInfo;
                    }
                    else
                    {
                        session = activeTransactionInfo.StarterSession;
                        activeTransactionInfo.AttendedSessions.Add(session);
                    }
                }
                else
                {
                    session = DbConnection != null
                        ? sessionFactory.OpenSessionWithConnection(DbConnection)
                        : sessionFactory.OpenSession();
                }

                ActiveSessions[sessionKey] = session;
            }

            var filters = _context.Filters().ToList();

            foreach (var filter in filters)
            {
                var name       = filter.Name();
                var parameters = filter.Parameters();
                var _filter    = session.EnableFilter(name);
                foreach (var parameter in parameters)
                {
                    _filter.SetParameter(parameter.Key, parameter.Value);
                }
            }
            return(session);
        }
예제 #10
0
 public virtual void AddSession(UserActiveSessionModel mdl)
 {
     mdl.Owner = this;
     ActiveSessions.Add(mdl);
     if (DBContext != null)
     {
         DBContext.Sessions.Add(mdl);
     }
 }
예제 #11
0
        public override Task OnDisconnected(bool stopCalled)
        {
            string userName     = Context.User.Identity.Name;
            string connectionId = Context.ConnectionId;

            UserHubModels user;

            Users.TryGetValue(userName, out user);

            if (user != null)
            {
                lock (user.ConnectionIds)
                {
                    user.ConnectionIds.RemoveWhere(cid => cid.Equals(connectionId));
                    if (!user.ConnectionIds.Any())
                    {
                        UserHubModels removedUser;
                        Users.TryRemove(userName, out removedUser);
                        Clients.Others.userDisconnected(userName);
                    }
                }
            }

            ActiveConnections.ActiveUsers.Remove(userName);
            ActiveConnections.ActiveSessions.Remove(Context.ConnectionId);


            AuditModel objaudit          = new AuditModel();
            var        currentBrowserUrl = Context.QueryString["currentBrowserUrl"];

            if (userName != null && userName != "")
            {
                objaudit.UserId = Convert.ToInt64(userName);
            }

            objaudit.SessionID = Context.ConnectionId;

            ActiveSessions activeSessions = new ActiveSessions();

            activeSessions = ActiveConnections.ActiveSessionsList.Where(x => x.ConnectionId == Context.ConnectionId).FirstOrDefault();

            if (activeSessions != null)
            {
                objaudit.ConnectedOn = activeSessions.ConnectedOn;
                objaudit.IPAddress   = activeSessions.IpAddress;
            }

            objaudit.PageAccessed = currentBrowserUrl;

            objaudit.DisconnectedOn = DateTime.Now;

            this._IAuditOrchestrator.SaveMVCAuditTrail(objaudit);


            return(base.OnDisconnected(stopCalled));
        }
        public string GenerateRandomSessionCode()
        {
            string sessionCode;

            do
            {
                sessionCode = GenerateRandomString("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 6);
            } while (ActiveSessions.ContainsKey(sessionCode));
            return(sessionCode.ToUpper());
        }
예제 #13
0
        public void Close()
        {
            lock (Channels)
            {
                Acceptor.Close();

                //  session.Close 에서 ActiveSessions가 변경되므로 복사본을 사용
                foreach (var session in ActiveSessions.ToList())
                {
                    session.Close(AegisResult.Ok);
                }
            }
        }
예제 #14
0
        /// <summary>
        /// 네트워크 작업을 종료하고 사용중인 리소스를 반환합니다.
        /// Acceptor와 활성화된 Session의 네트워크 작업이 중단됩니다.
        /// </summary>
        public void StopNetwork()
        {
            Acceptor.Close();


            List <Session> targets;

            lock (this)
            {
                targets = ActiveSessions.Concat(InactiveSessions).ToList();
            }
            targets.ForEach(v => v.Close());
        }
예제 #15
0
 public ActionResult ConsoleSignOut()
 {
     try
     {
         ActiveSessions.RemoveSession(Session.SessionID);
         Session.Abandon();
         return(new HttpStatusCodeResult(HttpStatusCode.OK));
     }
     catch
     {
         //todo: add logging
         return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
     }
 }
        public GameSession CreateNewSession()
        {
            GameSession session;

            lock (SessionCreationLock)
            {
                session = new GameSession
                {
                    ConnectedPlayers = new HashSet <Player>(),
                    SessionCode      = GenerateRandomSessionCode()
                };
                ActiveSessions.Add(session.SessionCode, session);
            }
            return(session);
        }
예제 #17
0
        public ISession GetOrCreateSession <TSessionContext>() where TSessionContext : StoveSessionContext
        {
            ISessionFactory sessionFactory = _sessionFactoryProvider.GetSessionFactory <TSessionContext>();
            var             connectionStringResolveArgs = new ConnectionStringResolveArgs();

            connectionStringResolveArgs["SessionContextType"] = typeof(TSessionContext);
            string connectionString = ResolveConnectionString(connectionStringResolveArgs);

            string sessionKey = typeof(TSessionContext).FullName + "#" + connectionString;

            if (!ActiveSessions.TryGetValue(sessionKey, out ISession session))
            {
                if (Options.IsTransactional == true)
                {
                    ActiveTransactionInfo activeTransactionInfo = ActiveTransactions.GetOrDefault(connectionString);
                    if (activeTransactionInfo == null)
                    {
                        session = DbConnection != null
                            ? sessionFactory.WithOptions().Connection(DbConnection).OpenSession()
                            : sessionFactory.OpenSession();

                        ITransaction transaction = Options.IsolationLevel.HasValue
                            ? session.BeginTransaction(Options.IsolationLevel.Value.ToSystemDataIsolationLevel())
                            : session.BeginTransaction();

                        activeTransactionInfo = new ActiveTransactionInfo(transaction, session.Connection, session);
                        ActiveTransactions[connectionString] = activeTransactionInfo;
                    }
                    else
                    {
                        session = activeTransactionInfo.StarterSession;

                        activeTransactionInfo.AttendedSessions.Add(session);
                    }
                }
                else
                {
                    session = DbConnection != null
                        ? sessionFactory.OpenSessionWithConnection(DbConnection)
                        : sessionFactory.OpenSession();
                }

                ActiveSessions[sessionKey] = session;
            }

            return(session);
        }
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            var incomingSessionToken = filterContext.HttpContext.Request.Params["SessionId"];
            var incomingEmail        = filterContext.HttpContext.Request.Params["UserId"];

            if (incomingSessionToken == null || incomingEmail == null)
            {
                filterContext.Result = new HttpStatusCodeResult(HttpStatusCode.Forbidden);
                return;
            }

            var validParams = ActiveSessions.SessionIsAuthenticated(incomingSessionToken, incomingEmail);

            if (!validParams)
            {
                filterContext.Result = new HttpStatusCodeResult(HttpStatusCode.Forbidden);
            }
        }
예제 #19
0
        /// <summary>
        ///     Rollbacks transaction and closes database connection.
        /// </summary>
        protected override void DisposeUow()
        {
            foreach (ActiveTransactionInfo activeTransaction in ActiveTransactions.Values)
            {
                foreach (ISession session in activeTransaction.AttendedSessions)
                {
                    session.Dispose();
                }

                activeTransaction.Transaction.Dispose();
                activeTransaction.StarterSession.Dispose();
            }

            foreach (ISession activeSession in ActiveSessions.Values)
            {
                activeSession.Dispose();
            }

            ActiveSessions.Clear();
            ActiveTransactions.Clear();
        }
예제 #20
0
 private void StopListeningToRoute(Route route)
 {
     Debug.Write("Stopping route listener: ");
     Debug.Write(route.ToString());
     Debug.Write(" ... ");
     foreach (var listenerkvp in TcpListeners)
     {
         var listener = listenerkvp.Value;
         try { listener.Stop(); }
         catch { }
     }
     if (ActiveSessions != null)
     {
         var sessionsToDispose = new List <RoutedSession>(ActiveSessions);
         foreach (IDisposable session in sessionsToDispose)
         {
             session.Dispose();
         }
         ActiveSessions.Clear();
     }
 }
예제 #21
0
        public async void LoadSession(int code)
        {
            if (_context == null)
            {
                ActiveSessions active = ActiveSessions.Instance;
                if (active.Sessions.TryGetValue(code, out AdminInstance admin1))
                {
                    HttpContext.Response.StatusCode = 200;
                    return; //Session already active?
                }
                else
                {
                    HttpContext.Response.StatusCode = 404;
                    return; //Session doesn't exist!
                }
            }

            if (_context.Active.Sessions.TryGetValue(code, out AdminInstance admin))
            {
                HttpContext.Response.StatusCode = 200;
                return; //Session already active?
            }
            else
            {
                Session session = await _context.Sessions.FindAsync(code);

                if (session == null)
                {
                    HttpContext.Response.StatusCode = 404;
                    return; //Session doesn't exist!
                }

                AdminInstance model = new AdminInstance();
                model.LoadSession(session.Questions);

                _context.Active.Sessions.Add(code, model);
                HttpContext.Response.StatusCode = 201;
                return; //Loaded from database
            }
        }
예제 #22
0
        private void TcpListener_AcceptSocket(IAsyncResult ar)
        {
            // Get the listener that handles the client request.
            var listenerkvp = (KeyValuePair <string, TcpListener>)ar.AsyncState;
            var name        = listenerkvp.Key;
            var listener    = listenerkvp.Value;
            var route       = Routes[listenerkvp.Key];

            try
            {
                // Start the session
                var session = RoutedSession.BeginSession(route, listener.EndAcceptSocket(ar));
                session.Closed += new EventHandler(Session_Closed);
                ActiveSessions.Add(session);
            }
            catch { } // skip the session, it failed

            // continue listening
            var stateObj2 = new KeyValuePair <string, TcpListener>(route.Name, listener);

            listener.BeginAcceptSocket(new AsyncCallback(TcpListener_AcceptSocket), stateObj2);
        }
예제 #23
0
 protected virtual IReadOnlyList <ISession> GetAllActiveSessions()
 {
     return(ActiveSessions.Select(x => x.Value).ToList());
 }
예제 #24
0
 protected void Session_End(object sender, EventArgs e)
 {
     ActiveSessions.RemoveSession(Session.SessionID);
 }
 public GameSession FindSessionByCode(string sessionCode)
 {
     return(ActiveSessions.GetValueOrDefault(sessionCode));
 }