Refactor project structure in solution
Replaced "EnvelopeGenerator.WebUI" with "EnvelopeGenerator.Server" and "EnvelopeGenerator.WebUI.Client" with "EnvelopeGenerator.Server.Client". Updated project entries, solution configuration platforms, and nested projects to reflect these changes.
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
using EnvelopeGenerator.WebUI.Client.Models.Constants;
|
||||
|
||||
namespace EnvelopeGenerator.WebUI.Client.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a signature position on a PDF page.
|
||||
/// Coordinates stored in INCHES (GdPicture14 native unit).
|
||||
/// Origin: Top-left corner, X increases right, Y increases down.
|
||||
/// </summary>
|
||||
public class SignatureDto
|
||||
{
|
||||
/// <summary>Unique identifier.</summary>
|
||||
public int Id { get; init; }
|
||||
|
||||
private double _x;
|
||||
private double _y;
|
||||
|
||||
/// <summary>Horizontal position in INCHES from left edge.</summary>
|
||||
public double X
|
||||
{
|
||||
get => _x * Factor;
|
||||
init => _x = value;
|
||||
}
|
||||
|
||||
/// <summary>Vertical position in INCHES from top edge.</summary>
|
||||
public double Y
|
||||
{
|
||||
get => _y * Factor;
|
||||
init => _y = value;
|
||||
}
|
||||
|
||||
/// <summary>1-based page number.</summary>
|
||||
public int Page { get; init; }
|
||||
|
||||
/// <summary>Sender application type that created this signature.</summary>
|
||||
public SenderAppType SenderAppType { get; init; }
|
||||
|
||||
private UnitOfLength _unitOfLength;
|
||||
|
||||
public SignatureDto Convert(UnitOfLength unitOfLength)
|
||||
{
|
||||
_unitOfLength = unitOfLength;
|
||||
return this;
|
||||
}
|
||||
|
||||
public double Factor
|
||||
{
|
||||
get
|
||||
{
|
||||
if (SenderAppType != SenderAppType.LegacyFormApp)
|
||||
{
|
||||
throw new NotImplementedException(
|
||||
$"SenderAppType '{SenderAppType}' is not yet implemented. " +
|
||||
$"Currently, only '{nameof(SenderAppType.LegacyFormApp)}' is supported. " +
|
||||
$"Future implementations will handle '{nameof(SenderAppType.ReceiverUIBlazorApp)}' and other types.");
|
||||
}
|
||||
|
||||
// LegacyFormApp uses GdPicture14 with INCHES
|
||||
return _unitOfLength switch
|
||||
{
|
||||
UnitOfLength.Inch => 1.0, // No conversion needed: INCHES → INCHES
|
||||
UnitOfLength.Point => 72.0, // INCHES → PDF Points: 1 inch = 72 points (PDF standard, NOT pixels!)
|
||||
_ => throw new InvalidOperationException(
|
||||
$"Unknown UnitOfLength: {_unitOfLength}. Expected '{nameof(UnitOfLength.Inch)}' or '{nameof(UnitOfLength.Point)}'.")
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class SignatureDtoExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts all signatures in the collection to the specified unit of length.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the collection (IEnumerable, List, etc.)</typeparam>
|
||||
/// <param name="signatures">Collection of SignatureDto objects to convert.</param>
|
||||
/// <param name="unitOfLength">Target unit of measurement (Inch or Point).</param>
|
||||
/// <returns>The same collection with all signatures converted to the specified unit.</returns>
|
||||
/// <exception cref="ArgumentNullException">Thrown when signatures collection is null.</exception>
|
||||
/// <remarks>
|
||||
/// <b>Usage:</b>
|
||||
/// <code>
|
||||
/// var signatures = await SignatureService.GetAsync(envelopeKey);
|
||||
/// var convertedSignatures = signatures.ConvertAll(UnitOfLength.Point);
|
||||
/// </code>
|
||||
/// <b>Note:</b> This method modifies each SignatureDto object in place and returns the same collection.
|
||||
/// </remarks>
|
||||
public static T Convert<T>(this T signatures, UnitOfLength unitOfLength)
|
||||
where T : IEnumerable<SignatureDto>
|
||||
{
|
||||
if (signatures == null)
|
||||
throw new ArgumentNullException(nameof(signatures));
|
||||
|
||||
foreach (var signature in signatures)
|
||||
{
|
||||
signature.Convert(unitOfLength);
|
||||
}
|
||||
|
||||
return signatures;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user