public void SentMessage(MessageEventArgsModel messageEventArgsModel) { string messageJson = JsonConvert.SerializeObject(messageEventArgsModel); _sWriter.WriteLine(messageJson); _sWriter.Flush(); }
private void btn_Sent_Click(object sender, RoutedEventArgs e) { var isAuthenticated = _clientTcp.IsAuthenticated(); if (!isAuthenticated || string.IsNullOrWhiteSpace(textSent.Text)) { return; } var selectedConversation = (ConversationModel)listBox.SelectedItem; if (selectedConversation != null) { var message = new MessageEventArgsModel { Text = textSent.Text, MessageType = MessageType.ToAnotherClient, ConversationId = selectedConversation.Id, ClientId = _currentСlient.Id, PostingDateTime = DateTime.Now }; var messageId = _common.SaveMessage(message); message.Id = messageId; _clientTcp.SentMessage(message); textSent.Text = string.Empty; } }
private void SentStartMessage(object sender, MessageEventArgsModel e) { e.ClientId = _currentСlient.Id; e.MessageType = MessageType.Authenticate; e.PostingDateTime = DateTime.Now; _clientTcp.SentMessage(e); }
private static void SentToClient(StreamWriter sWriter, MessageEventArgsModel message) { string messageJson = JsonConvert.SerializeObject(message); sWriter.WriteLine(messageJson); sWriter.Flush(); }
private static void SetClientId(ClientModel x, MessageEventArgsModel message) { if (x.Port == _startsPortNumber) { x.ClientId = message.ClientId; } }
private void SetMessage(object sender, MessageEventArgsModel e) { this.Dispatcher.Invoke((Action)(() => { Messages.Add(e); textBox.ItemsSource = Messages; })); }
public int SaveMessage(MessageEventArgsModel message) { var entityMessage = new Message { Client = new Client { Id = message.ClientId }, FromPort = message.FromPort, Conversation = new Conversation { Id = message.ConversationId }, MessageType = (int)message.MessageType, PostingDateTime = message.PostingDateTime, Text = message.Text, ToPort = message.ToPort }; var messageId = _clientRepository.SaveMessage(entityMessage); return(messageId); }
public void StartTcpClient(int portNumber) { _portNumber = portNumber; var ipPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), portNumber); _client = new TcpClient(); _client.Connect(ipPoint); _sReader = new StreamReader(_client.GetStream(), Encoding.ASCII); _sWriter = new StreamWriter(_client.GetStream(), Encoding.ASCII); _isConnected = true; HandleCommunication(); if (!_isAuthenticated) { var message = new MessageEventArgsModel { }; //SentMessage(message); SentStartMessage(this, message); } }