public Task Save(IBitmapImage Image, ImageFormats Format, string FileName) { try { var extension = Format.ToString().ToLower(); var fileName = _settings.GetFileName(extension, FileName); Image.Save(fileName, Format); _recentList.Add(new FileRecentItem(fileName, RecentFileType.Image)); // Copy path to clipboard only when clipboard writer is off if (_settings.CopyOutPathToClipboard && !ServiceProvider.Get <ClipboardWriter>().Active) { fileName.WriteToClipboard(); } _systemTray.ShowScreenShotNotification(fileName); } catch (Exception e) { _messageProvider.ShowException(e, _loc.NotSaved); } return(Task.CompletedTask); }
// Returns UploadResult on success, Exception on failure public async Task <object> Save(IBitmapImage image, ImageFormats format) { var progressItem = new ImageUploadNotification(); _systemTray.ShowNotification(progressItem); try { var uploadResult = await _imgUploader.Upload(image, format, progressItemProgress => progressItem.Progress = progressItemProgress); var link = uploadResult.Url; _recentList.Add(new UploadRecentItem(link, uploadResult.DeleteLink, _imgUploader)); progressItem.RaiseFinished(link); return(uploadResult); } catch (Exception e) { progressItem.RaiseFailed(); return(e); } }
public async Task Save(Bitmap Image, ImageFormat Format, string FileName) { var response = await Save(Image, Format); switch (response) { case ImgurUploadResponse uploadResponse: var link = uploadResponse.Data.Link; var deleteHash = uploadResponse.Data.DeleteHash; _recentList.Add(new ImgurRecentItem(link, deleteHash)); // Copy path to clipboard only when clipboard writer is off if (_settings.CopyOutPathToClipboard && !ServiceProvider.Get <ClipboardWriter>().Active) { link.WriteToClipboard(); } break; case Exception e: if (!_diskWriter.Active) { ServiceProvider.Get <IMainWindow>().IsVisible = true; var yes = _messageProvider.ShowYesNo( $"{_loc.ImgurFailed}\n{e.Message}\n\nDo you want to Save to Disk?", "Imgur Upload Failed"); if (yes) { await _diskWriter.Save(Image, Format, FileName); } } break; } }
async Task StopRecording() { _audioPlayer.Play(SoundKind.Stop); FileRecentItem savingRecentItem = null; FileSaveNotification notification = null; var fileName = _recordingModel.CurrentFileName; var isVideo = _recordingModel.IsVideo; IVideoConverter postWriter = null; // Assume saving to file only when extension is present if (!_timerModel.Waiting && !string.IsNullOrWhiteSpace(_videoWritersViewModel.SelectedVideoWriter.Extension)) { savingRecentItem = new FileRecentItem(fileName, isVideo ? RecentFileType.Video : RecentFileType.Audio, true); _recentList.Add(savingRecentItem); notification = new FileSaveNotification(savingRecentItem); notification.OnDelete += () => savingRecentItem.RemoveCommand.ExecuteIfCan(); _systemTray.ShowNotification(notification); if (isVideo && Settings.Video.PostConvert) { postWriter = _videoWritersViewModel.SelectedPostWriter; } } var task = _recordingModel.StopRecording(); lock (_stopRecTaskLock) { _stopRecTasks.Add(task); } var wasWaiting = _timerModel.Waiting; _timerModel.Waiting = false; try { // Ensure saved await task; if (postWriter != null) { notification.Converting(); var progress = new Progress <int>(); progress.ProgressChanged += (S, E) => notification.Progress = E; var outFileName = Path.Combine( Path.GetDirectoryName(fileName), $"{Path.GetFileNameWithoutExtension(fileName)}.converted{postWriter.Extension}"); try { await postWriter.StartAsync(new VideoConverterArgs { AudioQuality = Settings.Audio.Quality, VideoQuality = Settings.Video.Quality, InputFile = fileName, FileName = outFileName }, progress); File.Delete(fileName); var targetFileName = Path.Combine( Path.GetDirectoryName(fileName), $"{Path.GetFileNameWithoutExtension(fileName)}{postWriter.Extension}"); File.Move(outFileName, targetFileName); savingRecentItem.Converted(targetFileName); notification.Converted(targetFileName); } catch (FFmpegNotFoundException e) { try { _ffmpegViewsProvider.ShowUnavailable(); } catch { // Show simpler message for cases the above fails _messageProvider.ShowException(e, e.Message); } } catch (Exception e) { _messageProvider.ShowException(e, "Conversion Failed"); } } lock (_stopRecTaskLock) { _stopRecTasks.Remove(task); } } catch (Exception e) { _messageProvider.ShowException(e, "Error occurred when stopping recording.\nThis might sometimes occur if you stop recording just as soon as you start it."); return; } if (wasWaiting) { try { File.Delete(fileName); } catch { // Ignore Errors } } if (savingRecentItem != null) { AfterSave(savingRecentItem, notification); } }
async Task StopRecording() { _audioPlayer.Play(SoundKind.Stop); FileRecentItem savingRecentItem = null; FileSaveNotification notification = null; var fileName = _recordingModel.CurrentFileName; var isVideo = _recordingModel.IsVideo; // Assume saving to file only when extension is present if (!_timerModel.Waiting && !string.IsNullOrWhiteSpace(_videoWritersViewModel.SelectedVideoWriter.Extension)) { savingRecentItem = new FileRecentItem(fileName, isVideo ? RecentFileType.Video : RecentFileType.Audio, true); _recentList.Add(savingRecentItem); notification = new FileSaveNotification(savingRecentItem); notification.OnDelete += () => savingRecentItem.RemoveCommand.ExecuteIfCan(); _systemTray.ShowNotification(notification); } var task = _recordingModel.StopRecording(); lock (_stopRecTaskLock) { _stopRecTasks.Add(task); } var wasWaiting = _timerModel.Waiting; _timerModel.Waiting = false; try { // Ensure saved await task; lock (_stopRecTaskLock) { _stopRecTasks.Remove(task); } } catch (Exception e) { _messageProvider.ShowException(e, "Error occurred when stopping recording.\nThis might sometimes occur if you stop recording just as soon as you start it."); return; } if (wasWaiting) { try { File.Delete(fileName); } catch { // Ignore Errors } } if (savingRecentItem != null) { AfterSave(savingRecentItem, notification); } }