public void IncomingMessage(CSS.IM.XMPP.protocol.client.Message msg) { try { if (msg.Type == MessageType.error) { MsgBox.Show(this, "CSS&IM", "离线消息没有发送成功!", MessageBoxButtons.OK); btn_close_Click(null, null); //btn_close_Click(null, null); //if (msg.To.Bare == _connection.MyJID.Bare && msg.From.Bare == to_Jid.Bare) //{ // MsgBox.Show(this, "CSS&IM", "在服务器中没有找到该用户,无法发送消息!", MessageBoxButtons.OK); // btn_close_Click(null, null); //} } int m_type = msg.GetTagInt("m_type"); switch (m_type) { case 0://正常消息 //RTBRecord.AppendTextAsRtf(msg.From.User + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second + "\n", new Font(this.Font, FontStyle.Underline | FontStyle.Bold), CSS.IM.Library.ExtRichTextBox.RtfColor.Red, CSS.IM.Library.ExtRichTextBox.RtfColor.White); CSS.IM.UI.Util.Win32.FlashWindow(this.Handle, true);//闪烁 #region 显示我自己发送的消息 CSS.IM.XMPP.protocol.client.Message top_msg = new XMPP.protocol.client.Message(); top_msg.SetTag("FName", this.Font.Name);//获得字体名称 top_msg.SetTag("FSize", this.Font.Size);//字体大小 top_msg.SetTag("FBold", true);//是否粗体 top_msg.SetTag("FItalic", this.Font.Italic);//是否斜体 top_msg.SetTag("FStrikeout", this.Font.Strikeout);//是否删除线 top_msg.SetTag("FUnderline", true);//是否下划线 Color top_cl = Color.Red;//获取颜色 byte[] top_cby = BitConverter.GetBytes(top_cl.ToArgb()); top_msg.SetTag("CA", top_cby[0]); top_msg.SetTag("CR", top_cby[1]); top_msg.SetTag("CG", top_cby[2]); top_msg.SetTag("CB", top_cby[3]); top_msg.Body = (_NickName != "" ? _NickName : msg.From.User) + "(" + msg.From.User + "):" + DateTime.Now.ToString("HH:mm:ss"); top_msg.From = TO_Jid; top_msg.To = TO_Jid; RTBRecord_Show(top_msg, true); #endregion RTBRecord_Show(msg, false); if (IsPlayMsg) { if (CSS.IM.UI.Util.Path.MsgSwitch) CSS.IM.UI.Util.SoundPlayEx.MsgPlay(CSS.IM.UI.Util.Path.MsgPath); } break; case 1://收到对方的请求要过行视频功能服务,初始化本地的视频 this.Invoke(AccepVideotInit, new object[] { msg }); break; case 2://我发送视频请求后,对方告诉我视频初使化完成,进行自己本地的视频初使化 this.Invoke(ReturnAcceptVideoInit, new object[] { msg }); break; case 3://对方给我发送视频请求,我初使化本地视频服务,告诉对方,对方也初使化视频服务了,我打开视频功能 this.Invoke(AcceptVideoOpen, new object[] { msg }); break; case 4://去对方获取截图的功能 RemotBaseUDPPort = msg.GetTagInt("BPort"); RemotBaseUDPIP = IPAddress.Parse(msg.GetTag("BIP")); bool isSend = msg.GetTagBool("isSend"); if (isSend) { CSS.IM.XMPP.protocol.client.Message fmsg = new CSS.IM.XMPP.protocol.client.Message(); fmsg.SetTag("m_type", 4); fmsg.Type = MessageType.chat; fmsg.To = TO_Jid; fmsg.SetTag("BPort", ListenBasicUDPPort); fmsg.SetTag("BIP", Program.LocalHostIP.ToString()); fmsg.SetTag("isSend", false); XmppConn.Send(fmsg); } sendSelfImage(); break; case 5://视频释放 if (RemotVideoUDPPort != -1) { //avForm.isBtn_hangup = true; if (avForm != null && !avForm.IsDisposed) { avForm.isBtn_hangup = true; avForm.AVClose(); } if (ravForm != null && !ravForm.IsDisposed) { ravForm.isBtn_hangup = true; ravForm.AVClose(); } } break; case 6://传文件 RemotBaseUDPPort = msg.GetTagInt("BPort"); RemotBaseUDPIP = IPAddress.Parse(msg.GetTag("BIP")); CSS.IM.XMPP.protocol.client.Message lmsg = new CSS.IM.XMPP.protocol.client.Message(); lmsg.SetTag("m_type", 7);//告诉对方要发送文件啦 lmsg.Type = MessageType.chat; lmsg.To = TO_Jid; lmsg.SetTag("BPort", udpReceiveFile.Port); lmsg.SetTag("BIP", Program.LocalHostIP.ToString()); lmsg.SetTag("isSend", false); lmsg.SetTag("File", msg.GetTag("File").ToString()); XmppConn.Send(lmsg); break; case 7: RemotBaseUDPPort = msg.GetTagInt("BPort"); RemotBaseUDPIP = IPAddress.Parse(msg.GetTag("BIP")); this.Invoke(FileSendInitEvent, msg.GetTag("File").ToString()); break; case 8://ftp离线文件 this.Invoke(GetFtpFileEvent, new object[] { msg}); break; case 9://对方拒绝接收主线文件 this.AppendSystemRtf("对方"+msg.Body); break; case 10://对方接收离线文件 //DownloadImage try { FTPClient ftpClient = new FTPClient(Util.ServerAddress, Util.ftpPath, Util.ftpUser, Util.ftpPswd, Util.ftpPort); ftpClient.FtpPath=msg.GetTag("Path"); DownloadImage downloadImage = new DownloadImage(); downloadImage.ftpClient = ftpClient; downloadImage.remoteImageName = msg.GetTag("FileName"); downloadImage.parent = this; Thread getFileThread = new Thread(downloadImage.Download); getFileThread.Start(); } catch (Exception) { } break; case 11://接收到red的视频请求 this.Invoke(Red5AccpetEvent, new object[] { msg }); break; case 12://接收到red的视频请求 this.Invoke(Red5RefuseEvent, new object[] { msg }); break; case 13: //red5MsgSend_FormClosing if (red5MsgReceive != null || !red5MsgReceive.IsDisposed) { red5MsgReceive.Close(); red5MsgReceive.Dispose(); red5MsgReceive = null; } this.AppendSystemRtf("对方" + msg.From.User + "关闭了视频通话"); break; case 14: //red5MsgReceive_FormClosing if (red5MsgSend != null || !red5MsgSend.IsDisposed) { red5MsgSend.Close(); red5MsgSend.Dispose(); red5MsgSend = null; } this.AppendSystemRtf("对方" + msg.From.User + "关闭了视频通话"); break; } } catch (Exception) { } }
public DownloadFile(ChatFromMsg parent, FTPClient ftpClient) { this.parent = parent; this.ftpClient = ftpClient; }
public void ftpClient_PushProgressEvent(FTPClient sender, int args) { FileTransfersItem item = sender.sendFileManager.Tag as FileTransfersItem; if (item != null) { BeginInvoke(new MethodInvoker(delegate() { item.TotalTransfersSize += args; })); } }
private void item_OffLineFilesButtonClick(object sender, EventArgs e) { FileTransfersItem item = sender as FileTransfersItem; SendFileManager sendFileManager = item.Tag as SendFileManager; this.AppendSystemRtf(string.Format("文件 {0} 取消发送成功。", sendFileManager.Name)); if (OnLine) { udpSendFile.CancelSend(sendFileManager.MD5); } Util.SendFileManagerList.Add(sendFileManager.MD5, sendFileManager); FTPClient ftpClient = new FTPClient(Util.ServerAddress,Util.ftpPath, Util.ftpUser, Util.ftpPswd, Util.ftpPort); ftpClient.sendFileManager = sendFileManager; sendFileManager.ftpClient = ftpClient; item.Tag = sendFileManager; item.Style = FileTransfersItemStyle.Cancel; this.AppendSystemRtf(string.Format("文件 {0} 更改发送离线文件。",sendFileManager.Name)); UploadFile ftpPush = new UploadFile(this); Thread pushThread = new Thread(ftpPush.PushFile); pushThread.Start(ftpClient); }
//发送图片文件 private void sendSelfImage() { CSS.IM.Library.gifCollections tempGifs = PicQueue.Clone() as CSS.IM.Library.gifCollections; try { foreach (CSS.IM.Library.MyPicture pic in tempGifs) if (pic.IsSent) { System.IO.FileInfo f = new System.IO.FileInfo(Util.sendImage + pic.ImageMD5 + ".gif"); //this.ImageTransfers(true, f.FullName, pic.ImageMD5, (int)f.Length, f.Extension, pic.ImageMD5); FTPClient ftpClient = new FTPClient(Util.ServerAddress, Util.ftpPath, Util.ftpUser, Util.ftpPswd, Util.ftpPort); ftpClient.FtpPath = XmppConn.MyJID.User; UploadImage uploadImage = new UploadImage(); uploadImage.ftpClient = ftpClient; uploadImage.ImageName = pic.ImageMD5; uploadImage.Name = f.FullName; uploadImage.parent = this; Thread pushThread = new Thread(uploadImage.Upload); pushThread.Start(); PicQueue.Romove(pic);//将richTextBox中的自定义图片清除掉,以便下次继续发送消息时出现再次发送的情况 //System.Threading.Thread.Sleep(500); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("发送图片时错误:" + ex.Message); } }
private void ftpClient_PushFileSucceedEvent(FTPClient sender, string args) { FileTransfersItem item =sender.sendFileManager.Tag as FileTransfersItem; Util.SendFileManagerList.Remove(sender.sendFileManager.MD5); if (item != null) { BeginInvoke(new MethodInvoker(delegate() { CSS.IM.XMPP.protocol.client.Message fmsg = new CSS.IM.XMPP.protocol.client.Message(); fmsg.Type = MessageType.chat; fmsg.To = TO_Jid; fmsg.SetTag("m_type", 8); fmsg.SetTag("MD5", args); fmsg.SetTag("FileName", System.IO.Path.GetFileName(sender.sendFileManager.FileName)); fmsg.SetTag("Length", sender.sendFileManager.Length); fmsg.SetTag("Path", XmppConn.MyJID.User); fmsg.From = XmppConn.MyJID; fmsg.Body = "离线文件" + System.IO.Path.GetFileName(sender.sendFileManager.FileName); XmppConn.Send(fmsg); fileTansfersContainer.RemoveItem(item); item.Dispose(); })); } this.AppendSystemRtf(string.Format("离线文件 {0} 发送完成。", sender.sendFileManager.Name)); }
/// <summary> /// 接收离线文件 /// </summary> /// <param name="msg"></param> private void GetFtpFileAMethod(XMPP.protocol.client.Message msg) { FTPClient ftpClient = new FTPClient(Util.ServerAddress, Util.ftpPath, Util.ftpUser, Util.ftpPswd, Util.ftpPort); ftpClient.FtpPath = msg.GetTag("Path"); ftpClient.GetFileErrorEvent += new FTPClient.GetFileErrorDelegate(ftpClient_GetFileErrorEvent); ftpClient.GetFileProgressEvent += new FTPClient.GetFileProgressDelegate(ftpClient_GetFileProgressEvent); ftpClient.GetFileSucceedEvent += new FTPClient.GetFileSucceedDelegate(ftpClient_GetFileSucceedEvent); ftpClient.ChDir("/" + ftpClient.FtpPath + "/"); long fileSize = long.Parse(msg.GetTag("Length")); FileTransfersItem item = fileTansfersContainer.AddItem( msg.GetTag("MD5"), "接收文件", msg.GetTag("FileName"), Properties.Resources.ReceiveIco, fileSize, FileTransfersItemStyle.FtpGet); item.BaseColor = _baseColor; item.BorderColor = _borderColor; item.ProgressBarBarColor = _progressBarBarColor; item.ProgressBarBorderColor = _progressBarBorderColor; item.ProgressBarTextColor = _progressBarTextColor; RequestSendFileEventArgs requestSendFileEventArgs = new RequestSendFileEventArgs(); requestSendFileEventArgs.ftpClient = ftpClient; ftpClient.fileTransfersItem = item; item.Tag = requestSendFileEventArgs; item.SaveButtonClick += new EventHandler(ItemSaveButtonClick); item.SaveToButtonClick += new EventHandler(ItemSaveToButtonClick); item.RefuseButtonClick += new EventHandler(ItemRefuseButtonClick); Util.ReceiveFileManagerList.Add(msg.GetTag("MD5"), requestSendFileEventArgs); this.Invoke(new RequestSendFilePanel(RequestSendFilePanelMethod)); this.AppendSystemRtf(string.Format("请求接收离线文件 {0}。", msg.GetTag("FileName"))); }
private void ftpClient_ImagePushProgressEvent(FTPClient sender, int args) { //FileTransfersItem item = sender.sendFileManager.Tag as FileTransfersItem; //if (item != null) //{ // BeginInvoke(new MethodInvoker(delegate() // { // item.TotalTransfersSize += args; // })); //} }
private void ftpClient_PushFileErrorEvent(FTPClient sender, bool args) { if (InvokeRequired) { this.Invoke(new FTPClient.PushFileErrorDelegate(ftpClient_PushFileErrorEvent), new object[] { sender, args }); } Util.SendFileManagerList.Remove(sender.sendFileManager.MD5); FileTransfersItem item =sender.sendFileManager.Tag as FileTransfersItem; fileTansfersContainer.RemoveItem(item); this.AppendSystemRtf(string.Format("离线文件 {0} 取消成功。", sender.sendFileManager.Name)); }
private void ftpClient_ImagePushFileSucceedEvent(FTPClient sender, string args) { CSS.IM.XMPP.protocol.client.Message fmsg = new CSS.IM.XMPP.protocol.client.Message(); fmsg.Type = MessageType.chat; fmsg.To = TO_Jid; fmsg.SetTag("m_type", 10); fmsg.SetTag("FileName", args); fmsg.SetTag("Path", sender.FtpPath); fmsg.From = XmppConn.MyJID; fmsg.Body = "发送屏幕截图"; XmppConn.Send(fmsg); System.Diagnostics.Debug.WriteLine("图片上传完成:"+args); }
private void ftpClient_ImageGetFileSucceedEvent(FTPClient sender, string args) { CSS.IM.Library.Controls.fileTransmitEvnetArgs e = new fileTransmitEvnetArgs(false, Util.receiveImage + args, args, null, 0, 0, args); imageTransmittedDelegate d = new imageTransmittedDelegate(imageTransmitted); this.BeginInvoke(d, null, e); }
private void ftpClient_GetFileSucceedEvent(FTPClient sender, string args) { try { BeginInvoke(new MethodInvoker(delegate() { fileTansfersContainer.RemoveItem(sender.fileTransfersItem.Name); })); Util.ReceiveFileManagerList.Remove(sender.fileTransfersItem.Name); this.AppendSystemRtf(string.Format(@"文件<file:\\{0}>接收完成。", sender.fileTransfersItem.receivePath + sender.fileTransfersItem.FileName)); CSS.IM.XMPP.protocol.client.Message fmsg = new CSS.IM.XMPP.protocol.client.Message(); fmsg.Type = MessageType.chat; fmsg.To = TO_Jid; fmsg.SetTag("m_type", 9); fmsg.SetTag("FileName", sender.fileTransfersItem.FileName); fmsg.From = XmppConn.MyJID; fmsg.Body = "离线文件" + sender.fileTransfersItem.FileName + "接收成功。"; XmppConn.Send(fmsg); } catch (Exception) { } }
private void ftpClient_GetFileProgressEvent(FTPClient sender, int args) { FileTransfersItem item = fileTansfersContainer.Search(sender.fileTransfersItem.Name); if (item != null) { BeginInvoke(new MethodInvoker(delegate() { item.TotalTransfersSize += args; })); } }
private void ftpClient_GetFileErrorEvent(FTPClient sender, bool args) { if (InvokeRequired) { try { this.Invoke(new FTPClient.GetFileErrorDelegate(ftpClient_GetFileErrorEvent), new object[] { sender, args }); } catch (Exception) { return; } } Util.ReceiveFileManagerList.Remove(sender.fileTransfersItem.Name); FileTransfersItem item = sender.fileTransfersItem; fileTansfersContainer.RemoveItem(item); this.AppendSystemRtf(string.Format("接收离线文件 {0} 取消成功。", sender.fileTransfersItem.FileName)); }