/// <summary> /// 取消发送文件事件方法 /// </summary> /// <param name="md5"></param> /// <param name="remoteIP"></param> private void OnRequestCancelSendFile(string md5, IPEndPoint remoteIP) { ReceiveFileManager receiveFileManager; if (ReceiveFileManagerList.TryGetValue( md5, out receiveFileManager)) { OnFileReceiveCancel( new FileReceiveEventArgs(receiveFileManager)); lock (_receivesyncLock) { ReceiveFileManagerList.Remove(md5); receiveFileManager.Dispose(); receiveFileManager = null; } } else { FileReceiveEventArgs fe = new FileReceiveEventArgs(); fe.Tag = md5; OnFileReceiveCancel(fe); } Send( (int)Command.ResponeCancelSendFile, "OK", remoteIP); }
/// <summary> /// 文件接收完成时触发事件 /// </summary> /// <param name="e"></param> protected virtual void OnFileReceiveComplete(FileReceiveEventArgs e) { Form.ActiveForm.BeginInvoke(new MethodInvoker(delegate() { fileTansfersContainer.RemoveItem(e.ReceiveFileManager.MD5); })); if (FileReceiveComplete != null) { FileReceiveComplete(this, e); } }
/// <summary> /// 文件接收时被取消发送触发事件 /// </summary> /// <param name="e"></param> protected virtual void OnFileReceiveCancel(FileReceiveEventArgs e) { string md5 = string.Empty; if (e.ReceiveFileManager != null) { md5 = e.ReceiveFileManager.MD5; } else { md5 = e.Tag.ToString(); } FileTransfersItem item = fileTansfersContainer.Search(md5); Form.ActiveForm.BeginInvoke(new MethodInvoker(delegate() { fileTansfersContainer.RemoveItem(item); })); if (FileReceiveCancel != null) { FileReceiveCancel(this, e); } }