示例#1
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);
     }
 }
示例#2
0
        /// <summary>
        /// 发送文件
        /// </summary>
        /// <param name="fileName">文件路径(包含完整的文件名)</param>
        public void SendFile(string fileName)
        {
            SendFileManager sendFileManager = new SendFileManager(fileName);
            Image           img             = Icon.ExtractAssociatedIcon(fileName).ToBitmap();

            SendFile(sendFileManager, img);
        }
示例#3
0
 public FileSendBufferEventArgs(
     SendFileManager sendFileManager,
     int size)
     : base()
 {
     _sendFileManager = sendFileManager;
     _size            = size;
 }
示例#4
0
        /// <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);
        }
示例#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);
        }
示例#6
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;
        }
示例#7
0
 public FileSendEventArgs(SendFileManager sendFileManager)
     : base()
 {
     _sendFileManager = sendFileManager;
 }
示例#8
0
 /// <summary>
 /// 返回是否允许发送,在发送列表中的文件不能重复发送(避免文件被占用导致错误)
 /// </summary>
 /// <param name="sendFileManager"></param>
 /// <returns></returns>
 public bool CanSend(SendFileManager sendFileManager)
 {
     return(!SendFileManagerList.ContainsKey(sendFileManager.MD5));
 }