예제 #1
0
        public void Send()
        {
            _messageContent.MessageText   = SendText;
            _messageContent.MessageTime   = DateTime.Now.ToShortTimeString();
            _messageContent.MessageColour = SenderReceiwer.Send;

            if (!_messageContent.PictureChanged)
            {
                _messageContent.MessagePicture = UserGender.GetUserGender();
            }

            _messageContent.Name = UserInfo.Name;

            _messageContent.Id = User.Id;

            if (UserInfo.AddedPicture != null)
            {
                _messageContent.Pic            = ConvertImage.ToByte(UserInfo.AddedPicture);
                _messageContent.MessagePicture = @"C:\Users\X\Downloads\ChatData\ChatImage" + _messageContent.Id + ".jpg";

                _messageContent.PictureChanged = true;
            }


            var messageInBytes = ConverData.ToSend(_messageContent);

            try
            {
                TcpSocket.tcpSocket.BeginSend(messageInBytes, 0, messageInBytes.Length, SocketFlags.None, new AsyncCallback(SendCallback), TcpSocket.tcpSocket);
            }
            catch (Exception ex)
            {
                AlertMessages.Show(ex.Message);

                OnlineUsers.UserList.Clear();

                TcpSocket.tcpSocket.Shutdown(SocketShutdown.Both);
                TcpSocket.tcpSocket.Disconnect(true);

                _windowsViewModel.ChangeView(0);

                return;
            }

            SendText = "";

            UserInfo.AddedPicture = null;
            _messageContent.Pic   = null;
        }