Example #1
0
        /// <summary>
        /// 添加准备接收文件Item
        /// </summary>
        /// <param name="e"></param>
        public void AddReadyReceiveItem(RequestSendFileEventArgs e)
        {
            TraFransfersFileStart traFransfersFileStart = e.TraFransfersFileStart;

            Form.ActiveForm.BeginInvoke(new MethodInvoker(delegate()
            {
                FileTransfersItem item = fileTansfersContainer.AddItem(
                    traFransfersFileStart.MD5,
                    "接收文件",
                    traFransfersFileStart.FileName,
                    traFransfersFileStart.Image,
                    traFransfersFileStart.Length,
                    FileTransfersItemStyle.ReadyReceive);

                item.BaseColor              = _baseColor;
                item.BorderColor            = _borderColor;
                item.ProgressBarBarColor    = _progressBarBarColor;
                item.ProgressBarBorderColor = _progressBarBorderColor;
                item.ProgressBarTextColor   = _progressBarTextColor;
                item.Tag                = e;
                item.SaveButtonClick   += new EventHandler(ItemSaveButtonClick);
                item.SaveToButtonClick += new EventHandler(ItemSaveToButtonClick);
                item.RefuseButtonClick += new EventHandler(ItemRefuseButtonClick);
                fileTansfersContainer.ResumeLayout(true);
            }));
        }
Example #2
0
 /// <summary>
 /// 发送文件
 /// </summary>
 /// <param name="sendFileManager">需要发送的文件类</param>
 /// <param name="image">文件ICO图标</param>
 public void SendFile(SendFileManager sendFileManager, Image image)
 {
     if (SendFileManagerList.ContainsKey(sendFileManager.MD5))
     {
         throw new Exception(string.Format(
                                 "文件 {0} 正在发送,不能发送重复的文件。",
                                 sendFileManager.FileName));
     }
     else
     {
         SendFileManagerList.Add(sendFileManager.MD5, sendFileManager);
         sendFileManager.ReadFileBuffer += new ReadFileBufferEventHandler(
             SendFileManageReadFileBuffer);
         TraFransfersFileStart ts = new TraFransfersFileStart(
             sendFileManager.MD5,
             sendFileManager.Name,
             image,
             sendFileManager.Length,
             sendFileManager.PartCount,
             sendFileManager.PartSize);
         //添加
         AddSendItems(sendFileManager, image);
         Send((int)Command.RequestSendFile, ts);
     }
 }
Example #3
0
 public RequestSendFileEventArgs(
     TraFransfersFileStart traFransfersFileStart,
     IPEndPoint remoteIP)
     : base()
 {
     _traFransfersFileStart = traFransfersFileStart;
     _remoteIP = remoteIP;
 }
Example #4
0
 /// <summary>
 /// 开始接收文件事件方法(尚未开始接收文件)
 /// </summary>
 /// <param name="traFransfersFileStart"></param>
 /// <param name="remoteEp"></param>
 private void OnStartRecieve(
     TraFransfersFileStart traFransfersFileStart,
     IPEndPoint remoteEp)
 {
     OnFileRecieveRequest(
         new RequestSendFileEventArgs(
             traFransfersFileStart,
             remoteEp));
 }
Example #5
0
        /// <summary>
        /// 允许接收
        /// </summary>
        /// <param name="e"></param>
        public void AcceptReceive(RequestSendFileEventArgs e)
        {
            TraFransfersFileStart   traFransfersFileStart = e.TraFransfersFileStart;
            IPEndPoint              remoteIP = e.RemoteIP;
            ResponeTraFransfersFile responeTraFransfersFile;

            if (e.Cancel)
            {
                responeTraFransfersFile = new ResponeTraFransfersFile(
                    traFransfersFileStart.MD5, 0, -1);
                Send((int)Command.ResponeSendFile, responeTraFransfersFile, remoteIP);
            }
            else
            {
                ReceiveFileManager receiveFileManager;
                if (!ReceiveFileManagerList.TryGetValue(
                        traFransfersFileStart.MD5,
                        out receiveFileManager))
                {
                    receiveFileManager = new ReceiveFileManager(
                        traFransfersFileStart.MD5,
                        e.Path,
                        traFransfersFileStart.FileName,
                        traFransfersFileStart.PartCount,
                        traFransfersFileStart.PartSize,
                        traFransfersFileStart.Length,
                        remoteIP);
                    receiveFileManager.ReceiveFileComplete +=
                        new FileReceiveCompleteEventHandler(
                            ReceiveFileManagerReceiveFileComplete);
                    receiveFileManager.ReceiveFileTimeout +=
                        new EventHandler(ReceiveFileManagerReceiveFileTimeout);
                    ReceiveFileManagerList.Add(
                        traFransfersFileStart.MD5,
                        receiveFileManager);
                    receiveFileManager.Start();
                }
                responeTraFransfersFile = new ResponeTraFransfersFile(
                    traFransfersFileStart.MD5, 0, 0);
                Send((int)Command.ResponeSendFile, responeTraFransfersFile, remoteIP);
            }
        }