Exemple #1
0
        private void HandleConnectionStateChanged(object sender, ConnectionStateChangedEventArgs eventArgs)
        {
            string client         = eventArgs.ClientName;
            bool   isRegistration = false;

            if (eventArgs.EventLog.Type == DispatchType.Login && !eventArgs.EventLog.IsSuccessfully)
            {
                eventArgs.EventLog.IsSuccessfully = true;
                isRegistration = true;
                _dataBaseManager.CreateUserAsync(
                    new User
                {
                    Name = eventArgs.ClientName
                });
                AddNewUserOnList(client);
            }

            if (eventArgs.EventLog.Type == DispatchType.Login && eventArgs.EventLog.IsSuccessfully)
            {
                SendLoginInitAsync(eventArgs);
            }

            if (eventArgs.EventLog.IsSuccessfully && Contains(client))
            {
                var crc = new ChannelResponseContainer(new UpdateChannel(eventArgs.Connected, client, isRegistration), client);
                _wsServer.Send(crc, new GeneralAgenda());
                _tcpServer.Send(crc, new GeneralAgenda());
            }

            string clientState = eventArgs.Connected ? "connect" : "disconnect";
            string message     = $"Client '{client}' {clientState}.";

            AddUserOnList(eventArgs.Connected, client);

            var eventLogMessage = new EventLogMessage
            {
                IsSuccessfully = eventArgs.EventLog.IsSuccessfully,
                SenderName     = client,
                Text           = message,
                Time           = DateTime.Now,
                Type           = DispatchType.Connection
            };

            EventSaveAsync(new MessageEventLogContainer(eventLogMessage), new GeneralAgenda());
        }
Exemple #2
0
        private void OnConnectionStateChanged(object sender, ConnectionStateChangedEventArgs e)
        {
            string userState = e.IsConnected ? "connected." : "disconnected.";
            string message   = $"{e.Username} {userState}.";

            if (e.IsConnected)
            {
                var messageHistory = _requestHander.GetGroupMessages(e.Username);
                var users          = _requestHander.GetUsers();
                var groups         = _requestHander.GetGroups(e.Username);

                _wsServer.Send(String.Empty, e.Username, new MessageHistoryResponse(messageHistory).GetContainer());
                _wsServer.Send(String.Empty, e.Username, new UserListResponse(users).GetContainer());
                _wsServer.Send(String.Empty, e.Username, new GroupListResponse(groups).GetContainer());
            }

            _requestHander.AddEvent(EventType.Event, message, e.Date);

            Console.WriteLine($"{DateTime.Now} - {message}");

            _wsServer.Send(e.Username, String.Empty, new MessageBroadcast(e.Username, String.Empty, userState, String.Empty, DateTime.Now).GetContainer());
        }
Exemple #3
0
        private void HandleMessageReceived(object sender, MessageReceivedEventArgs e)
        {
            string target = e.Target;

            if (!String.IsNullOrEmpty(e.GroupName))
            {
                target = String.Empty;
            }

            if (e.Target == null)
            {
                Console.WriteLine($"{e.Source} : {e.Message}");
            }
            else
            {
                Console.WriteLine($"{e.Source} to {e.Target} : {e.Message}");
            }

            _txtMsgService.AddMessage(e.Source, e.Target, e.Message, e.Date);

            _wsServer.Send(e.Source, target, new MessageBroadcast(e.Source, target, e.Message, DateTime.Now, e.GroupName).GetContainer());
        }