Skip to content

Latest commit

 

History

History
97 lines (73 loc) · 2.49 KB

File metadata and controls

97 lines (73 loc) · 2.49 KB

TX Text Control Template Dependency Checker

Checks TX Text Control templates for dependencies that are missing from the runtime environment or from the template contract.

What It Checks

  • Fonts that are not available and trigger AdaptFont.
  • Referenced images whose FileName points to a missing file.
  • JSON data fields that do not exist as merge fields or form fields in the template.
  • JSON array properties that do not exist as merge blocks in the template.
  • JSON array item fields that do not exist as merge fields in the template.

Merge blocks are detected from SubTextPart names that use the TX Text Control merge block prefix txmb_.

Basic Usage

using TXTextControl.DocumentServer.Validation;

var checker = new TemplateDependencyChecker();

TemplateDependencyInfo info = checker.Check(
    "test.tx",
    TXTextControl.StreamType.InternalUnicodeFormat);

Check Against JSON Data

using TXTextControl.DocumentServer.Validation;

const string jsonData = """
{
  "customer": {
    "name": "Text Control",
    "firstName": "Text"
  },
  "lineItems": []
}
""";

var checker = new TemplateDependencyChecker();

TemplateDependencyInfo info = checker.Check(
    "test.tx",
    TXTextControl.StreamType.InternalUnicodeFormat,
    jsonData);

Reading Results

foreach (MissingFontDependency font in info.MissingFonts)
{
    Console.WriteLine($"Missing font: {font.FontName}");
}

foreach (MissingImageDependency image in info.MissingImages)
{
    Console.WriteLine($"Missing image: {image.FileName}");
}

if (info.DataDependencies is { } data)
{
    foreach (MissingDocumentFieldDependency field in data.MissingDocumentFields)
    {
        Console.WriteLine($"Merge field missing in document: {field.Name}");
    }

    foreach (MissingDocumentMergeBlockDependency block in data.MissingDocumentMergeBlocks)
    {
        Console.WriteLine($"Merge block missing in document: {block.Name}");
    }
}

Matching Rules

Scalar JSON fields use exact dot-notation matching. For example, customer.firstName must exist as customer.firstName in a merge field or form field.

Dotted JSON fields can also be satisfied by a merge block and an inner merge field. For example, customer.name is considered present if the template contains a customer merge block and a merge field named name.

Merge block names are matched leniently so lineItems can match a SubTextPart named txmb_lineItems.

Run The Sample

cd tx-check-template-dependencies
dotnet run