private async Task DoExportToImageFiles(string outputPath) { // TODO: If I add new image settings this may break things imageSettingsContainer.ImageSettings = new ImageSettings { JpegQuality = options.JpegQuality, TiffCompression = Enum.TryParse <TiffCompression>(options.TiffComp, true, out var tc) ? tc : TiffCompression.Auto }; foreach (var scan in scanList) { var op = operationFactory.Create <SaveImagesOperation>(); int i = -1; op.StatusChanged += (sender, args) => { if (op.Status.CurrentProgress > i) { OutputVerbose(ConsoleResources.ExportingImage, op.Status.CurrentProgress + 1, scan.Count); i = op.Status.CurrentProgress; } }; op.Start(outputPath, startTime, scan); await op.Success; } }
private bool SaveOneFile(AutoSaveSettings settings, DateTime now, int i, List <ScannedImage> images, ISaveNotify notify, ref string firstFileSaved) { if (images.Count == 0) { return(true); } var form = formFactory.Create <FProgress>(); string subPath = fileNamePlaceholders.SubstitutePlaceholders(settings.FilePath, now, true, i); if (settings.PromptForFilePath) { if (dialogHelper.PromptToSavePdfOrImage(subPath, out string newPath)) { subPath = fileNamePlaceholders.SubstitutePlaceholders(newPath, now, true, i); } } var extension = Path.GetExtension(subPath); if (extension != null && extension.Equals(".pdf", StringComparison.InvariantCultureIgnoreCase)) { if (File.Exists(subPath)) { subPath = fileNamePlaceholders.SubstitutePlaceholders(subPath, now, true, 0, 1); } var op = operationFactory.Create <SavePdfOperation>(); form.Operation = op; var ocrLanguageCode = userConfigManager.Config.EnableOcr ? userConfigManager.Config.OcrLanguageCode : null; if (op.Start(subPath, now, images, pdfSettingsContainer.PdfSettings, ocrLanguageCode, false)) { form.ShowDialog(); } if (op.Status.Success && firstFileSaved == null) { firstFileSaved = subPath; } if (op.Status.Success) { notify?.PdfSaved(subPath); } return(op.Status.Success); } else { var op = operationFactory.Create <SaveImagesOperation>(); form.Operation = op; if (op.Start(subPath, now, images)) { form.ShowDialog(); } if (op.Status.Success && firstFileSaved == null) { firstFileSaved = op.FirstFileSaved; } if (op.Status.Success) { notify?.ImagesSaved(images.Count, op.FirstFileSaved); } return(op.Status.Success); } }
private async Task <(bool, string)> SaveOneFile(AutoSaveSettings settings, DateTime now, int i, List <ScannedImage> images, ISaveNotify notify) { if (images.Count == 0) { return(true, null); } string subPath = fileNamePlaceholders.SubstitutePlaceholders(settings.FilePath, now, true, i); if (settings.PromptForFilePath) { if (dialogHelper.PromptToSavePdfOrImage(subPath, out string newPath)) { subPath = fileNamePlaceholders.SubstitutePlaceholders(newPath, now, true, i); } else { return(false, null); } } var extension = Path.GetExtension(subPath); if (extension != null && extension.Equals(".pdf", StringComparison.InvariantCultureIgnoreCase)) { if (File.Exists(subPath)) { subPath = fileNamePlaceholders.SubstitutePlaceholders(subPath, now, true, 0, 1); } var op = operationFactory.Create <SavePdfOperation>(); if (op.Start(subPath, now, images, pdfSettingsContainer.PdfSettings, ocrManager.DefaultParams, false, null)) { operationProgress.ShowProgress(op); } bool success = await op.Success; if (success) { notify?.PdfSaved(subPath); } return(success, subPath); } else { var op = operationFactory.Create <SaveImagesOperation>(); if (op.Start(subPath, now, images)) { operationProgress.ShowProgress(op); } bool success = await op.Success; if (success) { notify?.ImagesSaved(images.Count, op.FirstFileSaved); } return(success, subPath); } }
public async Task <bool> ExportPDF(string filename, List <ScannedImage> images, bool email, EmailMessage emailMessage) { var op = operationFactory.Create <SavePdfOperation>(); var pdfSettings = pdfSettingsContainer.PdfSettings; pdfSettings.Metadata.Creator = MiscResources.NAPS2; if (op.Start(filename, DateTime.Now, images, pdfSettings, ocrManager.DefaultParams, email, emailMessage)) { operationProgress.ShowProgress(op); } return(await op.Success); }
public async Task <IActionResult> GetScreenshots(Guid gameId) { var result = await _operationFactory.Create <GetScreenshotsQuery>(x => { x.GameId = gameId; }).HandleAsync(); if (result.HasFailed()) { return(BadRequest(result)); } return(Ok(result.Data)); }
public async Task <IActionResult> AddGame([FromBody] AddGameVaultOrWishListRequest request) { var result = await _operationFactory.Create <AddGameToVaultCommand>(x => { x.GameId = request.GameId; x.UserId = HttpContext.GetUserId(); }).HandleAsync(); if (result.HasFailed()) { return(BadRequest(result.Errors)); } return(Ok()); }
// POST: api/Sum public SumResponse Post([FromBody] SumRequest request) { var result = _operationFactory.Create(request).Execute(request); return((SumResponse)result); // return new SumResponse(); }
public async Task <IActionResult> SearchGames([FromQuery] SearchGameRequest searchGameRequest) { var result = await _operationFactory.Create <SearchGamesQuery>(x => { x.SearchText = searchGameRequest.SearchGameText; x.Skip = searchGameRequest.Skip; x.Take = searchGameRequest.Take; }).HandleAsync(); if (result.HasFailed()) { return(BadRequest(result.Errors)); } return(Ok(result.Data)); }
protected override async Task ScanInternal(ScannedImageSource.Concrete source) { var op = operationFactory.Create <WiaScanOperation>(); using (CancelToken.Register(op.Cancel)) { op.Start(ScanProfile, ScanDevice, ScanParams, DialogParent, source); Invoker.Current.SafeInvoke(() => { if (ScanParams.Modal && !ScanParams.NoUI) { operationProgress.ShowModalProgress(op); } else { operationProgress.ShowBackgroundProgress(op); } }); await op.Success; } if (op.ScanException != null) { op.ScanException.PreserveStackTrace(); throw op.ScanException; } }
public void PostProcessStep2(ScannedImage image, Bitmap bitmap, ScanProfile profile, ScanParams scanParams, int pageNumber) { if (!profile.UseNativeUI && profile.BrightnessContrastAfterScan) { if (profile.Brightness != 0) { AddTransformAndUpdateThumbnail(image, ref bitmap, new BrightnessTransform { Brightness = profile.Brightness }); } if (profile.Contrast != 0) { AddTransformAndUpdateThumbnail(image, ref bitmap, new TrueContrastTransform { Contrast = profile.Contrast }); } } if (profile.FlipDuplexedPages && pageNumber % 2 == 0) { AddTransformAndUpdateThumbnail(image, ref bitmap, new RotationTransform(RotateFlipType.Rotate180FlipNone)); } if (profile.AutoDeskew) { var op = operationFactory.Create <DeskewOperation>(); if (op.Start(new[] { image })) { operationProgress.ShowProgress(op); } } if (scanParams.DetectPatchCodes && image.PatchCode == PatchCode.None) { image.PatchCode = PatchCodeDetector.Detect(bitmap); } }
private void LoadData(string artistName) { _operationFactory.Create(this) .WithExpressionAsync(_ => _loadMusicService.GetTopArtistAlbumsAsync(artistName)) .OnSuccess(HandleLoadData) .ExecuteAsync(); }
public bool ExportPDF(string filename, List <ScannedImage> images, bool email) { var op = operationFactory.Create <SavePdfOperation>(); var progressForm = formFactory.Create <FProgress>(); progressForm.Operation = op; var pdfSettings = pdfSettingsContainer.PdfSettings; pdfSettings.Metadata.Creator = MiscResources.NAPS2; if (op.Start(filename, DateTime.Now, images, pdfSettings, ocrDependencyManager.DefaultLanguageCode, email)) { progressForm.ShowDialog(); } return(op.Status.Success); }
private async Task Save(DateTime now, int i, List <ScannedImage> images) { if (images.Count == 0) { return; } var subPath = fileNamePlaceholders.SubstitutePlaceholders(Settings.SavePath, now, true, i); if (GetSavePathExtension().ToLower() == ".pdf") { if (File.Exists(subPath)) { subPath = fileNamePlaceholders.SubstitutePlaceholders(subPath, now, true, 0, 1); } var snapshots = images.Select(x => x.Preserve()).ToList(); try { await pdfExporter.Export(subPath, snapshots, pdfSettingsContainer.PdfSettings, ocrManager.DefaultParams, (j, k) => { }, CancelToken); } finally { snapshots.ForEach(s => s.Dispose()); } } else { var op = operationFactory.Create <SaveImagesOperation>(); op.Start(subPath, now, images, true); await op.Success; } }
private void Save(DateTime now, int i, List <ScannedImage> images) { if (images.Count == 0) { return; } var barcode = images[0].Barcode; var subPath = fileNamePlaceholders.SubstitutePlaceholders(Settings.SavePath, now, barcode, true, i); if (GetSavePathExtension().ToLower() == ".pdf") { if (File.Exists(subPath)) { subPath = fileNamePlaceholders.SubstitutePlaceholders(subPath, now, barcode, true, 0, 1); } var ocrLanguageCode = userConfigManager.Config.EnableOcr ? userConfigManager.Config.OcrLanguageCode : null; pdfExporter.Export(subPath, images, pdfSettingsContainer.PdfSettings, ocrLanguageCode, j => true); } else { var op = operationFactory.Create <SaveImagesOperation>(); op.Start(subPath, now, images, true); op.WaitUntilFinished(); } }
public UpdateOperation StartUpdate(UpdateInfo update) { var op = operationFactory.Create <UpdateOperation>(); op.Start(update); operationProgress.ShowModalProgress(op); return(op); }
public IOperation <TContext>?Build() { var allOperationTypes = _operations.ToArray(); var lastOperationType = allOperationTypes.LastOrDefault(); if (lastOperationType == null) { return(null); } var nextOperation = new OperationMediator <TContext>(_operationFactory.Create <TContext>(lastOperationType), null); for (int i = allOperationTypes.Length - 2; i >= 0; i--) { nextOperation = new OperationMediator <TContext>(_operationFactory.Create <TContext>(allOperationTypes[i]), nextOperation); } return(nextOperation); }
private async void tsDeskew_Click(object sender, EventArgs e) { var op = operationFactory.Create <DeskewOperation>(); if (op.Start(new[] { ImageList.Images[ImageIndex] })) { operationProgress.ShowProgress(op); await UpdateImage(); } }
/// <summary> /// Implementation of this method has basically no significance from /// IoC point of view, except for using <see cref="_factory"/> to /// create instances of various numeric operations. /// </summary> public int Evaluate(IEnumerable <string> expression) { var operands = new Stack <int>(); var operations = new Stack <IOperation>(); // Simple variable controlling the syntactic correctness of // the input expression. var expectingConstant = true; // Process the expression in reverse order to fill in the stacks // that the expression will be evaluated from left to right. foreach (var token in expression.Reverse()) { if (expectingConstant) { int constant; if (int.TryParse(token, out constant)) { operands.Push(constant); } else { throw new Exception("invalid expression"); } expectingConstant = false; continue; } operations.Push(_factory.Create(token)); expectingConstant = true; } if (expectingConstant) { throw new Exception("invalid expression"); } if (operands.Count == 0) { throw new Exception("invalid expression"); } while (operands.Count > 1) { var operand1 = operands.Pop(); var operand2 = operands.Pop(); var operation = operations.Pop(); var result = operation.Evaluate(operand1, operand2); operands.Push(result); } return(operands.Peek()); }
private void DoExportToImageFiles(string outputPath) { // TODO: If I add new image settings this may break things imageSettingsContainer.ImageSettings = new ImageSettings { JpegQuality = options.JpegQuality }; var op = operationFactory.Create <SaveImagesOperation>(); int i = -1; op.StatusChanged += (sender, args) => { if (op.Status.CurrentProgress > i) { OutputVerbose(ConsoleResources.ExportingImage, op.Status.CurrentProgress + 1, imageList.Images.Count); i = op.Status.CurrentProgress; } }; op.Start(outputPath, startTime, imageList.Images); op.WaitUntilFinished(); }
/// <summary> Compress or decompress file </summary> /// <param name="pathParams"> Paths for input and output files </param> /// <param name="operationType"> Process operation type </param> public void ProcessFile(FilePaths pathParams, OperationType operationType) { Guard.NotNull(pathParams, $"{nameof(FilePaths)}"); Guard.DefinedEnumValue(operationType); Guard.True(operationType != OperationType.Default, Resources.UnexpectedOperationException); var operation = _operationFactory.Create(operationType); _taskManager.CreateTasks(pathParams, operation); _threadManager.ExecuteInParallel(_taskManager, UnexpectedTerminationProc); }
private void tsDeskew_Click(object sender, EventArgs e) { var op = operationFactory.Create <DeskewOperation>(); var progressForm = FormFactory.Create <FProgress>(); progressForm.Operation = op; if (op.Start(new[] { ImageList.Images[ImageIndex] })) { progressForm.ShowDialog(); UpdateImage(); UpdateCallback(Enumerable.Range(ImageIndex, 1)); } }
public void PostProcessStep2(ScannedImage image, Bitmap bitmap, ScanProfile profile, ScanParams scanParams, int pageNumber, bool supportsNativeUI = true) { if (!scanParams.NoThumbnails) { image.SetThumbnail(thumbnailRenderer.RenderThumbnail(bitmap)); } if (scanParams.SkipPostProcessing) { return; } if (profile.StretchHistogram && !profile.HistogramStretchConfig.IsNull) { AddTransformAndUpdateThumbnail(image, ref bitmap, new StretchHistogramTransform { Parameters = profile.HistogramStretchConfig }); } if ((!profile.UseNativeUI || !supportsNativeUI) && profile.BrightnessContrastAfterScan) { if (profile.Brightness != 0) { AddTransformAndUpdateThumbnail(image, ref bitmap, new BrightnessTransform { Brightness = profile.Brightness }); } if (profile.Contrast != 0) { AddTransformAndUpdateThumbnail(image, ref bitmap, new TrueContrastTransform { Contrast = profile.Contrast }); } } if (profile.FlipDuplexedPages && pageNumber % 2 == 0) { AddTransformAndUpdateThumbnail(image, ref bitmap, new RotationTransform(RotateFlipType.Rotate180FlipNone)); } if (profile.AutoDeskew) { var op = operationFactory.Create <DeskewOperation>(); if (op.Start(new[] { image })) { operationProgress.ShowProgress(op); op.Wait(); } } if (scanParams.DetectPatchCodes && image.PatchCode == PatchCode.None) { image.PatchCode = PatchCodeDetector.Detect(bitmap); } }
protected override void Result(out string result) { var input = ReadRows("Input1.txt"); List <IOperation> operations = new List <IOperation>(); foreach (var inp in input) { operations.Add(factory.Create(inp)); } int output = GetResult(operations); result = $"{output}"; }
public async Task <int> Run(string[] args) { var result = await Parser.Default .ParseArguments <InitOptions, InfoOptions, SetOptions, LoadOptions, BatchOptions, ProducerOptions, WorkerOptions>(args) .MapResult( (InitOptions options) => operationFactory.Create <InitOptions>().Run(options), (InfoOptions options) => operationFactory.Create <InfoOptions>().Run(options), (SetOptions options) => operationFactory.Create <SetOptions>().Run(options), (LoadOptions options) => operationFactory.Create <LoadOptions>().Run(options), (BatchOptions options) => operationFactory.Create <BatchOptions>().Run(options), (ProducerOptions options) => operationFactory.Create <ProducerOptions>().Run(options), (WorkerOptions options) => operationFactory.Create <WorkerOptions>().Run(options), errs => { Errors = errs.ToList(); return(Task.FromResult(ExitCodes.InvalidArguments)); }); return(result); }
private void Save(DateTime now, int i, List <ScannedImage> images) { if (images.Count == 0) { return; } var subPath = fileNamePlaceholders.SubstitutePlaceholders(Settings.SavePath, now, true, i); if (GetSavePathExtension().ToLower() == ".pdf") { if (File.Exists(subPath)) { subPath = fileNamePlaceholders.SubstitutePlaceholders(subPath, now, true, 0, 1); } pdfExporter.Export(subPath, images, pdfSettingsContainer.PdfSettings, ocrDependencyManager.DefaultLanguageCode, j => true); } else { var op = operationFactory.Create <SaveImagesOperation>(); op.Start(subPath, now, images, true); op.WaitUntilFinished(); } }
public LoginViewModel(INavigationService navigationService, IUserDialogs userDialogs, ISessionService sessionService, IOperationFactory operationFactory) { NavigationService = navigationService; UserDialogs = userDialogs; SessionService = sessionService; OperationFactory = operationFactory; _loginOperation = OperationFactory .Create(this) .WithLoadingNotification() // .WithPreventRepetitiveExecutions() .WithExpressionAsync((cancellationToken) => { if (ValidateCredentials(out var credentials)) { return(SessionService.Start(credentials)); } return(Task.FromResult(false)); }) .OnSuccess(success => { if (success) { NavigationService.Navigate <MainViewModel>(); } }) .OnError <InvalidCredentialException>(ex => SetErrorMessage(LoginErrorCases.WrongCredentials)) .OnError <Exception>(ex => SetErrorMessage(LoginErrorCases.GeneralError)); SetDebugCredentials(); }
public void PostProcessStep2(ScannedImage image, Bitmap bitmap, ScanProfile profile, ScanParams scanParams, int pageNumber) { if (!profile.UseNativeUI && profile.BrightnessContrastAfterScan) { if (profile.Brightness != 0) { AddTransformAndUpdateThumbnail(image, ref bitmap, new BrightnessTransform { Brightness = profile.Brightness }); } if (profile.Contrast != 0) { AddTransformAndUpdateThumbnail(image, ref bitmap, new TrueContrastTransform { Contrast = profile.Contrast }); } } if (profile.FlipDuplexedPages && pageNumber % 2 == 0) { AddTransformAndUpdateThumbnail(image, ref bitmap, new RotationTransform(RotateFlipType.Rotate180FlipNone)); } if (profile.AutoDeskew) { var op = operationFactory.Create <DeskewOperation>(); if (op.Start(new[] { image })) { operationProgress.ShowProgress(op); } } if (scanParams.DetectPatchCodes && image.PatchCode == PatchCode.None) { IBarcodeReader reader = new BarcodeReader(); var barcodeResult = reader.Decode(bitmap); if (barcodeResult != null) { switch (barcodeResult.Text) { case "PATCH1": image.PatchCode = PatchCode.Patch1; break; case "PATCH2": image.PatchCode = PatchCode.Patch2; break; case "PATCH3": image.PatchCode = PatchCode.Patch3; break; case "PATCH4": image.PatchCode = PatchCode.Patch4; break; case "PATCH6": image.PatchCode = PatchCode.Patch6; break; case "PATCHT": image.PatchCode = PatchCode.PatchT; break; } } } }
public async Task <IActionResult> GetUserProfile(Guid?userId) { var result = await _operationFactory.Create <GetUserProfileQuery>(x => { x.UserId = userId; x.CurrentUserId = HttpContext.GetUserId(); }).HandleAsync(); if (result.HasFailed()) { return(BadRequest(result)); } return(Ok(result.Data)); }
public void PostProcessStep2(ScannedImage image, Bitmap bitmap, ScanProfile profile, ScanParams scanParams, int pageNumber) { if (!profile.UseNativeUI && profile.BrightnessContrastAfterScan) { if (profile.Brightness != 0) { AddTransformAndUpdateThumbnail(image, ref bitmap, new BrightnessTransform { Brightness = profile.Brightness }); } if (profile.Contrast != 0) { AddTransformAndUpdateThumbnail(image, ref bitmap, new TrueContrastTransform { Contrast = profile.Contrast }); } } if (profile.FlipDuplexedPages && pageNumber % 2 == 0) { AddTransformAndUpdateThumbnail(image, ref bitmap, new RotationTransform(RotateFlipType.Rotate180FlipNone)); } if (profile.AutoDeskew) { var op = operationFactory.Create <DeskewOperation>(); if (op.Start(new[] { image })) { operationProgress.ShowProgress(op); } } if (scanParams.DetectPatchCodes && image.PatchCode == PatchCode.None) { IBarcodeReader reader = new BarcodeReader(); var barcodeResult = reader.Decode(bitmap); if (barcodeResult != null) { switch (barcodeResult.Text) { case "PATCH1": image.PatchCode = PatchCode.Patch1; break; case "PATCH2": image.PatchCode = PatchCode.Patch2; break; case "PATCH3": image.PatchCode = PatchCode.Patch3; break; case "PATCH4": image.PatchCode = PatchCode.Patch4; break; case "PATCH6": image.PatchCode = PatchCode.Patch6; break; case "PATCHT": image.PatchCode = PatchCode.PatchT; break; } } } else if (scanParams.DetectBarcodes) { IMultipleBarcodeReader multiReader = new BarcodeReader(); multiReader.Options.TryHarder = true; // profile.AutoSaveSettings.Separator == ImportExport.SaveSeparator.Barcode if (profile.AutoSaveSettings != null) { if (profile.AutoSaveSettings.BarcodeType != null && profile.AutoSaveSettings.BarcodeType != "") { switch (profile.AutoSaveSettings.BarcodeType) { case "2of5 interleaved": multiReader.Options.PossibleFormats = new List <BarcodeFormat>(); multiReader.Options.PossibleFormats.Add(BarcodeFormat.ITF); break; case "Code 39": multiReader.Options.PossibleFormats = new List <BarcodeFormat>(); multiReader.Options.PossibleFormats.Add(BarcodeFormat.CODE_39); break; case "Code 93": multiReader.Options.PossibleFormats = new List <BarcodeFormat>(); multiReader.Options.PossibleFormats.Add(BarcodeFormat.CODE_93); break; case "Code 128": multiReader.Options.PossibleFormats = new List <BarcodeFormat>(); multiReader.Options.PossibleFormats.Add(BarcodeFormat.CODE_128); break; case "EAN 8": multiReader.Options.PossibleFormats = new List <BarcodeFormat>(); multiReader.Options.PossibleFormats.Add(BarcodeFormat.EAN_8); break; case "EAN13": multiReader.Options.PossibleFormats = new List <BarcodeFormat>(); multiReader.Options.PossibleFormats.Add(BarcodeFormat.EAN_13); break; } } } var barcodeResult = multiReader.DecodeMultiple(bitmap); if (barcodeResult != null) { foreach (var barcode in barcodeResult) { image.Barcode = barcode.Text; System.Diagnostics.Debug.WriteLine(barcode.BarcodeFormat + " = " + barcode.Text); } } } }