/// <summary> /// For more information, see: /// http://www.w3.org/html/wg/drafts/html/master/embedded-content.html#update-the-image-data /// </summary> void GetImage(Url source) { if (source.IsInvalid) { source = null; } else if (_img != null && source.Equals(_img.Source)) { return; } if (_download != null && !_download.IsCompleted) { _download.Cancel(); } var document = Owner; if (source != null && document != null) { var loader = document.Loader; if (loader != null) { var request = this.CreateRequestFor(source); var download = loader.DownloadAsync(request); var task = this.ProcessResource <IImageInfo>(download, result => _img = result); document.DelayLoad(task); _download = download; } } }
/// <summary> /// Cancels the outstanding download, if any. /// </summary> public void Cancel() { if (_download != null && !_download.IsCompleted) { _download.Cancel(); } }
public void Abort() { if (_readyState == RequesterState.Loading) { _download.Cancel(); Fire(AbortEvent); } }
protected void StartDownload(ResourceRequest request) { if (_download != null && !_download.IsCompleted) { _download.Cancel(); } _download = _loader.DownloadAsync(request); }
void UpdateSource(String value) { //TODO More complex check if something is already loading (what is loading, cancel?, ...) //see: https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-load if (_download != null && !_download.IsCompleted) { _download.Cancel(); } var document = Owner; _network = MediaNetworkState.Idle; if (value != null && document != null) { var loader = document.Loader; if (loader != null) { var url = new Url(value); var request = this.CreateRequestFor(url); _network = MediaNetworkState.Loading; _download = loader.DownloadAsync(request); var task = this.ProcessResource <TResource>(_download, result => { _media = result; if (_media == null) { _network = MediaNetworkState.NoSource; } }); document.DelayLoad(task); } } }
void UpdateSource(String value) { if (_download != null && !_download.IsCompleted) { _download.Cancel(); } var document = Owner; if (!String.IsNullOrEmpty(value) && document != null) { var loader = document.Loader; if (loader != null) { var url = new Url(Source); var request = this.CreateRequestFor(url); var download = loader.DownloadAsync(request); var task = this.ProcessResource <IObjectInfo>(download, result => _obj = result); document.DelayLoad(task); _download = download; } } }
public void Build() { if (built) { return; } if (item == null) { built = true; return; } Grid DisplayGrid = new Grid(); DisplayGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); DisplayGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); DisplayGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); DisplayGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); DisplayGrid.RowDefinitions.Add(new RowDefinition()); DisplayGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); DisplayGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); DisplayGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(400) }); DisplayGrid.ColumnDefinitions.Add(new ColumnDefinition()); var margin = new Thickness(2.5); border = new Border { Margin = margin, BorderThickness = new Thickness(1) }; border.SetResourceReference(Border.BorderBrushProperty, "BlackBrush"); border.Child = DisplayGrid; Tile stopButton = new Tile { Width = 50, Height = 50, Margin = margin, Content = new PackIconModern { Width = 40, Height = 40, Kind = PackIconModernKind.Close }, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; stopButton.Click += async(s, e) => { var remove = await item.Cancel(); if (remove) { GlobalConsts.Downloads.Remove(this); } }; //Col 0: Grid.SetRow(stopButton, 0); Grid.SetRowSpan(stopButton, 6); Grid.SetColumn(stopButton, 0); Image image = new Image { Width = 200, Height = 112.5, Margin = margin, Source = new BitmapImage(new Uri(item.ImageUrl)), }; //Col 1: Grid.SetRow(image, 0); Grid.SetRowSpan(image, 6); Grid.SetColumn(image, 1); TextBlock title = new TextBlock { TextWrapping = TextWrapping.Wrap, Margin = margin, FontSize = 14, Text = item.Title }, currentTitle = new TextBlock { TextWrapping = TextWrapping.Wrap, Margin = margin, FontSize = 14 }, totalDownloaded = new TextBlock { TextWrapping = TextWrapping.Wrap, Margin = margin, FontSize = 14 }, currentStatus = new TextBlock { TextWrapping = TextWrapping.Wrap, Margin = margin, FontSize = 14 }, downloadSpeed = new TextBlock { TextWrapping = TextWrapping.Wrap, Margin = margin, FontSize = 14 }, downloadPrecent = new TextBlock { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; //Col 2: Grid.SetRow(title, 0); Grid.SetColumn(title, 2); Grid.SetRow(currentTitle, 1); Grid.SetColumn(currentTitle, 2); Grid.SetRow(totalDownloaded, 2); Grid.SetColumn(totalDownloaded, 2); Grid.SetRow(currentStatus, 3); Grid.SetColumn(currentStatus, 2); Grid.SetRow(downloadSpeed, 4); Grid.SetColumn(downloadSpeed, 2); Binding currentTitleBinding = new Binding { Source = item, Path = new PropertyPath("CurrentTitle"), UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.OneWay }, totalDownloadedBinding = new Binding { Source = item, Path = new PropertyPath("TotalDownloaded"), UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.OneWay }, currentStatusBinding = new Binding { Source = item, Path = new PropertyPath("CurrentStatus"), UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.OneWay }, downloadSpeedBinding = new Binding { Source = item, Path = new PropertyPath("CurrentDownloadSpeed"), UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.OneWay }, progressBinding = new Binding { Source = item, Path = new PropertyPath("CurrentProgressPrecent"), UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.OneWay }, downloadPrecentBinding = new Binding { Source = item, Path = new PropertyPath("CurrentProgressPrecent"), UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.OneWay }; Grid progressBarGrid = new Grid { Margin = margin }; MetroProgressBar progressBar = new MetroProgressBar { Width = 550, Height = 30, VerticalAlignment = VerticalAlignment.Center }; progressBarGrid.Children.Add(progressBar); progressBarGrid.Children.Add(downloadPrecent); //Col 3: Grid.SetRow(progressBarGrid, 0); Grid.SetRowSpan(progressBarGrid, 6); Grid.SetColumn(progressBarGrid, 3); currentTitle.SetBinding(TextBlock.TextProperty, currentTitleBinding); totalDownloaded.SetBinding(TextBlock.TextProperty, totalDownloadedBinding); currentStatus.SetBinding(TextBlock.TextProperty, currentStatusBinding); downloadSpeed.SetBinding(TextBlock.TextProperty, downloadSpeedBinding); progressBar.SetBinding(ProgressBar.ValueProperty, progressBinding); downloadPrecent.SetBinding(TextBlock.TextProperty, downloadPrecentBinding); //add everything to grid DisplayGrid.Children.Add(stopButton); DisplayGrid.Children.Add(image); DisplayGrid.Children.Add(title); DisplayGrid.Children.Add(currentTitle); DisplayGrid.Children.Add(totalDownloaded); DisplayGrid.Children.Add(currentStatus); DisplayGrid.Children.Add(downloadSpeed); DisplayGrid.Children.Add(progressBarGrid); built = true; }