public AttachAsync ( ) : UploadOperation>.IAsyncOperationWithProgress |
||
Résultat | UploadOperation>.IAsyncOperationWithProgress |
private async Task HandleUploadAsync(UploadOperation upload, bool start) { try { CancellationTokenSource cts = new CancellationTokenSource(); Progress<UploadOperation> progressCallback = new Progress<UploadOperation>(); if (start) { // Start the upload and attach a progress handler. await upload.StartAsync().AsTask(cts.Token, progressCallback); } else { // The upload was already running when the application started, re-attach the progress handler. await upload.AttachAsync().AsTask(cts.Token, progressCallback); } ResponseInformation response = upload.GetResponseInformation(); // Log(String.Format("Completed: {0}, Status Code: {1}", upload.Guid, response.StatusCode)); } catch (TaskCanceledException) { // Log("Upload cancelled."); } catch (Exception ex) { //LogException("Error", ex); } }
private async Task HandleUploadAsync(UploadOperation upload, bool start) { try { LogStatus("Running: " + upload.Guid, NotifyType.StatusMessage); Progress<UploadOperation> progressCallback = new Progress<UploadOperation>(UploadProgress); if (start) { // Start the upload and attach a progress handler. await upload.StartAsync().AsTask(cts.Token, progressCallback); } else { // The upload was already running when the application started, re-attach the progress handler. await upload.AttachAsync().AsTask(cts.Token, progressCallback); } ResponseInformation response = upload.GetResponseInformation(); LogStatus(String.Format(CultureInfo.CurrentCulture, "Completed: {0}, Status Code: {1}", upload.Guid, response.StatusCode), NotifyType.StatusMessage); } catch (TaskCanceledException) { LogStatus("Canceled: " + upload.Guid, NotifyType.StatusMessage); } catch (Exception ex) { if (!IsExceptionHandled("Error", ex, upload)) { throw; } } }
/// <summary> /// Start uplaod and create handler. /// </summary> /// <param name="upload">UploadOperation handled.</param> /// <param name="start">Whether uplaod is started.</param> /// <returns> /// Represent the asynchronous operation. /// </returns> private async Task HandleUploadAsync(UploadOperation upload, bool start) { try { try { Progress<UploadOperation> progressCallback = new Progress<UploadOperation>(UploadProgress); if (start) { // Start the upload and attach a progress handler. await upload.StartAsync().AsTask(cts.Token, progressCallback); } else { // The upload was already running when the application started, re-attach the progress handler. await upload.AttachAsync().AsTask(cts.Token, progressCallback); } } catch { ShowMessageDialog("Error90! Upload canceled."); } ResponseInformation response = upload.GetResponseInformation(); foreach (var c in response.Headers) { System.Diagnostics.Debug.WriteLine("{0}, {1}. markkkkkkkk", c.Key, c.Value); } if (images != null && images.Count != 0 && hasImage == false) { toBeUploadCourse.ImageUri = response.Headers[images.FirstOrDefault().Name]; hasImage = true; } SaveUploadLessonToListAsync(response); } catch (TaskCanceledException) { ShowMessageDialog("Error9! Upload canceled."); } catch { ShowMessageDialog("Error10! Upload canceled."); //throw; } }