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); }
public void UpdateList() { ListView.ListViewItemCollection listViewItemCollection = lvwDownloadTasks.Items; for (int i = 0; i < listViewItemCollection.Count; i++) { ListViewItem item = listViewItemCollection[i]; if (item == null) { return; } Guid guid = m_DownloadTaskItemMap[item]; DownloadTaskStatistics downloadTaskStatistics = m_DownloadHelper.GetDownloadTaskStatistics(guid); if (downloadTaskStatistics == null) { return; } DownloadTaskState state; if (item.Tag == null) { state = DownloadTaskState.Working; } else { state = (DownloadTaskState)item.Tag; } if (state != downloadTaskStatistics.DownloadTaskState || state == DownloadTaskState.Working || state == DownloadTaskState.WaitingForReconnect) { item.SubItems[1].Text = ByteFormatter.ToString(downloadTaskStatistics.FileSize); item.SubItems[2].Text = ByteFormatter.ToString(downloadTaskStatistics.TransferedDownload); item.SubItems[3].Text = GetDownloadProgressText(downloadTaskStatistics); item.SubItems[4].Text = TimeSpanFormatter.ToString(downloadTaskStatistics.RemainingTime); item.SubItems[5].Text = GetDownloadRateText(downloadTaskStatistics); item.SubItems[6].Text = GetAverageDownloadRateText(downloadTaskStatistics); if (!string.IsNullOrWhiteSpace(downloadTaskStatistics.LastError)) { item.SubItems[8].Text = string.Format(CultureInfo.CurrentCulture, "{0}, {1}", downloadTaskStatistics.DownloadTaskState, downloadTaskStatistics.LastError); } else { item.SubItems[8].Text = string.IsNullOrEmpty(downloadTaskStatistics.StatusMessage) ? downloadTaskStatistics.DownloadTaskState.ToString() : string.Format(CultureInfo.CurrentCulture, "{0}, {1}", downloadTaskStatistics.DownloadTaskState, downloadTaskStatistics.StatusMessage); } item.SubItems[9].Text = GetResumeText(downloadTaskStatistics); item.SubItems[10].Text = downloadTaskStatistics.FileUri.OriginalString; item.Tag = downloadTaskStatistics.DownloadTaskState; } } UpdateSegments(); }
private void UpdateSegments() { try { lvwDownloadTaskSegments.BeginUpdate(); if (lvwDownloadTasks.SelectedItems.Count == 1) { ListViewItem newDownloadTaskSelection = lvwDownloadTasks.SelectedItems[0]; Guid guid = m_DownloadTaskItemMap[newDownloadTaskSelection]; DownloadTaskStatistics downloadTaskStatistics = m_DownloadHelper.GetDownloadTaskStatistics(guid); if (m_LastDownloadTaskSelection == newDownloadTaskSelection) { if (downloadTaskStatistics.Segments.Count == lvwDownloadTaskSegments.Items.Count) { UpdateSegmentsWithoutInsert(downloadTaskStatistics.Segments); } else { UpdateSegmentsInserting(newDownloadTaskSelection, downloadTaskStatistics.Segments); } } else { UpdateSegmentsInserting(newDownloadTaskSelection, downloadTaskStatistics.Segments); } } else { m_LastDownloadTaskSelection = null; lvwDownloadTaskSegments.Items.Clear(); } } finally { lvwDownloadTaskSegments.EndUpdate(); } }
private static string GetDownloadProgressText(DownloadTaskStatistics downloadTaskStatistics) { return(string.Format(CultureInfo.CurrentCulture, "{0:0.##}%", downloadTaskStatistics.DownloadProgress)); }
private static string GetResumeText(DownloadTaskStatistics downloadTaskStatistics) { return(downloadTaskStatistics.IsDownloadResumable ? "Yes" : "No"); }
private static string GetAverageDownloadRateText(DownloadTaskStatistics downloadTaskStatistics) { return(string.Format(CultureInfo.CurrentCulture, "{0:0.##}", downloadTaskStatistics.AverageDownloadRate / 1024.0)); }
private static string GetDownloadProgressText(DownloadTaskStatistics downloadTaskStatistics) { return string.Format(CultureInfo.CurrentCulture, "{0:0.##}%", downloadTaskStatistics.DownloadProgress); }
private static string GetResumeText(DownloadTaskStatistics downloadTaskStatistics) { return downloadTaskStatistics.IsDownloadResumable ? "Yes" : "No"; }
private static string GetAverageDownloadRateText(DownloadTaskStatistics downloadTaskStatistics) { return string.Format(CultureInfo.CurrentCulture, "{0:0.##}", downloadTaskStatistics.AverageDownloadRate / 1024.0); }