public void TestExecute() { WebRequestFactory.Current = new TestWebRequestFactory(); var connectClient = new LiveConnectClient(new LiveConnectSession()); var requestUrl = new Uri("http://foo.com"); IStorageFile outputFile = new StorageFileStub(); IProgress<LiveOperationProgress> progress = new Progress<LiveOperationProgress>(); SynchronizationContextWrapper syncContext = SynchronizationContextWrapper.Current; var tailoredDownloadOperation = new TailoredDownloadOperation(connectClient, requestUrl, outputFile, progress, syncContext); }
/// <summary> /// Download a file to disk. /// </summary> /// <param name="path">relative or absolute uri to the file to be downloaded.</param> /// <param name="outputFile">the file that the downloaded content is written to.</param> /// <param name="ct">a token that is used to cancel the download operation.</param> /// <param name="progress">a delegate that is called to report the download progress.</param> /// <returns>TODO</returns> internal Task<LiveDownloadOperationResult> InternalDownloadAsync( string path, IStorageFile outputFile, CancellationToken ct, IProgress<LiveOperationProgress> progress) { var tcs = new TaskCompletionSource<LiveDownloadOperationResult>(); var op = new TailoredDownloadOperation( this, this.GetResourceUri(path, ApiMethod.Download), outputFile, progress, null); op.OperationCompletedCallback = (LiveDownloadOperationResult result) => { if (result.IsCancelled) { tcs.TrySetCanceled(); } else if (result.Error != null) { tcs.TrySetException(result.Error); } else { tcs.TrySetResult(result); } }; ct.Register(op.Cancel); op.Execute(); return tcs.Task; }