示例#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
        public static Task <UploadResult> InitiateUploadToDefaultUploader(IUploadPayload payload, HSSettings settingsContext, UploaderManager uploaderManager, ITransferProgressReporter?progressReporter)
        {
            Debug.Assert(payload != null);
            Debug.Assert(settingsContext != null);
            Debug.Assert(uploaderManager != null);

            var service = GetUploadServiceForSettingsContext(settingsContext, uploaderManager);

            Debug.Assert(service is not null);
            Debug.Assert(service.Metadata != null);
            Debug.Assert(service.Uploader != null);

            if (service?.Metadata == null || service?.Uploader == null)
            {
                throw new UploadException("Unable to find an uploader for the current settings context");
            }

            return(InitiateUpload(payload, settingsContext, service.Uploader, progressReporter));
        }