private static void GetAllMessages(IMessageContent messageContent, IJsonContainer container, SynchronizationContext uiContext)
 {
     foreach (var item in container.Messages)
     {
         uiContext.Send(x => MessageList.Items.Add(messageContent.NewInstance(item)), null);
     }
 }
Exemple #2
0
        private void Chat(string textFromClient, Socket socket)
        {
            if (FirstTime)
            {
                FirstTime = false;

                _person = ConverData.ToReceiv <Person>(textFromClient);

                _person.PersonId   = _PersonId;
                _person.Connection = socket;

                UsersOnline.Persons.Add(_person);

                ShowUsersOnline(_uIViewModel);

                AddPersonsToJsonContainer(_jsonContainer);

                foreach (var user in UsersOnline.Persons)
                {
                    if (user.PersonId == _PersonId)
                    {
                        _jsonContainer.CurrentPersonId.Id = _PersonId;

                        AddMessagesToJsonContainer(_jsonContainer);

                        user.Connection.Send(ConverData.ToSend(_jsonContainer));
                    }
                    else
                    {
                        _jsonContainer.Messages.Clear();
                        user.Connection.Send(ConverData.ToSend(_jsonContainer));
                    }
                }
            }
            else
            {
                DisconnectContent disconnectContent = new DisconnectContent();

                disconnectContent = ConverData.ToReceiv <DisconnectContent>(textFromClient);

                if (disconnectContent.ExitMessage != "€noc§dne§€")
                {
                    _messageContent = ConverData.ToReceiv <MessageContent>(textFromClient);

                    string tempName = _messageContent.Name;

                    AllMessages.Messages.Add(_messageContent.NewInstance(_messageContent));

                    AddToMessagesOnServer();

                    foreach (var item in UsersOnline.Persons)
                    {
                        if (item.PersonId == _messageContent.Id)
                        {
                            _messageContent.MessageAlignment         = "Right";
                            _messageContent.MessageColour            = SenderReceiwer.SendBubbleColor;
                            _messageContent.MessagePictureVisibility = "Hidden";
                            _messageContent.Name = "";
                        }
                        else
                        {
                            _messageContent.MessageAlignment         = "Left";
                            _messageContent.MessageColour            = SenderReceiwer.ReceiveBubleColor;
                            _messageContent.MessagePictureVisibility = "Visible";
                            _messageContent.Name = tempName;
                        }

                        item.Connection.Send(ConverData.ToSend(_messageContent));
                    }
                }
                else
                {
                    RemoveDisconnectedUser(disconnectContent);

                    SendUsersOnlineToClients();

                    ShowUsersOnline(_uIViewModel);
                }
            }
        }