Пример #1
0
        public void Add(Downloader d, bool autoStart)
        {
            d.StateChanged+=new EventHandler(task_StateChanged);
            using (locker.LockList(false))
            {
                downloads.Add(d);
            }

            OnDownloadAdd(d);

            if (autoStart)
            {
                d.Start();
            }
        }
Пример #2
0
 protected virtual void OnDownloadRemove(Downloader d)
 {
     if (DownloadRemove!=null)
     {
         DownloadRemove(this, new DownloadEventArgs(d));
     }
 }
Пример #3
0
 protected virtual void OnDownloadEndWithError(Downloader d)
 {
     if (DownloadEndWithError!=null)
     {
         DownloadEndWithError(this, new DownloadEventArgs(d));
     }
 }
Пример #4
0
 protected virtual void OnDownloadPaused(Downloader d)
 {
     if (DownloadPaused!=null)
     {
         DownloadPaused(this, new DownloadEventArgs(d));
     }
 }
Пример #5
0
        public Downloader Add(string url, string localFilePath, int segmentCount, bool autoStart, List<Segment> segments, DateTime createdtime)
        {
            Downloader task = new Downloader(url, localFilePath, segmentCount, segments, createdtime);

            Add(task, autoStart);

            return task;
        }
Пример #6
0
        /// <summary>
        /// 删除给定的任务
        /// </summary>
        /// <param name="task"></param>
        public void Remove(Downloader task)
        {
            if (task.State!=DownloadState.NeedToPrepare ||
                task.State!=DownloadState.paused ||
                task.State!=DownloadState.Ended)
            {
                task.Pause();
            }

            using (locker.LockList(false))
            {
                downloads.Remove(task);
            }

            OnDownloadRemove(task);
        }
Пример #7
0
        /// <summary>
        /// 按给定的参数添加新的任务
        /// </summary>
        /// <param name="url"></param>
        /// <param name="localFilePath"></param>
        /// <param name="segmentCount"></param>
        /// <param name="autoStart"></param>
        /// <returns></returns>
        public Downloader Add(string url, string localFilePath, int segmentCount, bool autoStart)
        {
            Downloader task = new Downloader(url, localFilePath, segmentCount);

            Add(task, autoStart);

            return task;
        }
Пример #8
0
 public SegmentEventArgs(Downloader download, Segment segment)
     : base(download)
 {
     this.segment = segment;
 }
Пример #9
0
 public DownloadEventArgs(Downloader downloader)
 {
     this.downloader = downloader;
 }
Пример #10
0
 /// <summary>
 /// 设置表示状态的图片
 /// </summary>
 /// <param name="task"></param>
 /// <param name="image"></param>
 private void SetStateImage(Downloader task,Image image)
 {
     Row row = taskToRow[task] as Row;
     row.Cells[0].Image = image;
 }
Пример #11
0
        /// <summary>
        /// 添加新的任务
        /// </summary>
        /// <param name="d"></param>
        private void AddTask(Downloader d)
        {
            d.SegmentFailed += new EventHandler<SegmentEventArgs>(d_SegmentFailed);
            d.SegmentStarted += new EventHandler<SegmentEventArgs>(d_SegmentStarted);
            d.SegmentStopped += new EventHandler<SegmentEventArgs>(d_SegmentStopped);
            d.SegmentsCreated += new EventHandler(d_SegmentsCreated);

            Row row = new Row();
            row.Cells.AddRange(new Cell[] {
                                            new Cell(),
                                            new Cell(d.FileName,d.FileIcon),
                                            new Cell((int)Math.Round(d.Progress)),
                                            new Cell(string.Format("{0:0.00}KB/s",d.Rate/1024.0f)),
                                            new Cell(ByteFormatter.ToString(d.DownloadedSize)),
                                            new Cell(ByteFormatter.ToString(d.FileSize)),
                                            new Cell(TimeSpanFormatter.ToString(d.LeftTime)),
                                            //new Cell(TimeSpanFormatter.ToString(d.UsedTime)),
                                            new Cell(d.FileTypeName)
                                            });

            row.Cells[1].ToolTipText = row.Cells[1].Text;
            rowToTask[row] = d;
            taskToRow[d] = row;

            if (d.State == DownloadState.NeedToPrepare ||
                d.State == DownloadState.paused || d.State==DownloadState.prepared)
            {
                SetStateImage(d, Resources.Paused);
            }
            else
            {
                SetStateImage(d, Resources.Working);
            }
            tasktable.TableModel.Rows.Add(row);
        }