Beispiel #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);
            }));
        }
Beispiel #2
0
 /// <summary>
 /// 请求接收文件响应时触发事件
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnFileRecieveRequest(RequestSendFileEventArgs e)
 {
     AddReadyReceiveItem(e);
     if (FileRecieveRequest != null)
     {
         FileRecieveRequest(this, e);
     }
 }
Beispiel #3
0
        /// <summary>
        /// 拒绝接收文件按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ItemRefuseButtonClick(object sender, EventArgs e)
        {
            FileTransfersItem        item = sender as FileTransfersItem;
            RequestSendFileEventArgs rse  = item.Tag as RequestSendFileEventArgs;

            rse.Cancel = true;
            fileTansfersContainer.RemoveItem(item);
            item.Dispose();
            AcceptReceive(rse);
        }
Beispiel #4
0
        /// <summary>
        /// 保存文件按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ItemSaveButtonClick(object sender, EventArgs e)
        {
            FileTransfersItem        item = sender as FileTransfersItem;
            RequestSendFileEventArgs rse  = item.Tag as RequestSendFileEventArgs;

            //自动保存在程序根目录下
            rse.Path = Application.StartupPath;
            ControlTag tag = new ControlTag(
                rse.TraFransfersFileStart.MD5,
                rse.TraFransfersFileStart.FileName,
                rse.RemoteIP);

            item.Tag                = tag;
            item.Style              = FileTransfersItemStyle.Receive;
            item.CancelButtonClick += new EventHandler(ItemCancelButtonClick);
            item.Start();
            this.AcceptReceive(rse);
        }
Beispiel #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);
            }
        }
Beispiel #6
0
        /// <summary>
        /// 文件另存为按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ItemSaveToButtonClick(object sender, EventArgs e)
        {
            FileTransfersItem        item = sender as FileTransfersItem;
            RequestSendFileEventArgs rse  = item.Tag as RequestSendFileEventArgs;
            FolderBrowserDialog      fbd  = new FolderBrowserDialog();

            if (fbd.ShowDialog() == DialogResult.OK)
            {
                rse.Path = fbd.SelectedPath;
                ControlTag tag = new ControlTag(
                    rse.TraFransfersFileStart.MD5,
                    rse.TraFransfersFileStart.FileName,
                    rse.RemoteIP);
                item.Tag                = tag;
                item.Style              = FileTransfersItemStyle.Receive;
                item.CancelButtonClick += new EventHandler(ItemCancelButtonClick);
                item.Start();

                this.AcceptReceive(rse);
            }
        }