Пример #1
0
        private async Task ProcessMrzAsync(
            IReadOnlyList <string> files,
            Options options,
            object state)
        {
            Console.WriteLine($"Starting MRZ processing of {files.Count} files");

            foreach (var file in files)
            {
                Console.WriteLine($"Starting processing of file: {file}");
                TaskInfo task;
                options.SourcePath = file;
                var parameters = ProcessingParamsBuilder.GetMrzProcessingParams();

                using (_scope.Start("Uploading"))
                    using (var fileStream = File.OpenRead(file))
                    {
                        task = await _ocrClient.ProcessMrzAsync(parameters, fileStream, options.FileName).ConfigureAwait(false);
                    }

                UploadFileCompleted?.Invoke(this, new UploadCompletedEventArgs(task, state));

                task = await WaitTaskAsync(task.TaskId, state).ConfigureAwait(false);

                await DownloadResultFilesAsync(task, options, state).ConfigureAwait(false);
            }

            Console.WriteLine("Processing has completed");
        }
Пример #2
0
        private async Task ProcessFieldsAsync(
            IReadOnlyList <string> files,
            Options options,
            object state)
        {
            Console.WriteLine($"Starting Fields processing of {files.Count} files");

            if (files.Count == 0)
            {
                return;
            }

            var task = await SubmitImagesAsync(files, state).ConfigureAwait(false);

            var parameters = ProcessingParamsBuilder.GetFieldsProcessingParams(task.TaskId);

            if (task is null)
            {
                throw new InvalidOperationException();
            }

            using (var fileStream = File.OpenRead(options.XmlSettingsPath))
            {
                task = await _ocrClient.ProcessFieldsAsync(parameters, fileStream, "fieldResult").ConfigureAwait(false);
            }

            task = await WaitTaskAsync(task.TaskId, state).ConfigureAwait(false);

            await DownloadResultFilesAsync(task, options, state).ConfigureAwait(false);

            Console.WriteLine("Processing has completed");
        }
Пример #3
0
        private async Task ProcessFilesAsync(
            IReadOnlyList <string> files,
            Options options,
            object state)
        {
            Console.WriteLine($"Starting the processing of {files.Count} files");

            if (files.Count == 0)
            {
                return;
            }

            var task = await SubmitImagesAsync(files, state).ConfigureAwait(false);

            if (task is null)
            {
                throw new InvalidOperationException();
            }

            var parameters = ProcessingParamsBuilder.GetDocumentProcessingParams(task.TaskId, options);

            task = await _ocrClient.ProcessDocumentAsync(parameters).ConfigureAwait(false);

            task = await WaitTaskAsync(task.TaskId, state).ConfigureAwait(false);

            await DownloadResultFilesAsync(task, options, state).ConfigureAwait(false);

            Console.WriteLine("Processing has completed");
        }
Пример #4
0
        private Task <TaskInfo> StartFieldProcessingAsync(
            Stream fileStream,
            Options options)
        {
            switch (options.Mode)
            {
            case Mode.TextField:
                var textParams = ProcessingParamsBuilder.GetTextFieldProcessingParams(options);
                return(_ocrClient.ProcessTextFieldAsync(textParams, fileStream, options.FileName));

            case Mode.BarcodeField:
                var barcodeParams = ProcessingParamsBuilder.GetBarcodeFieldProcessingParams();
                return(_ocrClient.ProcessBarcodeFieldAsync(barcodeParams, fileStream, options.FileName));

            case Mode.CheckmarkField:
                var checkmarkParams = ProcessingParamsBuilder.GetCheckmarkFieldProcessingParams();
                return(_ocrClient.ProcessCheckmarkFieldAsync(checkmarkParams, fileStream, options.FileName));

            default:
                throw new InvalidOperationException("Wrong operation");
            }
        }
Пример #5
0
        private async Task ProcessFileAsync(string filePath, Options options, object state)
        {
            Console.WriteLine($"Start single file processing: {filePath}");

            TaskInfo task;

            var parameters = ProcessingParamsBuilder.GetImageProcessingParams(options);

            using (_scope.Start("Uploading"))
                using (var fileStream = File.OpenRead(filePath))
                {
                    task = await _ocrClient.ProcessImageAsync(parameters, fileStream, options.FileName).ConfigureAwait(false);
                }

            UploadFileCompleted?.Invoke(this, new UploadCompletedEventArgs(task, state));

            task = await WaitTaskAsync(task.TaskId, state).ConfigureAwait(false);

            await DownloadResultFilesAsync(task, options, state).ConfigureAwait(false);

            Console.WriteLine("Processing has completed");
        }