Example #1
0
 /// <summary>
 ///     Creates a new instance of <see cref="CoderrConfiguration" />.
 /// </summary>
 public CoderrConfiguration()
 {
     Uploaders = new UploadDispatcher(this);
     _userInteraction.AskUserForDetails = true;
     ThrowExceptions = true;
     MaxNumberOfPropertiesPerCollection = 100;
 }
Example #2
0
 /// <summary>
 ///     Creates a new instance of <see cref="CoderrConfiguration" />.
 /// </summary>
 public CoderrConfiguration()
 {
     Uploaders = new UploadDispatcher(this);
     _userInteraction.AskUserForDetails = true;
     ThrowExceptions = Debugger.IsAttached;
     QueueReports    = !Debugger.IsAttached;
     MaxNumberOfPropertiesPerCollection = 100;
 }
        public void should_invoke_uploaders_when_a_feedback_is_submitted()
        {
            var config   = new CoderrConfiguration();
            var uploader = Substitute.For <IReportUploader>();
            var feedback = Substitute.For <FeedbackDTO>();

            var sut = new UploadDispatcher(config);

            sut.Register(uploader);
            sut.Upload(feedback);

            uploader.Received().UploadFeedback(feedback);
        }
        public void should_invoke_uploaders_when_a_new_report_is_being_uploaded()
        {
            var config   = new CoderrConfiguration();
            var uploader = Substitute.For <IReportUploader>();
            var report   = Substitute.For <ErrorReportDTO>();

            var sut = new UploadDispatcher(config);

            sut.Register(uploader);
            sut.Upload(report);

            uploader.Received().UploadReport(report);
        }
Example #5
0
        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;
            }
        }