public bool AddSendedMessage() { // 测试 var target = new SendedMessage(); target.CreateTime = DateTime.Now; target.From = "1561322601"; target.To = "1311949161"; target.Message = "使得房价过快的是的力量"; target.Owner = "1561322601"; m_MainDbContext.SendedMessageSet.Add(target); m_MainDbContext.SaveChanges(); return(true); }
public override void OnApplyTemplate() { SocketClient = SocketTool.GetClientUDP(); SendMessageCommand = new ActionCommand(() => { MessageContent_String MsgContent = new MessageContent_String(Text); MessageModel msg = new MessageModel(MessageType.String, UserFrom.UloginNumber ?? 0, UserTo.UloginNumber ?? 0, SocketTool.IPV4Address.ToString(), MsgContent); int MsgState = SocketClient.SendTo(msg, StaticResource.ServerIpaddress); SendedMessage?.Invoke(this, UserFrom, UserTo, msg, MsgState); Text = ""; }); SendImageCommand = new ActionCommand(() => { OpenFileDialog SelectDialog = new OpenFileDialog(); SelectDialog.Multiselect = true; SelectDialog.Filter = "*.jpg|*.png"; SelectDialog.ShowDialog(); String[] files = SelectDialog.FileNames; long FromNum = UserFrom.UloginNumber ?? 0; long ToNum = UserTo.UloginNumber ?? 0; foreach (String file in files) { ThreadPool.QueueUserWorkItem(call => { String FileName = ""; SocketTool.TCPSendFile(file, FromNum, ToNum, DataPacketType.ImageDataPacket, out FileName); MessageModel msg = TheMessageModel.IMAGE(FileName, FromNum, ToNum); int MsgState = SocketTool.GetClientUDP().SendToServer(msg); //将自己选择的文件位置作为图片发送出去 MessageContent_Image localImg = MessageModel.ToModel <MessageContent_Image>(msg.MessageContent); localImg.SetContent(file); msg.MessageContent = localImg; Dispatcher.Invoke(() => { SendedMessage?.Invoke(this, UserFrom, UserTo, msg, MsgState); }); Thread.Sleep(1000); }); } }); base.OnApplyTemplate(); }