private void OnDownloadStatusChange(Feed downloadList, Feed entry, DownloadState downloadState, double percentage) { if (Entries.Count <= 0 || _onStatusChanged == null) return; if (downloadState == DownloadState.Deleted) { _settings.SaveDownloadLists(this); UpdateStatus(downloadList, entry, DownloadState.AllFinished, 100.0); return; } var finishedCount = 0; var average = 0.0; foreach (var en in Entries) { if (en.DownloadState == DownloadState.AllFinished) finishedCount++; average += en.Percentage; } average = average/Entries.Count; if (downloadState == DownloadState.DownloadProgressChanged) UpdateStatus(downloadList, entry, DownloadState.DownloadProgressChanged, average); else if (finishedCount == Entries.Count) UpdateStatus(downloadList, entry, DownloadState.AllFinished, 100.0); else if (Entries.Count == 1 && downloadState == DownloadState.AllStart) UpdateStatus(downloadList, entry, DownloadState.AllStart, 0.0); else if(_onStatusChanged != null && !(downloadState == DownloadState.AllFinished || downloadState == DownloadState.AllStart || downloadState == DownloadState.DownloadProgressChanged )) _onStatusChanged(downloadList, entry, downloadState, percentage); _settings.SaveDownloadLists(this); }
public MainWindow() { InitializeComponent(); _lists = new DownloadLists(OnDownloadStatusChange); //DownloadStatusGrid.DataContext = _lists; //DownloadStatusGrid.ItemsSource = _lists.Entries; Navigate(new Uri("http://www.youtube.com/")); }
private void OnDownloadStatusChanged(Feed feed, DownloadState downloadState, double percentage) { var finishedCount = 0; var downloadCount = 0; var average = 0.0; if (downloadState == DownloadState.Deleted) { var entry = feed as YoutubeEntry; if (entry != null) { entry.OnEntryDownloadStatusChange = null; Entries.Remove(entry); } return; } foreach (var en in Entries) { if (en.DownloadState == DownloadState.Ready || en.DownloadState == DownloadState.Error) finishedCount++; if ( !(en.DownloadState == DownloadState.Ready || en.DownloadState == DownloadState.Error || en.DownloadState == DownloadState.Initialized)) downloadCount++; average += en.Percentage; } average = average/Entries.Count; if (OnListDownloadStatusChange != null) { DownloadState = downloadState; if (downloadState == DownloadState.DownloadProgressChanged) { Percentage = average; } if (downloadCount == 0 && finishedCount == Entries.Count) DownloadState = DownloadState.AllFinished; if (Entries.Count == 1 && downloadState == DownloadState.TitleChanged) { Title = Entries[0].Title; } OnListDownloadStatusChange(this, feed, DownloadState, Percentage); } if (downloadCount != _poolSize) DownloadFirst(); }
private void OnAudioConversionStatusChange(Feed feed, DownloadState downloadState, double percentage) { UpdateStatus(downloadState, percentage); }
private void UpdateStatus(Feed downloadItems, Feed entry, DownloadState downloadState, double percentage) { try { switch (downloadState) { case DownloadState.AllStart: ProgressBar.Value = 0; break; case DownloadState.AllFinished: Log.Text = "DONE!"; ProgressBar.Value = 0; downloadItems.Entries.Clear(); return; case DownloadState.DownloadProgressChanged: ProgressBar.Value = percentage; break; case DownloadState.TitleChanged: MixpanelTrack("Download", new {entry.Title, _settings.Guid}); break; } Log.Text = (entry != null) ? entry.ToString() : ""; } catch {} }
private void OnDownloadStatusChange(Feed downloadItems, Feed entry, DownloadState downloadState, double percentage) { try { Dispatcher.Invoke(() => UpdateStatus(downloadItems, entry, downloadState, percentage)); } catch {} }
private void UpdateStatus(Feed downloadList, Feed entry, DownloadState state, double percentage) { DownloadState = state; Percentage = percentage; if (_onStatusChanged != null) _onStatusChanged(downloadList, entry, DownloadState, Percentage); }
private static void SetExecutionStatus(Feed feed, DownloadEntry entry) { feed.ExecutionStatus = entry.ExecutionStatus; if (feed.ExecutionStatus== ExecutionStatus.Deleted) feed.DownloadState = DownloadState.Deleted; }
private void OnDownloadStatusChange(Feed downloadItems, Feed entry, DownloadState downloadState, double percentage) { Dispatcher.Invoke(new Action(() => { switch (downloadState) { case DownloadState.AllStart: Log.Text = "START"; ProgressBar.Value = 0; break; case DownloadState.AllFinished: Log.Text = "DONE!"; ProgressBar.Value = 0; downloadItems.Entries.Clear(); return; case DownloadState.DownloadProgressChanged: ProgressBar.Value = percentage; break; } if (entry != null) Log.Text = entry.ToString(); })); }