public void AddNewDownloadTask(DownloadTaskInfo downloadTaskInfo) { Guid newTaskGuid = m_DownloadHelper.AddNewDownloadTask(downloadTaskInfo); ListViewItem item = new ListViewItem(); DownloadTaskStatistics downloadTaskStatistics = m_DownloadHelper.GetDownloadTaskStatistics(newTaskGuid); string fileName = downloadTaskInfo.DownloadFileInfo.FileName; string fileExtension = Path.GetExtension(fileName); item.ImageIndex = FileTypeImageList.GetImageIndexByExtention(fileExtension); item.Text = Path.GetFileName(fileName); item.SubItems.Add(ByteFormatter.ToString(downloadTaskStatistics.FileSize)); item.SubItems.Add(ByteFormatter.ToString(downloadTaskStatistics.TransferedDownload)); item.SubItems.Add(GetDownloadProgressText(downloadTaskStatistics)); item.SubItems.Add(TimeSpanFormatter.ToString(downloadTaskStatistics.RemainingTime)); item.SubItems.Add("0"); item.SubItems.Add("0"); item.SubItems.Add(string.Format(CultureInfo.CurrentCulture, "{0} {1}", downloadTaskStatistics.CreatedDate.ToShortDateString(), downloadTaskStatistics.CreatedDate.ToShortTimeString())); item.SubItems.Add(downloadTaskStatistics.DownloadTaskState.ToString()); item.SubItems.Add(GetResumeText(downloadTaskStatistics)); item.SubItems.Add(downloadTaskStatistics.FileUri.OriginalString); m_DownloadTaskItemMap[item] = newTaskGuid; lvwDownloadTasks.Items.Add(item); }
private void AddDownload(Downloader d) { d.RestartingSegment += new EventHandler <SegmentEventArgs>(download_RestartingSegment); d.SegmentStoped += new EventHandler <SegmentEventArgs>(download_SegmentEnded); d.SegmentFailed += new EventHandler <SegmentEventArgs>(download_SegmentFailed); d.SegmentStarted += new EventHandler <SegmentEventArgs>(download_SegmentStarted); d.InfoReceived += new EventHandler(download_InfoReceived); d.SegmentStarting += new EventHandler <SegmentEventArgs>(Downloader_SegmentStarting); string ext = Path.GetExtension(d.LocalFile); ListViewItem item = new ListViewItem(); item.ImageIndex = FileTypeImageList.GetImageIndexByExtention(ext); item.Text = Path.GetFileName(d.LocalFile); // size item.SubItems.Add(ByteFormatter.ToString(d.FileSize)); // completed item.SubItems.Add(ByteFormatter.ToString(d.Transfered)); // progress item.SubItems.Add(String.Format("{0:0.##}%", d.Progress)); // left item.SubItems.Add(TimeSpanFormatter.ToString(d.Left)); // rate item.SubItems.Add("0"); // added item.SubItems.Add(d.CreatedDateTime.ToShortDateString() + " " + d.CreatedDateTime.ToShortTimeString()); // state item.SubItems.Add(d.State.ToString()); // resume item.SubItems.Add(GetResumeStr(d)); // url item.SubItems.Add(d.ResourceLocation.URL); mapDownloadToItem[d] = item; mapItemToDownload[item] = d; lvwDownloads.Items.Add(item); }