Add "Full Finalize Test" button for PDF finalization debug

Added a new "Full Finalize Test" button to frmFinalizePDF, along with its event handler. The handler loads annotation data, document bytes, and related entities, logs detailed information about the envelope and signatures, and tests the PDF annotation burning process. The result is saved to the desktop and opened automatically. Also added necessary repository/entity imports for EF Core access. This feature aids in debugging and verifying the full PDF finalization workflow.
This commit is contained in:
2026-03-10 02:16:58 +01:00
parent 82c85643c8
commit c523153654
2 changed files with 96 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ Partial Class frmFinalizePDF
Me.Label2 = New System.Windows.Forms.Label()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.Button3 = New System.Windows.Forms.Button()
Me.txtResult = New System.Windows.Forms.TextBox()
Me.txtEnvelope = New System.Windows.Forms.TextBox()
Me.SuspendLayout()
@@ -75,6 +76,15 @@ Partial Class frmFinalizePDF
Me.Button2.Text = "Merge Json"
Me.Button2.UseVisualStyleBackColor = True
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(15, 160)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(166, 23)
Me.Button3.TabIndex = 5
Me.Button3.Text = "Full Finalize Test"
Me.Button3.UseVisualStyleBackColor = True
'
'txtResult
'
Me.txtResult.Location = New System.Drawing.Point(333, 12)
@@ -97,6 +107,7 @@ Partial Class frmFinalizePDF
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(800, 450)
Me.Controls.Add(Me.txtResult)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.Label2)
@@ -116,5 +127,6 @@ Partial Class frmFinalizePDF
Friend WithEvents Label2 As Label
Friend WithEvents Button1 As Button
Friend WithEvents Button2 As Button
Friend WithEvents Button3 As Button
Friend WithEvents txtResult As TextBox
End Class

View File

@@ -8,6 +8,8 @@ Imports Newtonsoft.Json.Linq
Imports EnvelopeGenerator.Infrastructure
Imports Microsoft.EntityFrameworkCore
Imports DigitalData.Core.Abstractions
Imports DigitalData.Core.Abstraction.Application.Repository
Imports EnvelopeGenerator.Domain.Entities
Public Class frmFinalizePDF
Private Const CONNECTIONSTRING = "Server=sDD-VMP04-SQL17\DD_DEVELOP01;Database=DD_ECM;User Id=sa;Password=+bk8oAbbQP1AzoHtvZUbd+Mbok2f8Fl4miEx1qssJ5yEaEWoQJ9prg4L14fURpPnqi1WMNs9fE4=;" + "Encrypt=True;TrustServerCertificate=True;"
@@ -124,4 +126,86 @@ Public Class frmFinalizePDF
txtResult.Text = oJObject1.ToString()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Try
Dim envelopeId As Integer = CInt(txtEnvelope.Text)
Dim log As New System.Text.StringBuilder()
' 1. Load annotation JSON data (same as Service)
Dim oTable = LoadAnnotationDataForEnvelope()
Dim oJsonList = oTable.Rows.
Cast(Of DataRow).
Select(Function(r As DataRow) r.Item("VALUE").ToString()).
ToList()
log.AppendLine($"Annotation JSON count: {oJsonList.Count}")
' 2. Load document bytes (same as Service)
Dim oBuffer As Byte() = ReadEnvelope(envelopeId)
log.AppendLine($"Document bytes: {oBuffer.Length}")
' 3. Check what BurnAnnotsToPDF will do internally
Using scope = Factory.Shared.ScopeFactory.CreateScope()
Dim envRepo = scope.ServiceProvider.Repository(Of Envelope)()
Dim envelope = envRepo.Where(Function(env) env.Id = envelopeId).FirstOrDefault()
If envelope Is Nothing Then
log.AppendLine("ERROR: Envelope not found in EF Core!")
txtResult.Text = log.ToString()
Return
End If
log.AppendLine($"Envelope found: Id={envelope.Id}, EnvelopeTypeId={envelope.EnvelopeTypeId}")
log.AppendLine($"ReadOnly (IsReadAndConfirm): {envelope.ReadOnly}")
If envelope.ReadOnly Then
log.AppendLine(">>> EARLY RETURN: ReadOnly=True, original PDF returned without burning")
txtResult.Text = log.ToString()
Return
End If
Dim sigRepo = scope.ServiceProvider.Repository(Of Signature)()
Dim elements = sigRepo _
.Where(Function(sig) sig.Document.EnvelopeId = envelopeId) _
.Include(Function(sig) sig.Annotations) _
.ToList()
log.AppendLine($"Elements (Signature) count: {elements.Count}")
If elements.Any() Then
log.AppendLine(">>> PATH: BurnElementAnnotsToPDF (new element-based path)")
For Each elem In elements
Dim annotCount = If(elem.Annotations IsNot Nothing, elem.Annotations.Count(), 0)
log.AppendLine($" Element Id={elem.Id}, Page={elem.Page}, X={elem.X}, Y={elem.Y}, W={elem.Width}, H={elem.Height}, Annotations={annotCount}")
If elem.Annotations IsNot Nothing Then
For Each annot In elem.Annotations
log.AppendLine($" Annot: Name={annot.Name}, Type={annot.Type}, X={annot.X}, Y={annot.Y}, W={annot.Width}, H={annot.Height}")
Next
End If
Next
Else
log.AppendLine(">>> PATH: BurnInstantJSONAnnotsToPDF (old JSON-based path)")
End If
End Using
' 4. Actually call BurnAnnotsToPDF (same as Service)
log.AppendLine("")
log.AppendLine("Calling BurnAnnotsToPDF...")
Dim oNewBuffer = PDFBurner.BurnAnnotsToPDF(oBuffer, oJsonList, envelopeId)
log.AppendLine($"Result bytes: {oNewBuffer.Length}")
log.AppendLine($"Same as input: {oBuffer.Length = oNewBuffer.Length AndAlso oBuffer.SequenceEqual(oNewBuffer)}")
' 5. Write output
Dim desktopPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim oNewPath = Path.Combine(desktopPath, $"E{txtEnvelope.Text}_FullTest.burned.pdf")
File.WriteAllBytes(oNewPath, oNewBuffer)
log.AppendLine($"Output: {oNewPath}")
txtResult.Text = log.ToString()
Process.Start(oNewPath)
Catch ex As Exception
txtResult.Text = $"ERROR: {ex.Message}{vbCrLf}{vbCrLf}{ex.ToString()}"
End Try
End Sub
End Class