Beispiel #1
0
        public OperationResult <DocumentToProcess> Handle(GetDocumentToProcess query)
        {
            if (query == null || query.DocumentId == Guid.Empty)
            {
                return(OperationResult <DocumentToProcess> .Failure(new EmptyInput()));
            }

            DocumentToProcessPersistenceModel documentToProcessPersistenceModel;

            using (var context = new ImageProcessingContext(_persistenceConfiguration))
            {
                documentToProcessPersistenceModel =
                    context.DocumentsToProcess.Single(doc => doc.Id == query.DocumentId);
            }

            //TODO: Separating .Templating and .ImageProcessing into microservices will force this query to be HTTP request, not DB call
            var getTemplateResult = _getTemplateById.Handle(new GetTemplateDefinitionById
            {
                TemplateId = documentToProcessPersistenceModel.TemplateDefinitionIdentifier
            });

            if (!getTemplateResult.Successful)
            {
                return(OperationResult <DocumentToProcess> .Failure(getTemplateResult.Details));
            }

            TemplateDefinition templateDefinition = getTemplateResult.Result;

            var bitmaps = _getDocumentBitmapsHandler.Handle(new GetBitmapsForDocumentToProcess
            {
                DocumentId = query.DocumentId
            });

            if (!bitmaps.Success)
            {
                //TODO: FileStorageQueryFailed
                return(OperationResult <DocumentToProcess> .Failure(null));
            }

            var documentToProcess = new DocumentToProcess(documentToProcessPersistenceModel.RequesterIdentifier,
                                                          templateDefinition, documentToProcessPersistenceModel.Id);

            foreach (var bitmap in bitmaps.Result)
            {
                documentToProcess.AddDocumentPageBitmap(bitmap.AsOrderedBitmap());
            }

            return(OperationResult <DocumentToProcess> .Success(documentToProcess));
        }
 public OperationResult <Nothing> Handle(SaveDomainObject <RecognizedChoicePart> command)
 {
     using (var context = new ImageProcessingContext(_persistenceConfiguration))
     {
         try
         {
             context.Set <RecognizedChoicePart>().Add(command.ObjectToSave);
             context.SaveChanges();
             return(OperationResult <Nothing> .Success(new Nothing()));
         }
         catch (Exception ex)
         {
             return(OperationResult <Nothing> .Failure(new UncaughtException(ex)));
         }
     }
 }
        public void Process(Settings settings)
        {
            var imagesPath = settings.ImagesPath;

            var context = new ImageProcessingContext();

            var images = _fileInputOutputHelper.ReadImages(imagesPath, FileType.jpg);

            foreach (var image in images)
            {
                _bitmapConverter.ApplyGrayScale(image);
                //So far gaussian is too slow
                //_bitmapConverter.ApplyGaussianBlur(image, settings);


                _fileInputOutputHelper.SaveImage(image, true);
            }
        }
Beispiel #4
0
        public OperationResult <Nothing> Handle(CreateDocumentToProcess command)
        {
            using (var context = new ImageProcessingContext(_persistenceConfiguration))
            {
                try
                {
                    var document = new DocumentToProcessPersistenceModel
                    {
                        Id = command.Id,
                        RequesterIdentifier          = command.RequesterIdentifier,
                        TemplateDefinitionIdentifier = command.TemplateDefinitionIdentifier
                    };

                    context.DocumentsToProcess.Add(document);
                    context.SaveChanges();

                    return(OperationResult <Nothing> .Success(new Nothing()));
                }
                catch (Exception ex)
                {
                    return(OperationResult <Nothing> .Failure(new UncaughtException(ex)));
                }
            }
        }