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>
 /// 移除对应FileTransfersItem
 /// </summary>
 /// <param name="item">FileTransfersItem</param>
 public void RemoveItem(FileTransfersItem item)
 {
     base.Controls.Remove(item);
     if (IsAutomaticShowHide)
     {
         base.Visible = base.Controls.Count > 0 ? true : false;
     }
 }
Beispiel #3
0
        /// <summary>
        /// 取消按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ItemCancelButtonClick(object sender, EventArgs e)
        {
            FileTransfersItem item = sender as FileTransfersItem;
            ControlTag        tag  = item.Tag as ControlTag;

            CancelReceive(tag.MD5, tag.RemoteIP);
            fileTansfersContainer.RemoveItem(item);
            item.Dispose();
        }
Beispiel #4
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 #5
0
        private void ItemSendCancelButtonClick(object sender, EventArgs e)
        {
            FileTransfersItem item =
                sender as FileTransfersItem;
            SendFileManager sendFileManager =
                item.Tag as SendFileManager;

            this.CancelSend(sendFileManager.MD5);

            fileTansfersContainer.RemoveItem(item);
        }
Beispiel #6
0
        /// <summary>
        /// 文件被读取时(正在读取)触发事件
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnFileReceiveBuffer(FileReceiveBufferEventArgs e)
        {
            FileTransfersItem item = fileTansfersContainer.Search(
                e.ReceiveFileManager.MD5);

            if (item != null)
            {
                Form.ActiveForm.BeginInvoke(new MethodInvoker(delegate()
                {
                    item.TotalTransfersSize += e.Size;
                }));
            }
            if (FileReceiveBuffer != null)
            {
                FileReceiveBuffer(this, e);
            }
        }
Beispiel #7
0
        /// <summary>
        /// 文件正在发送时触发事件
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnFileSendBuffer(FileSendBufferEventArgs e)
        {
            FileTransfersItem item =
                e.SendFileManager.Tag as FileTransfersItem;

            if (item != null)
            {
                Form.ActiveForm.BeginInvoke(new MethodInvoker(delegate()
                {
                    item.TotalTransfersSize += e.Size;
                }));
            }
            if (FileSendBuffer != null)
            {
                FileSendBuffer(this, e);
            }
        }
Beispiel #8
0
        /// <summary>
        /// 文件被接收时触发事件
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnFileSendAccept(FileSendEventArgs e)
        {
            FileTransfersItem item =
                e.SendFileManager.Tag as FileTransfersItem;

            if (item != null)
            {
                Form.ActiveForm.BeginInvoke(new MethodInvoker(delegate()
                {
                    item.Start();
                }));
            }
            if (FileSendAccept != null)
            {
                FileSendAccept(this, e);
            }
        }
Beispiel #9
0
        public void RemoveItem(Predicate <FileTransfersItem> match)
        {
            FileTransfersItem itemRemove = null;

            foreach (FileTransfersItem item in base.Controls)
            {
                if (match(item))
                {
                    itemRemove = item;
                }
            }
            base.Controls.Remove(itemRemove);
            if (IsAutomaticShowHide)
            {
                base.Visible = base.Controls.Count > 0 ? true : false;
            }
        }
Beispiel #10
0
        /// <summary>
        /// 文件发送完成时触发事件
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnFileSendComplete(FileSendEventArgs e)
        {
            FileTransfersItem item =
                e.SendFileManager.Tag as FileTransfersItem;

            if (item != null)
            {
                Form.ActiveForm.BeginInvoke(new MethodInvoker(delegate()
                {
                    fileTansfersContainer.RemoveItem(item);
                    item.Dispose();
                }));
            }
            if (FileSendComplete != null)
            {
                FileSendComplete(this, e);
            }
        }
Beispiel #11
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 #12
0
        /// <summary>
        /// 添加发送文件控件Item
        /// </summary>
        /// <param name="sendFileManager"></param>
        /// <param name="image"></param>
        public void AddSendItems(SendFileManager sendFileManager, Image image)
        {
            FileTransfersItem item = fileTansfersContainer.AddItem(
                sendFileManager.MD5,
                "发送文件",
                sendFileManager.Name,
                image,
                sendFileManager.Length,
                FileTransfersItemStyle.Send);

            item.BaseColor              = Color.FromArgb(224, 224, 224);
            item.BorderColor            = _borderColor;
            item.ProgressBarBarColor    = _progressBarBarColor;
            item.ProgressBarBorderColor = _progressBarBorderColor;
            item.ProgressBarTextColor   = _progressBarTextColor;
            item.CancelButtonClick     += new EventHandler(ItemSendCancelButtonClick);
            item.Tag            = sendFileManager;
            sendFileManager.Tag = item;
        }
Beispiel #13
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);
            }
        }
Beispiel #14
0
        public FileTransfersItem AddItem(string text, string fileName, Image image, long fileSize, FileTransfersItemStyle style)
        {
            FileTransfersItem item = new FileTransfersItem();

            item.Text              = text;
            item.FileName          = fileName;
            item.Image             = image;
            item.FileSize          = fileSize;
            item.Style             = style;
            item.FileTransfersText = this.FileTransfersItemText;
            item.Dock              = DockStyle.Top;
            base.SuspendLayout();
            base.Controls.Add(item);
            item.BringToFront();
            base.ResumeLayout(true);
            if (IsAutomaticShowHide)
            {
                base.Visible = base.Controls.Count > 0 ? true : false;
            }
            return(item);
        }
Beispiel #15
0
        /// <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);
            }
        }