refactor: convert BurnPdfCommand to record and update handler to return byte[]
- Changed `BurnPdfCommand` from empty class to a `record` with properties: `SourceBuffer`, `InstantJSONList`, `EnvelopeId`. - Updated `BurnPdfCommandHandler` to implement `IRequestHandler<BurnPdfCommand, byte[]>`. - Modified `Handle` method to be async and use the `request` data to return PDF bytes. - Removed obsolete `BurnPdfCommand` class and updated related logic accordingly.
This commit is contained in:
parent
f1a140faa7
commit
55c20e83d8
@ -17,14 +17,12 @@ namespace EnvelopeGenerator.Application.Pdf;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class BurnPdfCommand : IRequest
|
public record BurnPdfCommand(byte[] SourceBuffer, List<string> InstantJSONList, int EnvelopeId) : IRequest<byte[]>;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class BurnPdfCommandHandler : IRequestHandler<BurnPdfCommand>
|
public class BurnPdfCommandHandler : IRequestHandler<BurnPdfCommand, byte[]>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -52,26 +50,6 @@ public class BurnPdfCommandHandler : IRequestHandler<BurnPdfCommand>
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="pSourceBuffer"></param>
|
|
||||||
/// <param name="pInstantJSONList"></param>
|
|
||||||
/// <param name="envelopeId"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public byte[] BurnAnnotsToPDF(byte[] pSourceBuffer, List<string> pInstantJSONList, int envelopeId)
|
|
||||||
{
|
|
||||||
// read the elements of envelope with their annotations
|
|
||||||
var elements = _signRepo
|
|
||||||
.Where(sig => sig.Document.EnvelopeId == envelopeId)
|
|
||||||
.Include(sig => sig.Annotations)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
return elements.Any()
|
|
||||||
? BurnElementAnnotsToPDF(pSourceBuffer, elements)
|
|
||||||
: BurnInstantJSONAnnotsToPDF(pSourceBuffer, pInstantJSONList);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -347,7 +325,8 @@ public class BurnPdfCommandHandler : IRequestHandler<BurnPdfCommand>
|
|||||||
_manager.AddFreeHandAnnot(oColor, oPoints);
|
_manager.AddFreeHandAnnot(oColor, oPoints);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void AddInkAnnotation(Annotation pAnnotation)
|
|
||||||
|
private void AddInkAnnotation(Annotation pAnnotation)
|
||||||
{
|
{
|
||||||
var oSegments = pAnnotation.Lines?.Points;
|
var oSegments = pAnnotation.Lines?.Points;
|
||||||
var oColor = ColorTranslator.FromHtml(pAnnotation.StrokeColor ?? "#000000");
|
var oColor = ColorTranslator.FromHtml(pAnnotation.StrokeColor ?? "#000000");
|
||||||
@ -388,11 +367,19 @@ public class BurnPdfCommandHandler : IRequestHandler<BurnPdfCommand>
|
|||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancel"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="NotImplementedException"></exception>
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
public Task Handle(BurnPdfCommand request, CancellationToken cancellationToken)
|
public async Task<byte[]> Handle(BurnPdfCommand request, CancellationToken cancel)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
// read the elements of envelope with their annotations
|
||||||
|
var elements = await _signRepo
|
||||||
|
.Where(sig => sig.Document.EnvelopeId == request.EnvelopeId)
|
||||||
|
.Include(sig => sig.Annotations)
|
||||||
|
.ToListAsync(cancel);
|
||||||
|
|
||||||
|
return elements.Count > 0
|
||||||
|
? BurnElementAnnotsToPDF(request.SourceBuffer, elements)
|
||||||
|
: BurnInstantJSONAnnotsToPDF(request.SourceBuffer, request.InstantJSONList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2,10 +2,11 @@
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
#elif NET
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Domain.Entities
|
namespace EnvelopeGenerator.Domain.Entities
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user