Esempio n. 1
0
        private void UpdateSegmentsInserting(Downloader d, ListViewItem newSelection)
        {
            lastSelection = newSelection;


            List <Block> blocks = new List <Block>();

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

                item.Text = d.Segments[i].CurrentTry.ToString();
                item.SubItems.Add(String.Format("{0:0.##}%", d.Segments[i].Progress));
                item.SubItems.Add(ByteFormatter.ToString(d.Segments[i].Transfered));
                item.SubItems.Add(ByteFormatter.ToString(d.Segments[i].TotalToTransfer));
                item.SubItems.Add(ByteFormatter.ToString(d.Segments[i].InitialStartPosition));
                item.SubItems.Add(ByteFormatter.ToString(d.Segments[i].EndPosition));
                item.SubItems.Add(String.Format("{0:0.##}", d.Segments[i].Rate / 1024.0));
                item.SubItems.Add(TimeSpanFormatter.ToString(d.Segments[i].Left));
                item.SubItems.Add(d.Segments[i].State.ToString());
                item.SubItems.Add(d.Segments[i].CurrentURL);

                blocks.Add(new Block(d.Segments[i].TotalToTransfer, (float)d.Segments[i].Progress));
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        private void UpdateSegmentsWithoutInsert(Downloader d)
        {
            for (int i = 0; i < d.Segments.Count; i++)
            {
                lvwSegments.Items[i].SubItems[0].Text = d.Segments[i].CurrentTry.ToString();
                lvwSegments.Items[i].SubItems[1].Text = String.Format("{0:0.##}%", d.Segments[i].Progress);
                lvwSegments.Items[i].SubItems[2].Text = ByteFormatter.ToString(d.Segments[i].Transfered);
                lvwSegments.Items[i].SubItems[3].Text = ByteFormatter.ToString(d.Segments[i].TotalToTransfer);
                lvwSegments.Items[i].SubItems[4].Text = ByteFormatter.ToString(d.Segments[i].InitialStartPosition);
                lvwSegments.Items[i].SubItems[5].Text = ByteFormatter.ToString(d.Segments[i].EndPosition);
                lvwSegments.Items[i].SubItems[6].Text = String.Format("{0:0.##}", d.Segments[i].Rate / 1024.0);
                lvwSegments.Items[i].SubItems[7].Text = TimeSpanFormatter.ToString(d.Segments[i].Left);
                if (d.Segments[i].LastError != null)
                {
                    lvwSegments.Items[i].SubItems[8].Text = d.Segments[i].State.ToString() + ", " + d.Segments[i].LastError.Message;
                }
                else
                {
                    lvwSegments.Items[i].SubItems[8].Text = d.Segments[i].State.ToString();
                }
                lvwSegments.Items[i].SubItems[9].Text = d.Segments[i].CurrentURL;

                this.blockedProgressBar1.BlockList[i].BlockSize       = d.Segments[i].TotalToTransfer;
                this.blockedProgressBar1.BlockList[i].PercentProgress = (float)d.Segments[i].Progress;
            }

            this.blockedProgressBar1.Refresh();
        }
Esempio n. 4
0
        public void UpdateList()
        {
            for (int i = 0; i < lvwDownloads.Items.Count; i++)
            {
                ListViewItem item = lvwDownloads.Items[i];
                if (item == null)
                {
                    return;
                }
                Downloader d = mapItemToDownload[item] as Downloader;
                if (d == null)
                {
                    return;
                }

                DownloaderState state;

                if (item.Tag == null)
                {
                    state = DownloaderState.Working;
                }
                else
                {
                    state = (DownloaderState)item.Tag;
                }

                if (state != d.State ||
                    state == DownloaderState.Working ||
                    state == DownloaderState.WaitingForReconnect)
                {
                    item.SubItems[1].Text = ByteFormatter.ToString(d.FileSize);
                    item.SubItems[2].Text = ByteFormatter.ToString(d.Transfered);
                    item.SubItems[3].Text = String.Format("{0:0.##}%", d.Progress);
                    item.SubItems[4].Text = TimeSpanFormatter.ToString(d.Left);
                    item.SubItems[5].Text = String.Format("{0:0.##}", d.Rate / 1024.0);

                    if (d.LastError != null)
                    {
                        item.SubItems[7].Text = d.State.ToString() + ", " + d.LastError.Message;
                    }
                    else
                    {
                        if (String.IsNullOrEmpty(d.StatusMessage))
                        {
                            item.SubItems[7].Text = d.State.ToString();
                        }
                        else
                        {
                            item.SubItems[7].Text = d.State.ToString() + ", " + d.StatusMessage;
                        }
                    }

                    item.SubItems[8].Text = GetResumeStr(d);
                    item.SubItems[9].Text = d.ResourceLocation.URL;
                    item.Tag = d.State;
                }
            }

            UpdateSegments();
        }
Esempio n. 5
0
        public void RefreshDownloaderData()
        {
            lock (_lockObj)
            {
                if (_downloader.State == DownloaderState.Preparing)
                {
                    lblStatus.Text = "Preparing";
                    return;
                }

                lblUrl.Text    = _downloader.ResourceLocation.URL;
                lblStatus.Text = _downloader.LastError != null
                    ? _downloader.State.ToString() + ", " + _downloader.LastError.Message
                    : _downloader.State.ToString();

                toggleStateButton.Label = _downloader.State == DownloaderState.Working ? "Pause" : "Resume";

                progressBar.Fraction = _downloader.Progress / 100.0;
                lblTransferred.Text  = string.Format("{0} ({1}%)", ByteFormatter.ToString(_downloader.Transfered),
                                                     _downloader.Progress);
                lblTransferRate.Text = TransferRateFormatter.ToString(_downloader.Rate);

                if (_downloader.RemoteFileInfo == null)
                {
                    return;
                }

                lblFileSize.Text  = ByteFormatter.ToString(_downloader.RemoteFileInfo.FileSize);
                lblResumable.Text = _downloader.RemoteFileInfo == null
                    ? "N/A"
                    : (_downloader.RemoteFileInfo.AcceptRanges ? "Yes" : "No");
                lblTimeLeft.Text = TimeSpanFormatter.ToString(_downloader.Left);
            }
        }
Esempio n. 6
0
        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();
        }
Esempio n. 7
0
        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();

            //ListViewItem.ListViewSubItem subItem;

            item.ImageIndex = FileTypeImageList.GetImageIndexByExtention(ext);
            //lvwDownloads.Columns["columnFile"].ImageIndex = FileTypeImageList.GetImageIndexByExtention(ext);
            //lvwDownloads.Columns[1].ImageIndex = FileTypeImageList.GetImageIndexByExtention(ext);

            //item.Text = Path.GetFileName(d.LocalFile);
            //item.Text = d.Id.ToString();
            item.Text = (d.OrderedIndex + 1).ToString();

            // Id
            item.SubItems.Add(d.Id.ToString());
            //File
            item.SubItems.Add(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);
        }
Esempio n. 8
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;
            }
        }
Esempio n. 9
0
 private void Fill(Segment s)
 {
     CurrentTry           = s.CurrentTry;
     Progress             = String.Format("{0:0.##}%", s.Progress);
     ProgressInt          = (int)s.Progress;
     Transferred          = ByteFormatter.ToString(s.Transfered);
     TotalToTransfer      = ByteFormatter.ToString(s.TotalToTransfer);
     InitialStartPosition = ByteFormatter.ToString(s.InitialStartPosition);
     EndPosition          = ByteFormatter.ToString(s.EndPosition);
     TransferRate         = TransferRateFormatter.ToString(s.Rate);
     TimeLeft             = TimeSpanFormatter.ToString(s.Left);
     if (s.LastError != null)
     {
         StateMessage = s.State.ToString() + ", " + s.LastError.Message;
     }
     else
     {
         StateMessage = s.State.ToString();
     }
     CurrentUrl = s.CurrentURL;
 }
Esempio n. 10
0
        void Fill(Downloader d)
        {
            FileName = System.IO.Path.GetFileName(d.LocalFile);
            // size
            FileSize = ByteFormatter.ToString(d.FileSize);
            // completed
            Transferred = ByteFormatter.ToString(d.Transfered);
            // progress
            Progress = String.Format("{0:0.##}%", d.Progress);
            // left
            TimeLeft = TimeSpanFormatter.ToString(d.Left);
            // rate
            TransferRate = String.Format("{0:0.##}", d.Rate / 1024.0);
            // added
            DateAdded = d.CreatedDateTime.ToShortDateString() + " " + d.CreatedDateTime.ToShortTimeString();
            // resume
            SupportsResume = DownloadList.GetResumeStr(d);
            // url
            Url = d.ResourceLocation.URL;

            SaveTo = d.LocalFile;

            if (d.LastError != null)
            {
                StateMessage = d.State.ToString() + ", " + d.LastError.Message;
            }
            else
            {
                if (String.IsNullOrEmpty(d.StatusMessage))
                {
                    StateMessage = d.State.ToString();
                }
                else
                {
                    StateMessage = d.State.ToString() + ", " + d.StatusMessage;
                }
            }

            Tag = d.State;
        }
Esempio n. 11
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);
            }
        }
Esempio n. 12
0
        public void UpdateList(bool all = true)
        {
            for (int i = 0; i < lvwDownloads.Items.Count; i++)
            {
                ListViewItem item = lvwDownloads.Items[i];
                if (item == null)
                {
                    return;
                }
                //Downloader d = mapItemToDownload[item] as Downloader;
                Downloader d = DownloadManager.Instance.GetOrderedDownloader(item.Index);
                if (d == null)
                {
                    return;
                }

                DownloaderState state;

                if (item.Tag == null)
                {
                    state = DownloaderState.Working;
                }
                else
                {
                    state = (DownloaderState)item.Tag;
                }

                if (all || state != d.State || state == DownloaderState.Working || state == DownloaderState.WaitingForReconnect)
                {
                    item.Text = (d.OrderedIndex + 1).ToString();
                    int indexColumnSize = 3;
                    int indexColumn     = indexColumnSize;
                    item.SubItems[indexColumn++].Text = ByteFormatter.ToString(d.FileSize);
                    item.SubItems[indexColumn++].Text = ByteFormatter.ToString(d.Transfered);
                    item.SubItems[indexColumn++].Text = String.Format("{0:0.##}%", d.Progress);
                    item.SubItems[indexColumn++].Text = TimeSpanFormatter.ToString(d.Left);
                    item.SubItems[indexColumn++].Text = String.Format("{0:0.##}", d.Rate / 1024.0);
                    indexColumn++; // column Added
                    if (d.LastError != null)
                    {
                        item.SubItems[indexColumn].Text = d.State.ToString() + ", " + d.LastError.Message;
                    }
                    else
                    {
                        if (String.IsNullOrEmpty(d.StatusMessage))
                        {
                            item.SubItems[indexColumn].Text = d.State.ToString();
                        }
                        else
                        {
                            item.SubItems[indexColumn].Text = d.State.ToString() + ", " + d.StatusMessage;
                        }
                    }
                    indexColumn++; // column State

                    item.SubItems[indexColumn++].Text = GetResumeStr(d);
                    item.SubItems[indexColumn++].Text = d.ResourceLocation.URL;
                    item.Tag = d.State;
                }
            }

            UpdateSegments();
        }