private async Task <LiveDownloadOperationResult> ExecuteAsync(bool start, CancellationToken cancellationToken, IProgress <LiveOperationProgress> progressHandler) { LiveDownloadOperationResult result = null; Exception error = null; try { var progressHandlerWrapper = new Progress <DownloadOperation>(t => { if (progressHandler != null) { progressHandler.Report( new LiveOperationProgress( (long)t.Progress.BytesReceived, (long)t.Progress.TotalBytesToReceive)); } }); IAsyncOperationWithProgress <DownloadOperation, DownloadOperation> asyncOperation = start ? this.downloadOperation.StartAsync() : this.downloadOperation.AttachAsync(); await asyncOperation.AsTask(cancellationToken, progressHandlerWrapper); result = this.downloadOperation.ResultFile != null ? new LiveDownloadOperationResult(this.downloadOperation.ResultFile) : new LiveDownloadOperationResult(this.downloadOperation.GetResultStreamAt(0)); return(result); } catch (TaskCanceledException) { throw; } catch (Exception ex) { error = ex; } error = await this.ProcessDownloadErrorResponse(error); throw error; }
private void LiveConnector_DownloadCompleted(LiveDownloadOperationResult e, MemoryStream userState) { System.Action action = null; System.Action action2 = null; if (null == null) { if (action == null) { action = delegate { this.datatransferingStep.Success(); this.dataCheckingStep.Start(); }; } this.StatusUpdatingCallBack(action); try { System.IO.MemoryStream result = e.Stream as System.IO.MemoryStream; if (result == null) { if (action2 == null) { action2 = delegate { this.OnSyncingFinished(System.EventArgs.Empty); this.dataCheckingStep.Success(); }; } this.StatusUpdatingCallBack(action2); } else { this.ProcessRestoreData(result); } } catch (System.Exception exception) { this.OnReportingStatus(new ReportStatusHandlerEventArgs("RestoreDataFromSkyDriveFailedMessage", exception.Message)); AppUpdater.AddErrorLog("RestoreDataFromSkyDriveFailedMessage", exception.ToString(), new string[0]); } } else { this.StatusUpdatingCallBack(new System.Action(this.datatransferingStep.Failed)); //this.OnReportingStatus(new ReportStatusHandlerEventArgs("DownloadDataFromSkyDriveFailedMessage", e.Error.Message)); } this.OnSyncingFinished(System.EventArgs.Empty); }