public async Task Consume(ConsumeContext <ConversionStartRequest> context) { using (LogContext.PushProperty(nameof(context.ConversationId), context.ConversationId)) { FileInfo sourceFile = null; try { Log.Information("Received {CommandName} command with conversationId {ConversationId} from the bus", nameof(ConversionStartRequest), context.ConversationId); var jobGuid = context.Message.JobGuid; var jobInfo = sftpServer.GetJobInfo(jobGuid); if (jobInfo == null) { Log.Error("Could not retrieve information about job with id {jobGuid}", jobGuid); throw new InvalidOperationException($"Could not retrieve information about job with id {jobGuid}"); } // Get source file sourceFile = new FileInfo(Path.Combine(sftpServer.GetJobDirectory(jobGuid).FullName, new FileInfo(jobInfo.Request.FileNameWithExtension).Name)); if (!sourceFile.Exists) { throw new FileNotFoundException(sourceFile.FullName); } Log.Information("Starting conversion for file {FullName} with job id {jobGuid}", sourceFile.FullName, jobGuid); var result = manager.Convert(jobGuid, sourceFile, context.Message.DestinationExtension, context.Message.VideoQuality); Log.Information("Finished conversion for file {FullName} with job id {jobGuid}", sourceFile.FullName, jobGuid); await context.RespondAsync(new ConversionStartResult { ConvertedFileName = result.Name, JobGuid = jobGuid, Password = jobInfo.Result.Password, Port = jobInfo.Result.Port, UploadUrl = jobInfo.Result.UploadUrl, User = jobInfo.Result.User }); } catch (Exception e) { var message = e.Message; try { // ReSharper disable once PossibleNullReferenceException message += $" (File: {sourceFile.FullName})"; } catch { // Hier ist nichts zu tun } Log.Error(e, message); await context.RespondAsync(new ConversionStartResult { IsInvalid = true, ErrorMessage = e.Message }); } } }
public async Task Consume(ConsumeContext <ExtractionStartRequest> context) { using (LogContext.PushProperty(nameof(context.ConversationId), context.ConversationId)) { var jobGuid = context.Message.JobGuid; try { Log.Information("Received {CommandName} command with conversationId {ConversationId} from the bus", nameof(ExtractionStartConsumer), context.ConversationId); var jobInfo = sftpServer.GetJobInfo(jobGuid); if (jobInfo == null) { Log.Error("Could not retrieve information about job with id {jobGuid}", jobGuid); throw new InvalidOperationException($"Could not retrieve information about job with id {jobGuid}"); } // Get source file var sourceFile = new FileInfo(Path.Combine(Path.Combine(DocumentConverterSettings.Default.BaseDirectory, jobGuid, new FileInfo(jobInfo.Request.FileNameWithExtension).Name))); if (!sourceFile.Exists) { throw new FileNotFoundException(sourceFile.FullName); } Log.Information("Starting text extraction for file {FullName} with job id {jobGuid} for archive record id {archiveRecordId}", sourceFile.FullName, jobGuid, jobInfo.Request.Context.ArchiveRecordId); var extractionResult = manager.ExtractText(jobGuid, sourceFile, jobInfo.Request.Context); Log.Information("Finished text extraction for file {FullName} with job id {jobGuid} for archive record id {archiveRecordId}", sourceFile.FullName, jobGuid, jobInfo.Request.Context.ArchiveRecordId); // Depending on the OCR extraction result, we prepare the result var result = new ExtractionStartResult(); if (!extractionResult.HasError) { result.Text = extractionResult.ToString(); } else { result.IsInvalid = true; result.ErrorMessage = extractionResult.ErrorMessage; } await context.RespondAsync(result); } catch (Exception e) { Log.Error(e, e.Message); await context.RespondAsync(new ExtractionStartResult { IsInvalid = true, ErrorMessage = e.Message }); } finally { sftpServer.RemoveJob(jobGuid); } } }