Ejemplo n.º 1
0
 private void OnSessionClosed(GameSession session, ClientCloseReason reason)
 {
     SessionClosed?.Invoke(this, new SessionCloseEventArgs()
     {
         GameSession = session, Reason = reason
     });
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Handles session termination.
 /// </summary>
 /// <param name="sender">Local session.</param>
 /// <param name="e">Formal junk.</param>
 private void Session_End(object sender, EventArgs e)
 {
     foreach (var remote in (sender as ActiveSession <T>).Remotes)
     {
         remote.Close();
     }
     SessionClosed?.Invoke(sender, EventArgs.Empty);
 }
Ejemplo n.º 3
0
 private void OnSessionClosed(Session session)
 {
     for (int i = 0; i < Sessions.Count; i++)
     {
         if (Sessions[i].GetName().ToString().Equals(session.GetName().ToString()))
         {
             SessionClosed.RaiseEvent(Sessions[i]);
             Sessions.Remove(Sessions[i]);
         }
     }
 }
Ejemplo n.º 4
0
 private void RaiseSessionClosedEvent(SessionCloseReason reason, Exception ex)
 {
     if (SessionClosed == null)
     {
         return;
     }
     foreach (EventHandler <TcpIpSessionClosedEventArgs> del in SessionClosed.GetInvocationList())
     {
         SessionClosed.BeginInvoke(this, new TcpIpSessionClosedEventArgs(reason, ex),
                                   AsyncCallBackRaiseSessionClosedEvent, del);
     }
 }
Ejemplo n.º 5
0
 public void CloseSession(string sessionID)
 {
     lock (_lockObj)
     {
         var sessionToRemove = _sessions.FirstOrDefault(s => s.SessionID == sessionID);
         if (sessionToRemove != null)
         {
             _sessions.Remove(sessionToRemove);
             SessionClosed?.Invoke(sessionToRemove);
         }
     }
 }
Ejemplo n.º 6
0
        private void RaiseSessionClosedEvent(SmppSessionCloseReason reason, Exception exception)
        {
            if (SessionClosed == null)
            {
                return;
            }
            SmppSessionClosedEventArgs e = new SmppSessionClosedEventArgs(reason, exception);

            foreach (EventHandler <SmppSessionClosedEventArgs> del in SessionClosed.GetInvocationList())
            {
                del.BeginInvoke(this, e, AsyncCallBackRaiseSessionClosedEvent, del);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 连接已关闭
        /// </summary>
        private void ChannelInactive(IChannelHandlerContext context)
        {
            /*连接数-1*/
            Interlocked.Decrement(ref connectionCount);
            var channelId = context.Channel.Id.AsShortText();

            if (allSession.TryRemove(channelId, out var session))
            {
                session.OnClosed();
                SessionClosed?.Invoke(this, session);
                OnSessionClosed(session);
            }
        }
Ejemplo n.º 8
0
        public bool TryCreateSession(string sessionId, out Session session)
        {
            if (String.IsNullOrWhiteSpace(sessionId))
            {
                sessionId = Guid.NewGuid().ToString();
            }

            SessionCreating?.Invoke(this, new SessionArgs(null));
            Cookie cookie;

            if ((cookie = _context.Request.Cookies[COOKIE_SESSION_ID]) != null)
            {
                if (_sessionDictionary.TryGetValue(cookie.Value, out session))
                {
                    SessionCreated?.Invoke(this, new SessionArgs(session, true));
                    return(true);
                }
                else
                {
                    session = new Session(sessionId, ExpireTime);
                    if (_sessionDictionary.TryAdd(session.Id, session))
                    {
                        //_context.Session = session;
                        SessionCreated?.Invoke(this, new SessionArgs(session, true));
                        return(true);
                    }
                    else
                    {
                        SessionClosed?.Invoke(this, new SessionArgs(session, false));
                        return(false);
                    }
                }
            }

            session = new Session(sessionId, ExpireTime);

            _context.Response.Cookies.Add(new Cookie(COOKIE_SESSION_ID, session.Id)
            {
                Expires = session.ExpireTime,
                Path    = "/"
            });
            if (_sessionDictionary.TryAdd(session.Id, session))
            {
                //_context.Session = session;
                SessionCreated?.Invoke(this, new SessionArgs(session, true));
                return(true);
            }

            SessionClosed?.Invoke(this, new SessionArgs(session, false));
            return(false);
        }
Ejemplo n.º 9
0
        private void RaiseSessionClosedEvent(SessionCloseReason reason, Exception ex)
        {
            if (SessionClosed == null)
            {
                return;
            }
            foreach (EventHandler <TcpIpSessionClosedEventArgs> del in SessionClosed.GetInvocationList())
            {
#if NET40
                SessionClosed.BeginInvoke(this, new TcpIpSessionClosedEventArgs(reason, ex),
                                          AsyncCallBackRaiseSessionClosedEvent, del);
#else
                System.Threading.Tasks.Task.Run(() => SessionClosed.Invoke(this, new TcpIpSessionClosedEventArgs(reason, ex)));
#endif
            }
        }
Ejemplo n.º 10
0
        private void RaiseSessionClosedEvent(SmppSessionCloseReason reason, Exception exception)
        {
            if (SessionClosed == null)
            {
                return;
            }
            SmppSessionClosedEventArgs e = new SmppSessionClosedEventArgs(reason, exception);

            foreach (EventHandler <SmppSessionClosedEventArgs> del in SessionClosed.GetInvocationList())
            {
#if NET40
                del.BeginInvoke(this, e, AsyncCallBackRaiseSessionClosedEvent, del);
#else
                System.Threading.Tasks.Task.Run(() => del.Invoke(this, e));
#endif
            }
        }
Ejemplo n.º 11
0
 protected void CloseSession()
 {
     _executor = null;
     if (Session == null)
     {
         return;
     }
     try
     {
         SessionClosed?.Invoke(Session);
     }
     finally
     {
         Session.OnClosingSession();
         Session = NotConnectedSession.Default;
     }
 }
Ejemplo n.º 12
0
        public bool TryRemoveSession(Session session)
        {
            SessionCloseing?.Invoke(this, new SessionArgs(session));
            if (_sessionDictionary.TryRemove(session.Id, out var value))
            {
                _context.Response.Cookies.Remove(session.Id);
                session = null;

                //_context.Session = null;
                SessionClosed?.Invoke(this, new SessionArgs(value, true));
                return(true);
            }

            session = value;
            //_context.Session = value;
            SessionClosed?.Invoke(this, new SessionArgs(value, false));
            return(false);
        }
Ejemplo n.º 13
0
        public void Start()
        {
            var header = bh.RecieveHead();

            // bool tokenRecieved = false;
            while (header.type != 0 && header.type != BlockTypeConstants.ENDConnect)
            {
                switch (header.type)
                {
                case BlockTypeConstants.RegisterBlock:
                    RecieveRegister(header.size);
                    break;

                case BlockTypeConstants.AuthBlock:
                    RecieveAuth(header.size);
                    break;

                case BlockTypeConstants.RequestUserListBlock:
                    RecieveRequestUserList(header.size);
                    break;

                case BlockTypeConstants.RequestDialogueListBlock:
                    RecieveRequestDialogueList(header.size);
                    break;

                case BlockTypeConstants.DialogueCreateBlock:
                    RecieveDialogueCreate(header.size);
                    break;

                case BlockTypeConstants.RequestMsgList:
                    RecieveRequestMsgList(header.size);
                    break;

                case BlockTypeConstants.CSendMsgBlock:
                    RecieveMsg(header.size);
                    break;

                default:
                    return;
                }
                header = bh.RecieveHead();
            }
            SessionClosed.Invoke(SessionId);
        }
Ejemplo n.º 14
0
        private void RecieveRegister(int size)
        {
            var tBlock = bh.RecieveBlock(size, new RegisterBlock());

            try {
                profile = mh.CreateProfile(tBlock.Username, tBlock.Password);
                if (profile == null)
                {
                    client.Disconnect(false);
                    SessionClosed.Invoke(SessionId);
                }
                else
                {
                    SendProfile(profile);
                }
            } catch (Exception e) {
                SendError(e);
            }
        }
Ejemplo n.º 15
0
 private void Elapsed(object state)
 {
     lock (_lockObj)
     {
         var now = DateTime.Now;
         foreach (var session in _sessions.ToList())
         {
             if (session.LastRefreshed + _sessionLifetime < now)
             {
                 SessionClosed?.Invoke(session);
                 _sessions.Remove(session);
             }
             else
             {
                 session.LastRefreshed = now;
             }
         }
     }
 }
Ejemplo n.º 16
0
        public bool TryRemoveSession()
        {
            Cookie cookie;

            if ((cookie = _context.Response.Cookies[COOKIE_SESSION_ID]) == null)
            {
                return(false);
            }


            SessionCloseing?.Invoke(this, new SessionArgs(null));
            if (_sessionDictionary.TryRemove(cookie.Name, out var session))
            {
                _context.Response.Cookies.Remove(cookie.Name);
                //_context.Session = null;
                SessionClosed?.Invoke(this, new SessionArgs(session, true));
                return(true);
            }

            SessionClosed?.Invoke(this, new SessionArgs(session, false));
            return(false);
        }
Ejemplo n.º 17
0
        /*连接已关闭*/
        private void OnConnectionClose(TSession connection)
        {
            var e = connection.ReceiveSAE;

            if (e == null)
            {
                return;
            }
            e.AcceptSocket = null;
            e.UserToken    = null;
            receiveAsyncEventQueue.Enqueue(e);

            try
            {
                connection.Socket.Shutdown(SocketShutdown.Both);
                connection.Socket.Close();
            }
            catch (Exception) { }

            Interlocked.Decrement(ref connectionCount);
            connection.SetClose();
            SessionClosed?.Invoke(this, connection);
            OnSessionClosed(connection);
        }
        public override void OnSessionClosed(Session session)
        {
            LogWriteLine("********* SESSION " + session.GetName().GetString() + " CLOSED ******");

            SessionClosed?.Invoke(session);
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Handles session termination.
 /// </summary>
 /// <param name="sender">Local session.</param>
 /// <param name="e">Formal junk.</param>
 private void Session_End(object sender, EventArgs e)
 {
     (sender as ActiveSession <T>).Remotes[0].Close();
     SessionClosed?.Invoke(sender, EventArgs.Empty);
 }
Ejemplo n.º 20
0
 protected virtual void RaiseSessionClosed(WampSessionCloseEventArgs e)
 {
     SessionClosed?.Invoke(this, e);
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Called internally when no references are left to the project editing session
 /// </summary>
 internal void SessionTerminated()
 {
     CloseAllModelSystemEditingSessions();
     SessionClosed?.Invoke(this, new EventArgs());
 }
Ejemplo n.º 22
0
 protected virtual void OnSessionClosed(T serverSession)
 {
     SessionClosed?.Invoke(serverSession, new EventArgs());
 }
Ejemplo n.º 23
0
 protected void RaiseClosed(Session session)
 {
     SessionClosed?.Invoke(session);
 }
 /// <summary>
 /// Added to provide derived classes with the ability to send event notifications.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="eventArgs"></param>
 protected internal void SafeInvokeSessionClosed(Object sender, EventArgs eventArgs)
 {
     SessionClosed.SafeInvoke(sender, eventArgs);
 }
Ejemplo n.º 25
0
 protected virtual void OnSessionClosed(Guid e)
 {
     SessionClosed?.BeginInvoke(this, e, EndInvokeGuid, SessionClosed);
 }
 public static void InvokeSessionClosed(object sender, MushraTestDetailsModel e)
 {
     SessionClosed?.Invoke(sender, e);
     _sessionCreatedFlag = false;
 }
 private void OnSessionClosed(Session session)
 {
     SessionClosed.RaiseEvent(session);
     Sessions.Remove(session);
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Raise the <see cref="SessionClosed"/> event.
 /// </summary>
 /// <param name="session">The closed session.</param>
 protected void InvokeSessionClosed(IEtpSession session)
 {
     SessionClosed?.Invoke(this, session);
 }
 /// <summary>
 ///     This gets called after a session has been terminated by either
 ///     the modeller controller or the project session.
 /// </summary>
 internal void SessionTerminated()
 {
     SessionClosed?.Invoke(this, new EventArgs());
 }
Ejemplo n.º 30
0
 /// <summary>
 /// 会话关闭后调用
 /// </summary>
 internal protected virtual void OnClosed(CloseReason closedReason)
 {
     SessionClosed?.Invoke(closedReason);
 }