private void ProcessResponse(HttpWebResponse response) { try { using (Stream responseStream = ((WebResponse)response).GetResponseStream()) { using (IsolatedStorageFile storeForApplication = IsolatedStorageFile.GetUserStoreForApplication()) { this.EnsureFoldersExist(storeForApplication); string fileNamePath = this.GetFileNamePath(this._fromByte); using (IsolatedStorageFileStream storageFileStream = storeForApplication.OpenFile(fileNamePath, FileMode.Create, FileAccess.Write)) this.ReadWriteFromStreamToStream(responseStream, (Stream)storageFileStream); this.ReportDownloadedChunk(fileNamePath); if (this._stopFlag || this.CopyAndReportWholeFileIfNeeded() || this._toByte >= this._contentLength - 1L) { return; } this._nextChunkDownloader = new ChunkDownloader(this._fileId, this._uri, this._toByte + 1L); this._nextChunkDownloader.StartDownloading(); } } } catch (Exception) { this._downloadFailed = true; } finally { response.Close(); } }
private void RequestCallback(IAsyncResult asyncResult) { try { HttpWebResponse response = (HttpWebResponse)this._request.EndGetResponse(asyncResult); this._contentLength = ChunkDownloader.ReadContentLengthFromHeaderValue(response.Headers["content-range"]); this._toByte = Math.Min(this._contentLength - 1L, this._fromByte + (long)this.DEFAULT_CHUNK_SIZE - 1L); this.ProcessResponse(response); } catch (Exception) { this._downloadFailed = true; } }