void FormTalkUser_FormClosing(object sender, FormClosingEventArgs e) { if (!tsButAV.Enabled && flowLayoutPanel1.Controls.Count == 0)//如果视频对话中。。。 { if (MessageBox.Show("如果关闭窗口,将会中止视频对话。是否关闭窗口?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes) { video1.CancelAV();//取消视频 IMLibrary3.Protocol.AVMsg msg = new IMLibrary3.Protocol.AVMsg(); msg.type = IMLibrary3.Protocol.type.cancel; if (SendMsgToUser != null)//触发消息发送事件 { SendMsgToUser(msg, User); } e.Cancel = false; } } else if (tsButAV.Enabled && flowLayoutPanel1.Controls.Count > 0) { if (MessageBox.Show("如果关闭窗口,将会中止文件传输。是否关闭窗口?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes) { IMLibrary3.Protocol.P2PFileMsg pfile = new IMLibrary3.Protocol.P2PFileMsg(); //文件传输协商协议 pfile.type = IMLibrary3.Protocol.type.cancel; //标记取消文件传输 pfile.MD5 = ""; if (SendMsgToUser != null) //触发消息发送事件 { SendMsgToUser(pfile, User); } e.Cancel = false; } } else if (!tsButAV.Enabled && flowLayoutPanel1.Controls.Count > 0) { if (MessageBox.Show("如果关闭窗口,将会中止文件传输和视频对话。是否关闭窗口?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes) { video1.CancelAV();//取消视频 IMLibrary3.Protocol.AVMsg msg = new IMLibrary3.Protocol.AVMsg(); msg.type = IMLibrary3.Protocol.type.cancel; if (SendMsgToUser != null)//触发消息发送事件 { SendMsgToUser(msg, User); } IMLibrary3.Protocol.P2PFileMsg pfile = new IMLibrary3.Protocol.P2PFileMsg(); //文件传输协商协议 pfile.type = IMLibrary3.Protocol.type.cancel; //标记取消文件传输 pfile.MD5 = ""; if (SendMsgToUser != null) //触发消息发送事件 { SendMsgToUser(pfile, User); } e.Cancel = false; } } }
/// <summary> /// 设置文件传输远程主机信息 /// </summary> public void setFileRometEP(IMLibrary3.Protocol.P2PFileMsg pfile) { foreach (Control c in flowLayoutPanel1.Controls) { OurMsg.Controls.FileTransmit ft = c as OurMsg.Controls.FileTransmit; if (ft != null && ft.P2PFileTransmit.TFileInfo.MD5 == pfile.MD5) { ft.P2PFileTransmit.Start(true); //发送方参数须设置为真 ft.P2PFileTransmit.setRemoteIP(new IPEndPoint(pfile.LocalIP, pfile.LocalPort), new IPEndPoint(pfile.remoteIP, pfile.remotePort)); //设置文件传输远程主机信息 } } }
void P2PFileTransmit_GetIPEndPoint(object sender, IPEndPoint local, IPEndPoint remote) { IMLibrary3.Protocol.P2PFileMsg pfile = new IMLibrary3.Protocol.P2PFileMsg(); //文件传输协商协议 pfile.type = IMLibrary3.Protocol.type.set; //标记要求对方设置当前用户的远程主机信息 pfile.MD5 = (sender as p2pFileClient).TFileInfo.MD5; pfile.LocalIP = local.Address; pfile.LocalPort = local.Port; pfile.remoteIP = remote.Address; pfile.remotePort = remote.Port; if (SendMsgToUser != null)//触发消息发送事件 { SendMsgToUser(pfile, User); } }
/// <summary> /// 准备接收文件传输 /// </summary> /// <param name="pfile"></param> public void ReceiveFile(IMLibrary3.Protocol.P2PFileMsg pfile) { TFileInfo tFileInfo = new TFileInfo(); tFileInfo.Name = pfile.Name; tFileInfo.Length = pfile.Length; tFileInfo.Extension = pfile.Extension; tFileInfo.MD5 = pfile.MD5; OurMsg.Controls.FileTransmit ft = new Controls.FileTransmit(); ft.P2PFileTransmit = new p2pFileClient(Global.FileTransmitServerEP, tFileInfo); ft.fileTransmitCancel += new OurMsg.Controls.FileTransmit.fileTransmitEventHandler(ft_fileTransmitCancel); ft.P2PFileTransmit.GetIPEndPoint += new FileTransmitBase.GetIPEndPointEventHandler(P2PFileTransmit_GetIPEndPoint); ft.fileTransmitted += new OurMsg.Controls.FileTransmit.fileTransmitEventHandler(ft_fileTransmitted); flowLayoutPanel1.Controls.Add(ft); }
void ft_fileTransmitCancel(object sender) { OurMsg.Controls.FileTransmit ft = sender as OurMsg.Controls.FileTransmit; IMLibrary3.Protocol.P2PFileMsg pfile = new IMLibrary3.Protocol.P2PFileMsg(); //文件传输协商协议 pfile.type = IMLibrary3.Protocol.type.cancel; //标记取消文件传输 pfile.MD5 = ft.P2PFileTransmit.TFileInfo.MD5; if (SendMsgToUser != null)//触发消息发送事件 { SendMsgToUser(pfile, User); } MessagePanel1.addRemarkTextToRecord(" 您取消了文件“" + ft.P2PFileTransmit.TFileInfo.Name + "”的传输!"); flowLayoutPanel1.Controls.Remove(ft); ft.Dispose(); ft = null; }
private void sendFile(string filename) { OurMsg.Controls.FileTransmit ft = new Controls.FileTransmit(); ft.P2PFileTransmit = new p2pFileClient(Global.FileTransmitServerEP, filename); ft.fileTransmitCancel += new OurMsg.Controls.FileTransmit.fileTransmitEventHandler(ft_fileTransmitCancel); ft.P2PFileTransmit.GetIPEndPoint += new FileTransmitBase.GetIPEndPointEventHandler(P2PFileTransmit_GetIPEndPoint); ft.fileTransmitted += new OurMsg.Controls.FileTransmit.fileTransmitEventHandler(ft_fileTransmitted); flowLayoutPanel1.Controls.Add(ft); IMLibrary3.Protocol.P2PFileMsg pfile = new IMLibrary3.Protocol.P2PFileMsg(); //文件传输协商协议 pfile.type = IMLibrary3.Protocol.type.New; //标记发送新文件 pfile.Name = ft.P2PFileTransmit.TFileInfo.Name; pfile.MD5 = ft.P2PFileTransmit.TFileInfo.MD5; pfile.Length = ft.P2PFileTransmit.TFileInfo.Length; pfile.Extension = ft.P2PFileTransmit.TFileInfo.Extension; if (SendMsgToUser != null)//触发消息发送事件 { SendMsgToUser(pfile, User); } }
/// <summary> /// 取消文件传输 /// </summary> /// <param name="pfile"></param> public void CancelFile(IMLibrary3.Protocol.P2PFileMsg pfile) { if (pfile.MD5 == "") { flowLayoutPanel1.Controls.Clear(); MessagePanel1.addRemarkTextToRecord(" 对方取消了所有文件的传输!"); return; } foreach (Control c in flowLayoutPanel1.Controls) { OurMsg.Controls.FileTransmit ft = c as OurMsg.Controls.FileTransmit; if (ft != null && (ft.P2PFileTransmit.TFileInfo.MD5 == pfile.MD5)) { ft.CancelTransmit(); MessagePanel1.addRemarkTextToRecord(" 对方取消了文件“" + ft.P2PFileTransmit.TFileInfo.Name + "”的传输!"); flowLayoutPanel1.Controls.Remove(ft); ft.Dispose(); ft = null; } } }
void P2PFileTransmit_GetIPEndPoint(object sender, IPEndPoint local, IPEndPoint remote) { IMLibrary3.Protocol.P2PFileMsg pfile = new IMLibrary3.Protocol.P2PFileMsg();//文件传输协商协议 pfile.type = IMLibrary3.Protocol.type.set;//标记要求对方设置当前用户的远程主机信息 pfile.MD5 = (sender as p2pFileClient).TFileInfo.MD5; pfile.LocalIP = local.Address; pfile.LocalPort = local.Port; pfile.remoteIP = remote.Address; pfile.remotePort = remote.Port; if (SendMsgToUser != null)//触发消息发送事件 SendMsgToUser(pfile, User); }
void ft_fileTransmitCancel(object sender) { OurMsg.Controls.FileTransmit ft = sender as OurMsg.Controls.FileTransmit; IMLibrary3.Protocol.P2PFileMsg pfile = new IMLibrary3.Protocol.P2PFileMsg();//文件传输协商协议 pfile.type = IMLibrary3.Protocol.type.cancel ;//标记取消文件传输 pfile.MD5 = ft.P2PFileTransmit.TFileInfo.MD5; if (SendMsgToUser != null)//触发消息发送事件 SendMsgToUser(pfile, User); MessagePanel1.addRemarkTextToRecord(" 您取消了文件“" + ft.P2PFileTransmit.TFileInfo.Name + "”的传输!"); flowLayoutPanel1.Controls.Remove(ft); ft.Dispose(); ft = null; }
private void sendFile(string filename) { OurMsg.Controls.FileTransmit ft = new Controls.FileTransmit(); ft.P2PFileTransmit = new p2pFileClient(Global.FileTransmitServerEP, filename); ft.fileTransmitCancel += new OurMsg.Controls.FileTransmit.fileTransmitEventHandler(ft_fileTransmitCancel); ft.P2PFileTransmit.GetIPEndPoint += new FileTransmitBase.GetIPEndPointEventHandler(P2PFileTransmit_GetIPEndPoint); ft.fileTransmitted += new OurMsg.Controls.FileTransmit.fileTransmitEventHandler(ft_fileTransmitted); flowLayoutPanel1.Controls.Add(ft); IMLibrary3.Protocol.P2PFileMsg pfile = new IMLibrary3.Protocol.P2PFileMsg();//文件传输协商协议 pfile.type = IMLibrary3.Protocol.type.New;//标记发送新文件 pfile.Name = ft.P2PFileTransmit.TFileInfo.Name; pfile.MD5 = ft.P2PFileTransmit.TFileInfo.MD5; pfile.Length = ft.P2PFileTransmit.TFileInfo.Length; pfile.Extension = ft.P2PFileTransmit.TFileInfo.Extension; if (SendMsgToUser != null)//触发消息发送事件 SendMsgToUser(pfile, User); }
void FormTalkUser_FormClosing(object sender, FormClosingEventArgs e) { if (!tsButAV.Enabled && flowLayoutPanel1.Controls.Count == 0)//如果视频对话中。。。 { if (MessageBox.Show("如果关闭窗口,将会中止视频对话。是否关闭窗口?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes) { video1.CancelAV();//取消视频 IMLibrary3.Protocol.AVMsg msg = new IMLibrary3.Protocol.AVMsg(); msg.type = IMLibrary3.Protocol.type.cancel; if (SendMsgToUser != null)//触发消息发送事件 SendMsgToUser(msg, User); e.Cancel = false; } } else if (tsButAV.Enabled && flowLayoutPanel1.Controls.Count > 0) { if (MessageBox.Show("如果关闭窗口,将会中止文件传输。是否关闭窗口?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes) { IMLibrary3.Protocol.P2PFileMsg pfile = new IMLibrary3.Protocol.P2PFileMsg();//文件传输协商协议 pfile.type = IMLibrary3.Protocol.type.cancel;//标记取消文件传输 pfile.MD5 = ""; if (SendMsgToUser != null)//触发消息发送事件 SendMsgToUser(pfile, User); e.Cancel = false; } } else if (!tsButAV.Enabled && flowLayoutPanel1.Controls.Count > 0) { if (MessageBox.Show("如果关闭窗口,将会中止文件传输和视频对话。是否关闭窗口?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes) { video1.CancelAV();//取消视频 IMLibrary3.Protocol.AVMsg msg = new IMLibrary3.Protocol.AVMsg(); msg.type = IMLibrary3.Protocol.type.cancel; if (SendMsgToUser != null)//触发消息发送事件 SendMsgToUser(msg, User); IMLibrary3.Protocol.P2PFileMsg pfile = new IMLibrary3.Protocol.P2PFileMsg();//文件传输协商协议 pfile.type = IMLibrary3.Protocol.type.cancel;//标记取消文件传输 pfile.MD5 = ""; if (SendMsgToUser != null)//触发消息发送事件 SendMsgToUser(pfile, User); e.Cancel = false; } } }