public void BindDownloader(AbstractDownloader downloader) { if (downloader == Downloader) { return; } if (Downloader != null) { ClearDownloaderBinding(); } Downloader = downloader; if (downloader == null) { return; } Downloader.DownloadTask.PropertyChanged += DownloadTask_PropertyChanged; DownloadTask_PropertyChanged(Downloader.DownloadTask, null); TaskNameTextBlock.Text = downloader.DownloadTask.DestinationFileName; if (downloader.DownloadTask.Target is HttpTarget httpTarget) { TaskHyperlink.Text = httpTarget.Uri.ToString(); } else if (downloader.DownloadTask.Target is TorrentTarget torrentTarget) { TaskHyperlink.Text = torrentTarget.DisplayedUri.ToString(); } DisposeButton.IsEnabled = true; Downloader.StatusChanged += StatusChanged; StatusChanged(downloader, downloader.Status); Downloader.Progress.ProgressChanged += ProgressChanged; ProgressChanged(downloader.Progress, null); Downloader.Speed.Updated += SpeedUpdated; SpeedUpdated(downloader.Speed); BasicLabelCollection.Add(new TaskDetailPageLabel(CreationTimeText, downloader.DownloadTask.CreationTime.ToLocalTime().ToString("F"))); BasicLabelCollection.Add(new TaskDetailPageLabel(TargetTypeText, downloader.DownloadTask.Target.GetType().Name)); BasicLabelCollection.Add(new TaskDetailPageLabel(DownloaderTypeText, downloader.GetType().Name)); if (downloader.Progress is IMeasurableProgress progress) { BasicLabelCollection.Add(new TaskDetailPageLabel(TotalSizeText, progress.TotalSize.SizedString())); } }
public void ClearDownloaderBinding() { Downloader.DownloadTask.PropertyChanged -= DownloadTask_PropertyChanged; Downloader.StatusChanged -= StatusChanged; Downloader.Speed.Updated -= SpeedUpdated; Downloader.Progress.ProgressChanged -= ProgressChanged; TaskNameTextBlock.Text = string.Empty; TaskHyperlink.Text = string.Empty; StartButton.IsEnabled = CancelButton.IsEnabled = DisposeButton.IsEnabled = false; StatusTextBlock.Text = string.Empty; ProgressTextBlock.Text = string.Empty; DownloadTimeTextBlock.Text = string.Empty; BasicLabelCollection.Clear(); DynamicLabelCollection.Clear(); Downloader = null; }