public async Task Invoke(IReadOnlyDictionary <string, string> parameters, HSSettings settingsContext) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } if (settingsContext == null) { throw new ArgumentNullException(nameof(settingsContext)); } var fileName = parameters.Count != 1 || !parameters.ContainsKey(FileNameParameter) ? ShowFileSelector(UploadFile) : parameters[FileNameParameter]; if (fileName == null) { return; // We did not get a valid file name (user cancelled or something else was strange) } if (!CanProcessFile(fileName)) { // TODO: Error Message return; } using var bmp = new Bitmap(fileName); var format = ImageFormatInformation.GetImageFormatFromFileName(fileName); Debug.Assert(format != null); try { var result = await UploadDispatcher.InitiateUploadToDefaultUploader(bmp, settingsContext, HolzShotsApplication.Instance.Uploaders, format, null).ConfigureAwait(true); UploadHelper.InvokeUploadFinishedUI(result, settingsContext); } catch (UploadCanceledException) { NotificationManager.ShowOperationCanceled(); } catch (UploadException ex) { await NotificationManager.UploadFailed(ex); } }
static async Task InvokeAfterCaptureAction(ScreenRecording recording, HSSettings settingsContext) { switch (settingsContext.ActionAfterVideoCapture) { case VideoCaptureHandlingAction.Upload: try { var payload = new VideoUploadPayload(recording); var result = await UploadDispatcher.InitiateUploadToDefaultUploader(payload, settingsContext, HolzShotsApplication.Instance.Uploaders, null).ConfigureAwait(true); UploadHelper.InvokeUploadFinishedUI(result, settingsContext); } catch (UploadCanceledException) { NotificationManager.ShowOperationCanceled(); } catch (UploadException ex) { await NotificationManager.UploadFailed(ex); } return; case VideoCaptureHandlingAction.CopyFile: { var success = ClipboardEx.SetFiles(recording.FilePath); if (settingsContext.ShowCopyConfirmation) { if (success) { NotificationManager.ShowFileCopyConfirmation(); } else { NotificationManager.CopyingFileFailed(); } } } break; case VideoCaptureHandlingAction.CopyFilePath: { var success = ClipboardEx.SetText(recording.FilePath); if (settingsContext.ShowCopyConfirmation) { if (success) { NotificationManager.ShowFilePathCopyConfirmation(); } else { NotificationManager.CopyingFilePathFailed(); } } } break; case VideoCaptureHandlingAction.ShowInExplorer: IO.HolzShotsPaths.OpenSelectedFileInExplorer(recording.FilePath); return; case VideoCaptureHandlingAction.OpenInDefaultApp: Process.Start(recording.FilePath); return; case VideoCaptureHandlingAction.None: return; default: throw new ArgumentException("Unhandled VideoCaptureHandlingAction: " + settingsContext.ActionAfterVideoCapture); } }
protected static async Task ProcessCapturing(Screenshot screenshot, HSSettings settingsContext) { if (screenshot == null) { throw new ArgumentNullException(nameof(screenshot)); } if (settingsContext == null) { throw new ArgumentNullException(nameof(settingsContext)); } ScreenshotAggregator.HandleScreenshot(screenshot, settingsContext); switch (settingsContext.ActionAfterImageCapture) { case ImageCaptureHandlingAction.OpenEditor: var shower = new ShotEditor(screenshot, HolzShotsApplication.Instance.Uploaders, settingsContext); shower.Show(); return; case ImageCaptureHandlingAction.Upload: try { var result = await UploadDispatcher.InitiateUploadToDefaultUploader(screenshot.Image, settingsContext, HolzShotsApplication.Instance.Uploaders, null, null).ConfigureAwait(true); UploadHelper.InvokeUploadFinishedUI(result, settingsContext); } catch (UploadCanceledException) { NotificationManager.ShowOperationCanceled(); } catch (UploadException ex) { await NotificationManager.UploadFailed(ex); } return; case ImageCaptureHandlingAction.Copy: try { Clipboard.SetImage(screenshot.Image); NotificationManager.ShowImageCopiedConfirmation(); } catch (Exception ex) when(ex is ExternalException || ex is System.Threading.ThreadStateException || ex is ArgumentNullException) { NotificationManager.CopyImageFailed(ex); } return; case ImageCaptureHandlingAction.SaveAs: PromptSaveAs(screenshot, settingsContext); return; case ImageCaptureHandlingAction.None: return; // Intentionally do nothing default: return; } }