Beispiel #1
0
        public DownloadTaskStatistics GetDownloadTaskStatistics()
        {
            double   downloadRate       = 0;
            bool     isDownloadFinished = Count != 0;
            long     remainingTransfer  = 0;
            long     transferedDownload = 0;
            DateTime?downloadFinishDate = null;

            for (int i = 0; i < Count; i++)
            {
                ISegmentDownloadTask   segmentDownloadTask   = this[i];
                ISegmentDownloaderInfo segmentDownloaderInfo = segmentDownloadTask.SegmentDownloaderInfo;
                downloadRate       += segmentDownloaderInfo.DownloadRate.GetValueOrDefault(0);
                remainingTransfer  += segmentDownloaderInfo.RemainingTransfer;
                transferedDownload += segmentDownloaderInfo.TransferedDownload;

                if (!segmentDownloaderInfo.IsDownloadFinished)
                {
                    isDownloadFinished = false;
                }
                else
                {
                    if (downloadFinishDate.HasValue)
                    {
                        downloadFinishDate = downloadFinishDate > segmentDownloaderInfo.DownloadFinishDate ? downloadFinishDate : segmentDownloaderInfo.DownloadFinishDate;
                    }
                    else
                    {
                        downloadFinishDate = segmentDownloaderInfo.DownloadFinishDate;
                    }
                }
            }

            TimeSpan remainingTime = Math.Abs(downloadRate) < 0.001D ? TimeSpan.MaxValue : TimeSpan.FromSeconds(remainingTransfer / downloadRate);

            return(new DownloadTaskStatistics
            {
                DownloadRate = downloadRate,
                IsDownloadFinished = isDownloadFinished,
                DownloadFinishDate = downloadFinishDate,
                RemainingTransfer = remainingTransfer,
                RemainingTime = remainingTime,
                TransferedDownload = transferedDownload,
                Segments = new SegmentDownloaderInfoCollection(this.Select(x => x.SegmentDownloaderInfo))
            });
        }
Beispiel #2
0
        private void UpdateSegmentsWithoutInsert(SegmentDownloaderInfoCollection segmentDownloaderInfoCollection)
        {
            for (int i = 0; i < segmentDownloaderInfoCollection.Count; i++)
            {
                ISegmentDownloaderInfo segmentDownloaderInfo = segmentDownloaderInfoCollection[i];
                ListViewItem           listViewItem          = lvwDownloadTaskSegments.Items[i];
                listViewItem.SubItems[0].Text = string.Format("{0:0.##}%", segmentDownloaderInfo.DownloadProgress);
                listViewItem.SubItems[1].Text = ByteFormatter.ToString(segmentDownloaderInfo.TransferedDownload);
                listViewItem.SubItems[2].Text = ByteFormatter.ToString(segmentDownloaderInfo.EndPosition - segmentDownloaderInfo.StartPosition);
                listViewItem.SubItems[3].Text = ByteFormatter.ToString(segmentDownloaderInfo.StartPosition);
                listViewItem.SubItems[4].Text = ByteFormatter.ToString(segmentDownloaderInfo.EndPosition);
                listViewItem.SubItems[5].Text = string.Format("{0:0.##}", segmentDownloaderInfo.DownloadRate / 1024.0);
                listViewItem.SubItems[6].Text = TimeSpanFormatter.ToString(segmentDownloaderInfo.RemainingTime);
                listViewItem.SubItems[7].Text = segmentDownloaderInfo.LastException != null?string.Format(CultureInfo.CurrentCulture, "{0}, {1}", segmentDownloaderInfo.State, segmentDownloaderInfo.LastException.Message) : segmentDownloaderInfo.State.ToString();

                listViewItem.SubItems[8].Text = segmentDownloaderInfo.Uri.OriginalString;
            }
        }
Beispiel #3
0
        private void UpdateSegmentsInserting(ListViewItem newSelection, SegmentDownloaderInfoCollection segmentDownloaderInfoCollection)
        {
            m_LastDownloadTaskSelection = newSelection;

            lvwDownloadTaskSegments.Items.Clear();

            for (int i = 0; i < segmentDownloaderInfoCollection.Count; i++)
            {
                ListViewItem item = new ListViewItem();

                ISegmentDownloaderInfo segmentDownloaderInfo = segmentDownloaderInfoCollection[i];
                item.Text = string.Format("{0:0.##}%", segmentDownloaderInfo.DownloadProgress);
                item.SubItems.Add(ByteFormatter.ToString(segmentDownloaderInfo.TransferedDownload));
                item.SubItems.Add(ByteFormatter.ToString(segmentDownloaderInfo.EndPosition - segmentDownloaderInfo.StartPosition));
                item.SubItems.Add(ByteFormatter.ToString(segmentDownloaderInfo.StartPosition));
                item.SubItems.Add(ByteFormatter.ToString(segmentDownloaderInfo.EndPosition));
                item.SubItems.Add(string.Format("{0:0.##}", segmentDownloaderInfo.DownloadRate / 1024.0));
                item.SubItems.Add(TimeSpanFormatter.ToString(segmentDownloaderInfo.RemainingTime));
                item.SubItems.Add(segmentDownloaderInfo.State.ToString());
                item.SubItems.Add(segmentDownloaderInfo.Uri.OriginalString);

                lvwDownloadTaskSegments.Items.Add(item);
            }
        }