private async Task DoStartSessionAsync(TcpClient client) { var session = new SmsServerSession(this, this.MessageFactory); session.NetworkMessageReceived += OnSessionNetworkMessageReceived; session.SessionEnded += OnSessionEnded; await session.StartAsync(client); var sessions = this.Sessions; lock (sessions) { sessions.Add(session); } this.OnSessionStarted(session); }
private async Task DoStopSessionAsync(SmsServerSession session) { if (session != null) { bool found = false; var sessions = this.Sessions; lock (sessions) { if (sessions.Remove(session)) { session.NetworkMessageReceived -= OnSessionNetworkMessageReceived; session.SessionEnded -= OnSessionEnded; found = true; } } if (found) { await session.StopAsync(); } this.OnSessionStopped(session); } }
protected virtual async Task DoNetworkMessageReceived(SmsServerSession session, NetworkMessage message) { await Task.Delay(0); }
protected virtual void OnSessionStopped(SmsServerSession session) { }