Exemplo n.º 1
0
        private void AppServer_NewSessionConnected(WebSocketSession session)
        {
            System.Diagnostics.Debug.WriteLine($"ChatService: New session connected! Sessions counter = {appServer.SessionCount}");

            lock (_Chats)
            {
                var result = new ChatServiceMethod()
                {
                    Method = "items", Value = JsonConvert.SerializeObject(_Chats)
                };
                new Task(() => session.Send(JsonConvert.SerializeObject(result))).Start();
            }
        }
Exemplo n.º 2
0
        public void AddChat(Chat chat)
        {
            //chat.Id = Guid.NewGuid();
            chat.Time = DateTimeOffset.UtcNow;

            lock (_Chats)
            {
                if (_Chats.Count == LengthArray)
                {
                    _Chats.RemoveAt(0);
                }

                _Chats.Add(chat);
            }

            foreach (var item in appServer.GetAllSessions().ToList())
            {
                var result = new ChatServiceMethod()
                {
                    Method = "item", Value = JsonConvert.SerializeObject(chat)
                };
                new Task(() => item.Send(JsonConvert.SerializeObject(result))).Start();
            }
        }