Beispiel #1
0
        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();
            }
        }
Beispiel #2
0
 private void OnExit()
 {
     IsExitingValue.Update(b =>
     {
         if (!IsRunningValue.Check(bb => bb))
         {
             return(b);
         }
         if (!b)
         {
             Server.NotifySessionQuit(this);
         }
         return(true);
     });
 }
Beispiel #3
0
        //线程安全
        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);
        }
Beispiel #4
0
        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 = ""
                });
            }
        }