Exemplo n.º 1
0
        public void SetSession(ISession session)
        {
            _session              = session;
            session.MessageEvent += (message) =>
            {
                //Add new messages to the queue.  This will be retrieved periodically to display.
                _queue.Add(message);
                if (message.IsIncoming && !message.IsAdmin)
                {
                    _messageHandler.CrackMessage(message);
                }
            };

            _canceller = new CancellationTokenSource();

            _session.StateChangeEvent += state =>
            {
                if (state == SessionState.Started)
                {
                    StartListener();
                }
                if (state == SessionState.LoggedOut)
                {
                    StopListener();
                }
            };

            if (UserSettings.Default.AutoStart)
            {
                _session.Start();
            }
        }