コード例 #1
0
ファイル: HttpSession.cs プロジェクト: blockspacer/niveum
        public void Start()
        {
            IsRunningValue.Update
            (
                b =>
            {
                if (b)
                {
                    throw new InvalidOperationException();
                }
                return(true);
            }
            );

            try
            {
                Context.RemoteEndPoint = RemoteEndPoint;

                Server.ServerContext.RegisterSession(Context);
                Server.SessionMappings.DoAction(Mappings => Mappings.Add(Context, this));

                if (Server.ServerContext.EnableLogSystem)
                {
                    Server.ServerContext.RaiseSessionLog(new SessionLogEntry {
                        Token = Context.SessionTokenString, RemoteEndPoint = RemoteEndPoint, Time = DateTime.UtcNow, Type = "Sys", Name = "SessionEnter", Message = ""
                    });
                }
                ssm.Start();
            }
            catch (Exception ex)
            {
                OnCriticalError(ex, new StackTrace(true));
                ssm.NotifyFailure();
            }
        }
コード例 #2
0
ファイル: UdpSession.cs プロジェクト: blockspacer/niveum
 private void OnExit()
 {
     IsExitingValue.Update(b =>
     {
         if (!IsRunningValue.Check(bb => bb))
         {
             return(b);
         }
         if (!b)
         {
             Server.NotifySessionQuit(this);
         }
         return(true);
     });
 }
コード例 #3
0
ファイル: HttpSession.cs プロジェクト: blockspacer/niveum
        //线程安全
        private void OnExit()
        {
            bool Done = false;

            IsExitingValue.Update(b =>
            {
                if (!IsRunningValue.Check(bb => bb))
                {
                    Done = true;
                    return(b);
                }
                Done = b;
                return(true);
            });
            if (Done)
            {
                return;
            }

            Server.NotifySessionQuit(this);
        }
コード例 #4
0
ファイル: HttpSession.cs プロジェクト: blockspacer/niveum
        public void Dispose()
        {
            if (IsDisposed)
            {
                return;
            }
            IsDisposed = true;

            IsExitingValue.Update(b => true);
            ssm.NotifyExit();

            Server.SessionMappings.DoAction(Mappings =>
            {
                if (Mappings.ContainsKey(Context))
                {
                    Mappings.Remove(Context);
                }
            });
            Server.ServerContext.TryUnregisterSession(Context);

            si.Dispose();

            IsRunningValue.Update(b => false);

            SpinWait.SpinUntil(() => ssm.IsExited());

            Context.Dispose();

            IsExitingValue.Update(b => false);

            if (Server.ServerContext.EnableLogSystem)
            {
                Server.ServerContext.RaiseSessionLog(new SessionLogEntry {
                    Token = Context.SessionTokenString, RemoteEndPoint = RemoteEndPoint, Time = DateTime.UtcNow, Type = "Sys", Name = "SessionExit", Message = ""
                });
            }
        }