コード例 #1
0
        public static async Task <UploadResult> InitiateUpload(IUploadPayload payload, HSSettings settingsContext, Uploader uploader, ITransferProgressReporter?progressReporter)
        {
            if (payload == null)
            {
                throw new ArgumentNullException(nameof(payload));
            }
            if (settingsContext == null)
            {
                throw new ArgumentNullException(nameof(settingsContext));
            }
            if (uploader == null)
            {
                throw new ArgumentNullException(nameof(uploader));
            }

            try
            {
                var sc = uploader.GetSupportedSettingsInvocations();
                if ((sc & SettingsInvocationContexts.OnUse) == SettingsInvocationContexts.OnUse)
                {
                    // A third-party settings dialog may throw an exception
                    // If it does, we abort the upload
                    await uploader.InvokeSettingsAsync(SettingsInvocationContexts.OnUse).ConfigureAwait(true);
                }

                using var ui = new UploadUI(payload, uploader, progressReporter);
                try
                {
                    ui.ShowUI();

                    return(await ui.InvokeUploadAsync().ConfigureAwait(true));
                }
                finally
                {
                    ui.HideUI();
                }
            }
            catch (OperationCanceledException c)
            {
                throw new UploadCanceledException(c);
            }
            catch (UploadException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new UploadException(ex.Message, ex);
            }
        }
コード例 #2
0
 // TODO: maybe refactor this, so the payload gets created somewhere else
 /// <summary> Catch the UploadException! </summary>
 public static async Task <UploadResult> InitiateUpload(Image image, HSSettings settingsContext, Uploader uploader, ImageFormat?format, ITransferProgressReporter?progressReporter)
 {
     format ??= GetImageFormat(image, settingsContext);
     using var payload = new ImageUploadPayload(image, format);
     return(await InitiateUpload(payload, settingsContext, uploader, progressReporter));
 }