Esempio n. 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();
            }
        }
Esempio n. 2
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 = ""
                });
            }
        }