Compare commits
16 Commits
cc4a7d8c20
...
7af934ea19
| Author | SHA1 | Date | |
|---|---|---|---|
| 7af934ea19 | |||
| b65367fb6d | |||
| 25c31108cb | |||
| 4083833b19 | |||
| f53bc65acf | |||
| 070d9be00c | |||
| 6f7b04a26e | |||
| 473358e2b9 | |||
| 8f3aa69cbf | |||
| eededeb1f1 | |||
| 737774f077 | |||
| 69499273cc | |||
| ead33ab2e7 | |||
| d1e2840617 | |||
| a39ef6a0e2 | |||
| 7d620988d8 |
@@ -31,7 +31,7 @@ public class ConfigDto
|
||||
/// <summary>
|
||||
/// Gets or sets the path where exports will be saved.
|
||||
/// </summary>
|
||||
public string? ExportPath { get; set; }
|
||||
public string ExportPath { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the creation timestamp.
|
||||
|
||||
@@ -154,8 +154,7 @@ namespace EnvelopeGenerator.Domain.Entities
|
||||
#if nullable
|
||||
?
|
||||
#endif
|
||||
Type
|
||||
{ get; set; }
|
||||
Type { get; set; }
|
||||
|
||||
#if NETFRAMEWORK
|
||||
[NotMapped]
|
||||
@@ -169,22 +168,26 @@ namespace EnvelopeGenerator.Domain.Entities
|
||||
#if nullable
|
||||
?
|
||||
#endif
|
||||
Documents
|
||||
{ get; set; }
|
||||
Documents { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public Document
|
||||
#if nullable
|
||||
?
|
||||
#endif
|
||||
DefaultDocument => Documents?.FirstOrDefault();
|
||||
|
||||
public List<History>
|
||||
#if nullable
|
||||
?
|
||||
#endif
|
||||
Histories
|
||||
{ get; set; }
|
||||
Histories { get; set; }
|
||||
|
||||
public List<EnvelopeReceiver>
|
||||
#if nullable
|
||||
?
|
||||
#endif
|
||||
EnvelopeReceivers
|
||||
{ get; set; }
|
||||
EnvelopeReceivers { get; set; }
|
||||
|
||||
//#if NETFRAMEWORK
|
||||
/// <summary>
|
||||
|
||||
36
EnvelopeGenerator.Domain/Entities/EnvelopeReport.cs
Normal file
36
EnvelopeGenerator.Domain/Entities/EnvelopeReport.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace EnvelopeGenerator.Domain.Entities
|
||||
{
|
||||
[Table("VWSIG_ENVELOPE_REPORT", Schema = "dbo")]
|
||||
public class EnvelopeReport
|
||||
{
|
||||
[Column("ENVELOPE_ID", TypeName = "int")]
|
||||
[Required]
|
||||
public int EnvelopeId { get; set; }
|
||||
|
||||
[Column("HEAD_UUID", TypeName = "nvarchar(36)")]
|
||||
[Required]
|
||||
public string HeadUuid { get; set; }
|
||||
|
||||
[Column("HEAD_TITLE", TypeName = "nvarchar(128)")]
|
||||
public string HeadTitle { get; set; }
|
||||
|
||||
[Column("HEAD_MESSAGE", TypeName = "nvarchar(max)")]
|
||||
[Required]
|
||||
public string HeadMessage { get; set; }
|
||||
|
||||
[Column("POS_STATUS", TypeName = "int")]
|
||||
[Required]
|
||||
public int PosStatus { get; set; }
|
||||
|
||||
[Column("POS_WHEN", TypeName = "datetime")]
|
||||
public DateTime? PosWhen { get; set; }
|
||||
|
||||
[Column("POS_WHO", TypeName = "nvarchar(128)")]
|
||||
[Required]
|
||||
public string PosWho { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -79,6 +79,8 @@ public abstract class EGDbContextBase : DbContext
|
||||
|
||||
public DbSet<ClientUser> ClientUsers { get; set; }
|
||||
|
||||
public DbSet<EnvelopeReport> EnvelopeReports { get; set; }
|
||||
|
||||
private readonly DbTriggerParams _triggers;
|
||||
|
||||
private readonly ILogger
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.16" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
|
||||
<PackageReference Include="DevExpress.Reporting.Core" Version="24.2.*" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -18,7 +18,6 @@ public static class DependencyInjection
|
||||
services.AddScoped<PDFBurner>();
|
||||
services.AddScoped<PDFMerger>();
|
||||
services.AddScoped<ReportModel>();
|
||||
services.AddSingleton<State>();
|
||||
services.AddScoped<MSSQLServer>();
|
||||
|
||||
//TODO: Check lifetime of services. They might be singleton or scoped.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Data;
|
||||
using DigitalData.Core.Abstraction.Application.Repository;
|
||||
using EnvelopeGenerator.Domain.Constants;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using EnvelopeGenerator.ServiceHost.Exceptions;
|
||||
@@ -7,7 +8,7 @@ using EnvelopeGenerator.ServiceHost.Extensions;
|
||||
namespace EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument;
|
||||
|
||||
[Obsolete("Instead of ReportModel create and use EnvelopeReport mediator queries")]
|
||||
public class ReportCreator(ReportModel ReportModel, ILogger<ReportCreator> Logger)
|
||||
public class ReportCreator(ReportModel ReportModel, ILogger<ReportCreator> Logger, IRepository<EnvelopeReport> reportRepo)
|
||||
{
|
||||
[Obsolete("Solve the spaghetti...")]
|
||||
private Envelope? _envelope;
|
||||
|
||||
@@ -1,9 +1,94 @@
|
||||
using DevExpress.XtraReports.UI;
|
||||
using DevExpress.Drawing;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
|
||||
namespace EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument;
|
||||
|
||||
public class rptEnvelopeHistory
|
||||
public class rptEnvelopeHistory : XtraReport
|
||||
{
|
||||
public rptEnvelopeHistory()
|
||||
{
|
||||
BuildLayout();
|
||||
}
|
||||
|
||||
private void BuildLayout()
|
||||
{
|
||||
Bands.AddRange(
|
||||
[
|
||||
new TopMarginBand(),
|
||||
new BottomMarginBand(),
|
||||
new ReportHeaderBand { HeightF = 40 },
|
||||
new PageHeaderBand { HeightF = 24 },
|
||||
new DetailBand { HeightF = 22 }
|
||||
]);
|
||||
|
||||
var reportHeader = (ReportHeaderBand)Bands[nameof(ReportHeaderBand)]!;
|
||||
var pageHeader = (PageHeaderBand)Bands[nameof(PageHeaderBand)]!;
|
||||
var detail = (DetailBand)Bands[nameof(DetailBand)]!;
|
||||
|
||||
var title = new XRLabel
|
||||
{
|
||||
BoundsF = new RectangleF(0, 0, 750, 28),
|
||||
Font = new DXFont("Segoe UI", 14, DXFontStyle.Bold),
|
||||
Text = "Envelope History"
|
||||
};
|
||||
reportHeader.Controls.Add(title);
|
||||
|
||||
var headerTable = CreateTable(isHeader: true);
|
||||
pageHeader.Controls.Add(headerTable);
|
||||
|
||||
var detailTable = CreateTable(isHeader: false);
|
||||
detail.Controls.Add(detailTable);
|
||||
|
||||
Margins = new DXMargins(40, 40, 40, 40);
|
||||
PaperKind = (DevExpress.Drawing.Printing.DXPaperKind)System.Drawing.Printing.PaperKind.A4;
|
||||
}
|
||||
|
||||
private static XRTable CreateTable(bool isHeader)
|
||||
{
|
||||
var table = new XRTable
|
||||
{
|
||||
BoundsF = new RectangleF(0, 0, 750, 22),
|
||||
Borders = DevExpress.XtraPrinting.BorderSide.All
|
||||
};
|
||||
|
||||
var row = new XRTableRow();
|
||||
|
||||
if (isHeader)
|
||||
{
|
||||
row.Font = new DXFont("Segoe UI", 9, DXFontStyle.Bold);
|
||||
row.BackColor = Color.Gainsboro;
|
||||
row.Cells.Add(CreateCell("Date"));
|
||||
row.Cells.Add(CreateCell("Status"));
|
||||
row.Cells.Add(CreateCell("User"));
|
||||
row.Cells.Add(CreateCell("Title"));
|
||||
row.Cells.Add(CreateCell("Subject"));
|
||||
}
|
||||
else
|
||||
{
|
||||
row.Font = new DXFont("Segoe UI", 9, DXFontStyle.Regular);
|
||||
row.Cells.Add(CreateCell("[ItemDate]"));
|
||||
row.Cells.Add(CreateCell("[ItemStatusTranslated]"));
|
||||
row.Cells.Add(CreateCell("[ItemUserReference]"));
|
||||
row.Cells.Add(CreateCell("[EnvelopeTitle]"));
|
||||
row.Cells.Add(CreateCell("[EnvelopeSubject]"));
|
||||
}
|
||||
|
||||
table.Rows.Add(row);
|
||||
return table;
|
||||
}
|
||||
|
||||
private static XRTableCell CreateCell(string textOrExpression)
|
||||
{
|
||||
return new XRTableCell
|
||||
{
|
||||
Text = textOrExpression,
|
||||
Padding = new DevExpress.XtraPrinting.PaddingInfo(4, 4, 2, 2),
|
||||
CanGrow = false
|
||||
};
|
||||
}
|
||||
|
||||
public object? DataSource { get; set; }
|
||||
public string? DataMember { get; set; }
|
||||
|
||||
|
||||
@@ -1,24 +1,25 @@
|
||||
using System.Data;
|
||||
using DigitalData.Core.Abstraction.Application.Repository;
|
||||
using DigitalData.Modules.Database;
|
||||
using EnvelopeGenerator.Application.Common.Dto;
|
||||
using EnvelopeGenerator.Application.Configuration.Queries;
|
||||
using EnvelopeGenerator.Application.Envelopes.Queries;
|
||||
using EnvelopeGenerator.Domain.Constants;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using EnvelopeGenerator.ServiceHost.Exceptions;
|
||||
using EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument;
|
||||
using GdPicture14;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.Extensions.Options;
|
||||
using EnvelopeGenerator.ServiceHost.Extensions;
|
||||
using EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument;
|
||||
using GdPicture.Internal.MSOfficeBinary.translator.Spreadsheet.XlsFileFormat.Records;
|
||||
using GdPicture14;
|
||||
using MediatR;
|
||||
using EnvelopeGenerator.Application.Configuration.Queries;
|
||||
using EnvelopeGenerator.Application.Common.Dto;
|
||||
using EnvelopeGenerator.Application.Envelopes.Queries;
|
||||
using DigitalData.Core.Abstraction.Application.Repository;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Data;
|
||||
|
||||
namespace EnvelopeGenerator.ServiceHost.Jobs;
|
||||
|
||||
[Obsolete("ActionService is a placeholder service added by copilot. Migrate the actual logic from CommonServices.Jobs")]
|
||||
public class FinalizeDocumentJob(IOptions<WorkerOptions> options, IConfiguration config, ILogger<FinalizeDocumentJob> logger, TempFiles tempFiles, ActionService actionService, PDFBurner pdfBurner, PDFMerger pdfMerger, ReportCreator reportCreator, ReportModel _reportModel, MSSQLServer _database, GdViewer? _gdViewer, LicenseManager licenseManager, IMediator mediator, IRepository<Envelope> envRepo)
|
||||
public class FinalizeDocumentJob(IOptions<WorkerOptions> options, ILogger<FinalizeDocumentJob> logger, TempFiles tempFiles, ActionService actionService, PDFBurner pdfBurner, PDFMerger pdfMerger, ReportCreator reportCreator, GdViewer? _gdViewer, LicenseManager licenseManager, IMediator mediator, IRepository<Envelope> envRepo, IRepository<Domain.Entities.DocumentStatus> docStatusRepo)
|
||||
{
|
||||
private readonly WorkerOptions _options = options.Value;
|
||||
|
||||
@@ -36,12 +37,13 @@ public class FinalizeDocumentJob(IOptions<WorkerOptions> options, IConfiguration
|
||||
public byte[]? DocAsByte { get; set; }
|
||||
}
|
||||
|
||||
public bool RethrowOnError { get; set; } = true;
|
||||
|
||||
public async Task ExecuteAsync(CancellationToken cancel = default)
|
||||
{
|
||||
var gdPictureKey = _options.GdPictureLicenseKey;
|
||||
tempFiles.Create();
|
||||
var jobId = typeof(FinalizeDocumentJob).FullName;
|
||||
logger.LogDebug("Starting job {jobId}", jobId);
|
||||
|
||||
_config = await mediator.Send(new ReadDefaultConfigQuery(), cancel);
|
||||
|
||||
@@ -55,123 +57,58 @@ public class FinalizeDocumentJob(IOptions<WorkerOptions> options, IConfiguration
|
||||
if (envelopes.Count > 0)
|
||||
logger.LogInformation("Found [{count}] completed envelopes.", envelopes.Count);
|
||||
|
||||
var total = envelopes.Count;
|
||||
var current = 1;
|
||||
|
||||
foreach (var envelope in envelopes)
|
||||
{
|
||||
try
|
||||
{
|
||||
var envelopeData = GetEnvelopeData(envelope.Id);
|
||||
|
||||
if (envelopeData is null)
|
||||
{
|
||||
logger.LogWarning("EnvelopeData could not be loaded for Id [{id}]!", envelope.Id);
|
||||
throw new ArgumentNullException(nameof(EnvelopeData));
|
||||
}
|
||||
|
||||
logger.LogDebug("Burning Annotations to pdf ...");
|
||||
var burnedDocument = BurnAnnotationsToPdf(envelopeData);
|
||||
if (burnedDocument is null)
|
||||
{
|
||||
logger.LogWarning("Document could not be finalized!");
|
||||
throw new ApplicationException("Document could not be finalized");
|
||||
}
|
||||
|
||||
if (actionService?.CreateReport(envelope) == false)
|
||||
{
|
||||
logger.LogWarning("Document Report could not be created!");
|
||||
throw new ApplicationException("Document Report could not be created");
|
||||
}
|
||||
|
||||
logger.LogDebug("Creating report..");
|
||||
var report = reportCreator!.CreateReport(envelope);
|
||||
logger.LogDebug("Report created!");
|
||||
|
||||
logger.LogDebug("Merging documents ...");
|
||||
var mergedDocument = pdfMerger!.MergeDocuments(burnedDocument, report);
|
||||
logger.LogDebug("Documents merged!");
|
||||
|
||||
var outputDirectoryPath = Path.Combine(_config.ExportPath, _parentFolderUid);
|
||||
logger.LogDebug("oOutputDirectoryPath is {outputDirectoryPath}", outputDirectoryPath);
|
||||
if (!Directory.Exists(outputDirectoryPath))
|
||||
{
|
||||
logger.LogDebug("Directory not existing. Creating ... ");
|
||||
Directory.CreateDirectory(outputDirectoryPath);
|
||||
}
|
||||
|
||||
var outputFilePath = Path.Combine(outputDirectoryPath, $"{envelope.Uuid}.pdf");
|
||||
logger.LogDebug("Writing finalized Pdf to disk..");
|
||||
logger.LogInformation("Output path is [{outputFilePath}]", outputFilePath);
|
||||
|
||||
try
|
||||
{
|
||||
File.WriteAllBytes(outputFilePath, mergedDocument);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogWarning("Could not export final document to disk!");
|
||||
throw new ExportDocumentException("Could not export final document to disk!", ex);
|
||||
}
|
||||
|
||||
logger.LogDebug("Writing EB-bytes to database...");
|
||||
UpdateFileDb(outputFilePath, envelope.Id);
|
||||
|
||||
if (!SendFinalEmails(envelope))
|
||||
{
|
||||
throw new ApplicationException("Final emails could not be sent!");
|
||||
}
|
||||
|
||||
logger.LogInformation("Report-mails successfully sent!");
|
||||
|
||||
logger.LogDebug("Setting envelope status..");
|
||||
if (actionService?.FinalizeEnvelope(envelope) == false)
|
||||
{
|
||||
logger.LogWarning("Envelope could not be finalized!");
|
||||
throw new ApplicationException("Envelope could not be finalized");
|
||||
}
|
||||
await Finalize(envelope, cancel);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex);
|
||||
logger.LogWarning(ex, "Unhandled exception while working envelope [{id}]", envelope.Id);
|
||||
logger.LogError(ex, "Unhandled exception while working envelope [{id}]", envelope.Id);
|
||||
|
||||
if(RethrowOnError)
|
||||
throw;
|
||||
}
|
||||
|
||||
current += 1;
|
||||
logger.LogInformation("Envelope [{id}] finalized!", envelope.Id);
|
||||
}
|
||||
|
||||
logger.LogDebug("Completed job {jobId} successfully!", jobId);
|
||||
}
|
||||
|
||||
private void UpdateFileDb(string filePath, long envelopeId)
|
||||
private async Task Finalize(Envelope envelope, CancellationToken cancel)
|
||||
{
|
||||
var annotations = await docStatusRepo.Where(s => s.EnvelopeId == envelope.Id).Select(s => s.Value).ToListAsync(cancel);
|
||||
var burnedDocument = pdfBurner!.BurnAnnotsToPDF(envelope.DefaultDocument.ByteData!, annotations, envelope.Id)
|
||||
?? throw new ApplicationException("Document could not be finalized");
|
||||
|
||||
actionService.CreateReport(envelope, cancel);
|
||||
|
||||
var report = reportCreator!.CreateReport(envelope);
|
||||
|
||||
var mergedDocument = pdfMerger!.MergeDocuments(burnedDocument, report);
|
||||
|
||||
var outputDirectoryPath = Path.Combine(_config!.ExportPath, _parentFolderUid);
|
||||
|
||||
if (!Directory.Exists(outputDirectoryPath))
|
||||
Directory.CreateDirectory(outputDirectoryPath);
|
||||
|
||||
var outputFilePath = Path.Combine(outputDirectoryPath, $"{envelope.Uuid}.pdf");
|
||||
|
||||
try
|
||||
{
|
||||
var imageData = ReadFile(filePath);
|
||||
if (imageData is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var query = $"UPDATE TBSIG_ENVELOPE SET DOC_RESULT = @ImageData WHERE GUID = {envelopeId}";
|
||||
using var command = new SqlCommand(query, _database!.GetConnection);
|
||||
command.Parameters.Add(new SqlParameter("@ImageData", imageData));
|
||||
command.ExecuteNonQuery();
|
||||
File.WriteAllBytes(outputFilePath, mergedDocument);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger?.LogError(ex);
|
||||
throw new ExportDocumentException("Could not export final document to disk. Envelope Id is " + envelope.Id, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[]? ReadFile(string path)
|
||||
{
|
||||
var fileInfo = new FileInfo(path);
|
||||
var numBytes = fileInfo.Length;
|
||||
using var stream = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
using var reader = new BinaryReader(stream);
|
||||
return reader.ReadBytes((int)numBytes);
|
||||
var outputFile = await File.ReadAllBytesAsync(outputFilePath, cancel);
|
||||
await envRepo.UpdateAsync(e => e.DocResult = outputFile, e => e.Id == envelope.Id, cancel);
|
||||
|
||||
SendFinalEmails(envelope);
|
||||
|
||||
actionService?.FinalizeEnvelope(envelope, cancel);
|
||||
}
|
||||
|
||||
private bool SendFinalEmails(Envelope envelope)
|
||||
@@ -180,23 +117,17 @@ public class FinalizeDocumentJob(IOptions<WorkerOptions> options, IConfiguration
|
||||
var mailToReceivers = (FinalEmailType)(envelope.FinalEmailToReceivers ?? 0);
|
||||
|
||||
if (mailToCreator != FinalEmailType.No)
|
||||
{
|
||||
logger?.LogDebug("Sending email to creator ...");
|
||||
SendFinalEmailToCreator(envelope, mailToCreator);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger?.LogWarning("No SendFinalEmailToCreator - oMailToCreator [{0}] <> [{1}] ", mailToCreator, FinalEmailType.No);
|
||||
}
|
||||
logger?.LogWarning("No SendFinalEmailToCreator - oMailToCreator [{mailToCreator}] <> [{noFinalEmailType}] ", mailToCreator, FinalEmailType.No);
|
||||
|
||||
if (mailToReceivers != FinalEmailType.No)
|
||||
{
|
||||
logger?.LogDebug("Sending emails to receivers..");
|
||||
SendFinalEmailToReceivers(envelope, mailToReceivers);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger?.LogWarning("No SendFinalEmailToReceivers - oMailToCreator [{0}] <> [{1}] ", mailToReceivers, FinalEmailType.No);
|
||||
logger?.LogWarning("No SendFinalEmailToReceivers - oMailToCreator [{mailToReceivers}] <> [{noFinalEmailType}] ", mailToReceivers, FinalEmailType.No);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -204,12 +135,9 @@ public class FinalizeDocumentJob(IOptions<WorkerOptions> options, IConfiguration
|
||||
|
||||
private bool SendFinalEmailToCreator(Envelope envelope, FinalEmailType mailToCreator)
|
||||
{
|
||||
var includeAttachment = SendFinalEmailWithAttachment(mailToCreator);
|
||||
logger?.LogDebug("Attachment included: [{0}]", includeAttachment);
|
||||
|
||||
if (actionService?.CompleteEnvelope(envelope) == false)
|
||||
{
|
||||
logger?.LogError(new Exception("CompleteEnvelope failed"), "Envelope could not be completed for receiver [{0}]", envelope.User?.Email);
|
||||
logger?.LogError(new Exception("CompleteEnvelope failed"), "Envelope could not be completed for receiver [{email}]", envelope.User?.Email);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -218,109 +146,15 @@ public class FinalizeDocumentJob(IOptions<WorkerOptions> options, IConfiguration
|
||||
|
||||
private bool SendFinalEmailToReceivers(Envelope envelope, FinalEmailType mailToReceivers)
|
||||
{
|
||||
var includeAttachment = SendFinalEmailWithAttachment(mailToReceivers);
|
||||
logger?.LogDebug("Attachment included: [{0}]", includeAttachment);
|
||||
|
||||
foreach (var receiver in envelope.EnvelopeReceivers ?? Enumerable.Empty<EnvelopeReceiver>())
|
||||
{
|
||||
if (actionService?.CompleteEnvelope(envelope, receiver.Receiver) == false)
|
||||
{
|
||||
logger?.LogError(new Exception("CompleteEnvelope failed"), "Envelope could not be completed for receiver [{0}]", receiver.Receiver?.EmailAddress);
|
||||
logger?.LogError(new Exception("CompleteEnvelope failed"), "Envelope could not be completed for receiver [{email}]", receiver.Receiver?.EmailAddress);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool SendFinalEmailWithAttachment(FinalEmailType type)
|
||||
{
|
||||
return type == FinalEmailType.YesWithAttachment;
|
||||
}
|
||||
|
||||
private byte[] BurnAnnotationsToPdf(EnvelopeData envelopeData)
|
||||
{
|
||||
var envelopeId = envelopeData.EnvelopeId;
|
||||
|
||||
logger?.LogInformation("Burning [{0}] signatures", envelopeData.AnnotationData.Count);
|
||||
var annotations = envelopeData.AnnotationData;
|
||||
var inputPath = string.Empty;
|
||||
if (envelopeData.DocAsByte is null)
|
||||
{
|
||||
inputPath = envelopeData.DocumentPath;
|
||||
logger?.LogInformation("Input path: [{0}]", inputPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger?.LogDebug("we got bytes..");
|
||||
inputPath = _config!.DocumentPath;
|
||||
logger?.LogDebug("oInputPath: {0}", _config.DocumentPath);
|
||||
}
|
||||
|
||||
if (envelopeData.DocAsByte is null)
|
||||
{
|
||||
var directorySource = Path.GetDirectoryName(inputPath) ?? string.Empty;
|
||||
var split = directorySource.Split('\\');
|
||||
_parentFolderUid = split[^1];
|
||||
}
|
||||
else
|
||||
{
|
||||
_parentFolderUid = envelopeData.EnvelopeUuid;
|
||||
}
|
||||
|
||||
logger?.LogInformation("ParentFolderUID: [{0}]", _parentFolderUid);
|
||||
byte[] inputDocumentBuffer;
|
||||
if (envelopeData.DocAsByte is not null)
|
||||
{
|
||||
inputDocumentBuffer = envelopeData.DocAsByte;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
inputDocumentBuffer = File.ReadAllBytes(inputPath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new BurnAnnotationException("Source document could not be read from disk!", ex);
|
||||
}
|
||||
}
|
||||
|
||||
return pdfBurner!.BurnAnnotsToPDF(inputDocumentBuffer, annotations, envelopeId);
|
||||
}
|
||||
|
||||
private EnvelopeData? GetEnvelopeData(int envelopeId)
|
||||
{
|
||||
var sql = $"SELECT T.GUID, T.ENVELOPE_UUID, T.ENVELOPE_TYPE, T2.FILEPATH, T2.BYTE_DATA FROM [dbo].[TBSIG_ENVELOPE] T\n JOIN TBSIG_ENVELOPE_DOCUMENT T2 ON T.GUID = T2.ENVELOPE_ID\n WHERE T.GUID = {envelopeId}";
|
||||
var table = _database!.GetDatatable(sql);
|
||||
var row = table.Rows.Cast<DataRow>().SingleOrDefault();
|
||||
if (row is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var annotationData = GetAnnotationData(envelopeId);
|
||||
var data = new EnvelopeData
|
||||
{
|
||||
EnvelopeId = envelopeId,
|
||||
DocumentPath = row.ItemEx("FILEPATH", string.Empty),
|
||||
AnnotationData = annotationData,
|
||||
DocAsByte = row.Field<byte[]?>("BYTE_DATA"),
|
||||
EnvelopeUuid = row.ItemEx("ENVELOPE_UUID", string.Empty)
|
||||
};
|
||||
|
||||
logger?.LogDebug("Document path: [{0}]", data.DocumentPath);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private List<string> GetAnnotationData(int envelopeId)
|
||||
{
|
||||
var sql = $"SELECT VALUE FROM TBSIG_DOCUMENT_STATUS WHERE ENVELOPE_ID = {envelopeId}";
|
||||
var table = _database!.GetDatatable(sql);
|
||||
|
||||
return table.Rows.Cast<DataRow>()
|
||||
.Select(r => r.ItemEx("VALUE", string.Empty))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using DigitalData.Modules.Database;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
|
||||
namespace EnvelopeGenerator.ServiceHost.Jobs;
|
||||
|
||||
[Obsolete("Use DbContext")]
|
||||
public class State
|
||||
{
|
||||
public int UserId { get; set; }
|
||||
public FormUser? User { get; set; }
|
||||
public Config? Config { get; set; }
|
||||
public MSSQLServer? Database { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user