This commit is contained in:
Developer01 2025-04-28 13:27:38 +02:00
commit 4f95a1eed4
6 changed files with 49 additions and 21 deletions

View File

@ -3,23 +3,8 @@
/// <summary>
/// Represents the response for reading a document.
/// </summary>
public class ReadDocumentResponse
public class ReadDocumentResponse : ReadDocumentResponseBase
{
/// <summary>
/// The unique identifier of the document.
/// </summary>
public int Guid { get; init; }
/// <summary>
/// The identifier of the associated envelope.
/// </summary>
public int EnvelopeId { get; init; }
/// <summary>
/// The date and time when the document was added.
/// </summary>
public DateTime AddedWhen { get; init; }
/// <summary>
/// The binary data of the document, if available.
/// </summary>

View File

@ -0,0 +1,22 @@
namespace EnvelopeGenerator.Application.Documents.Queries.Read;
/// <summary>
/// Represents the response for reading a document.
/// </summary>
public class ReadDocumentResponseBase
{
/// <summary>
/// The unique identifier of the document.
/// </summary>
public int Guid { get; init; }
/// <summary>
/// The identifier of the associated envelope.
/// </summary>
public int EnvelopeId { get; init; }
/// <summary>
/// The date and time when the document was added.
/// </summary>
public DateTime AddedWhen { get; init; }
}

View File

@ -281,7 +281,7 @@
<Compile Include="Entities\ElementStatus.vb" />
<Compile Include="Entities\EmailData.vb" />
<Compile Include="Entities\EmailTemplate.vb" />
<Compile Include="Jobs\PDFBurnerParams.vb" />
<Compile Include="Jobs\FinalizeDocument\PDFBurnerParams.vb" />
<Compile Include="Services\TemplateService.vb" />
<Compile Include="Entities\Envelope.vb" />
<Compile Include="Entities\EnvelopeDocument.vb" />

View File

@ -32,11 +32,27 @@ public class CommandManager
[Subcommand]
public IEnvelopeReceiverService EnvelopeReceiver => _envelopeReceiverService;
[Command]
public async Task ReadDocument(IConsole console, int? id = null, int? envelopeId = null)
[Command(ArgumentSeparatorStrategy = ArgumentSeparatorStrategy.EndOfOptions)]
public async Task ReadDocument(IConsole console,
[Option(Description = "ID of the document.")] int? id = null,
[Option(Description = "ID of the envelope containing the document.")] int? envelopeId = null,
[Option(Description = "Path to save the PDF")] bool save = false,
[Option(Description = "Directory to save the PDF")] string? dir = null,
[Option(Description = "Name of file to save the PDF")] string? fileName = null)
{
ReadDocumentQuery query = new(id, envelopeId);
var document = await _mediator.Send(query);
console.WriteLine(JsonSerializer.Serialize(document, Options));
console.WriteLine(JsonSerializer.Serialize(save ? document as ReadDocumentResponseBase : document, Options));
if (save)
{
dir ??= AppContext.BaseDirectory;
fileName ??= $"D{document?.Guid}E{document?.EnvelopeId}.pdf";
var path = Path.Combine(dir, fileName);
console.WriteLine("Save to " + path);
File.WriteAllBytes(path, document?.ByteData ?? Array.Empty<byte>());
}
}
}

View File

@ -1,4 +1,5 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
namespace EnvelopeGenerator.Terminal;
@ -8,6 +9,10 @@ public class Program
{
var builder = Host.CreateApplicationBuilder(args);
builder.Configuration
.SetBasePath(AppContext.BaseDirectory)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
var config = builder.Configuration;
builder.Services.AddCommandManagerRunner(config);