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(); } }
protected virtual void OnDownloadRemove(Downloader d) { if (DownloadRemove!=null) { DownloadRemove(this, new DownloadEventArgs(d)); } }
protected virtual void OnDownloadEndWithError(Downloader d) { if (DownloadEndWithError!=null) { DownloadEndWithError(this, new DownloadEventArgs(d)); } }
protected virtual void OnDownloadPaused(Downloader d) { if (DownloadPaused!=null) { DownloadPaused(this, new DownloadEventArgs(d)); } }
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; }
/// <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); }
/// <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; }
public SegmentEventArgs(Downloader download, Segment segment) : base(download) { this.segment = segment; }
public DownloadEventArgs(Downloader downloader) { this.downloader = downloader; }
/// <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; }
/// <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); }