/// <summary> /// 读取文件并发送文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SendFileManageReadFileBuffer( object sender, ReadFileBufferEventArgs e) { SendFileManager sendFileManager = sender as SendFileManager; TraFransfersFile ts = new TraFransfersFile( sendFileManager.MD5, e.Index, e.Buffer); Send((int)Command.RequestSendFilePack, ts); }
/// <summary> /// 接收文件事件方法 /// </summary> /// <param name="traFransfersFile"></param> /// <param name="remoteEp"></param> private void OnRecieveBuffer( TraFransfersFile traFransfersFile, IPEndPoint remoteEp) { ReceiveFileManager receiveFileManager; if (!ReceiveFileManagerList.TryGetValue( traFransfersFile.MD5, out receiveFileManager)) { return; } if (receiveFileManager != null) { ResponeTraFransfersFile responeTraFransfersFile; int size = receiveFileManager.ReceiveBuffer( traFransfersFile.Index, traFransfersFile.Buffer); if (receiveFileManager.Completed) { responeTraFransfersFile = new ResponeTraFransfersFile( traFransfersFile.MD5, size, -2); Send( (int)Command.ResponeSendFilePack, responeTraFransfersFile, remoteEp); } else { responeTraFransfersFile = new ResponeTraFransfersFile( traFransfersFile.MD5, size, receiveFileManager.GetNextReceiveIndex()); Send( (int)Command.ResponeSendFilePack, responeTraFransfersFile, remoteEp); } OnFileReceiveBuffer( new FileReceiveBufferEventArgs( receiveFileManager, traFransfersFile.Buffer.Length)); } }