public TaskImageDownloadEventArgs(DownloadTask task, ImageViewState view, GalleryImagePath image, byte[] data, int index, int retryCount) { this.Task = task; this.View = view; this.Image = image; this.Data = data; this.Index = index; this.RetryCount = retryCount; }
private byte[] Download(GalleryAgent agent, ImageViewState imageViewState, GalleryImagePath imagePath, GalleryParameterValues values) { using (var source = new CancellationTokenSource()) { var cancelSources = this.CancelSources; try { lock (cancelSources) { this.ThrowIfCancelRequested(); cancelSources.Add(source); } var downloadRequest = agent.CreateImageRequest(imageViewState.View, imagePath, values); using (var response = agent.Explorer.Request(downloadRequest, source)) { if (response.StatusCode == HttpStatusCode.ServiceUnavailable) { throw new HttpStatusCodeException(response.StatusCode); } imageViewState.Length = response.ContentLength; imageViewState.Position = 0L; using (var responseStream = response.ReadAsStream()) { return(this.Download(imageViewState, responseStream)); } } } finally { lock (cancelSources) { cancelSources.Remove(source); } } } }