README.md

April 7, 2020 ยท View on GitHub

Overview

This is a Razor provider and transform for Transformalize using RazorEngine for the .NET Framework and RazorEngineCore for .NET Core.

Write Usage

<add name='TestProcess' mode='init'>
  <connections>
    <add name='input' provider='bogus' seed='1' />
    <add name='output' provider='Razor' template='template.cshtml' file='output.html' />
  </connections>
  <entities>
    <add name='Contact' size='1000'>
      <fields>
        <add name='Identity' type='int' primary-key='true' />
        <add name='FirstName' />
        <add name='LastName' />
        <add name='Stars' type='byte' min='1' max='5' />
        <add name='Reviewers' type='int' min='0' max='500' />
      </fields>
    </add>
  </entities>
</add>

This writes 1000 rows of bogus data to output.html.

The template template.cshtml is passed a RazorModel. The template in this example looks like this:

@model Transformalize.Providers.Razor.RazorModel
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>Razor Output</title>
</head>
<body>
    <table>
        <thead>
            <tr>
                @foreach (var field in Model.Entity.Fields.Where(f => !f.System)) {
                    <th>@field.Label</th>
                }
            </tr>
        </thead>
        <tbody>
            @foreach (var row in Model.Rows) {
                <tr>
                    @foreach (var field in Model.Entity.Fields.Where(f => !f.System)) {
                        <td>@(row[field])</td>
                    }
                </tr>
                ++Model.Entity.Inserts;
            }
        </tbody>
    </table>
</body>
</html>

The table in output.html looks like this (clipped for brevity):

Identity FirstName LastName Stars Reviewers
1 Justin Konopelski 3 153
2 Eula Schinner 2 41
3 Tanya Shanahan 4 412
4 Emilio Hand 4 469
5 Rachel Abshire 3 341

Benchmark

Note: Numbers get better with more records.


BenchmarkDotNet=v0.11.3, OS=Windows 10.0.18363
Intel Core i7-7700HQ CPU 2.80GHz (Kaby Lake), 1 CPU, 8 logical and 4 physical cores
  [Host]       : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 32bit LegacyJIT-v4.8.4150.0
  LegacyJitX64 : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 64bit LegacyJIT/clrjit-v4.8.4150.0;compatjit-v4.8.4150.0

Job=LegacyJitX64  Jit=LegacyJit  Platform=X64  
Runtime=Clr  

MethodMeanErrorStdDevRatioRatioSD
'10000 test rows'871.0 ms12.63 ms11.82 ms1.000.00
'10000 rows with 1 razor'1,222.3 ms23.75 ms30.03 ms1.410.05

BenchmarkDotNet=v0.12.0, OS=Windows 10.0.18363
Intel Core i7-7700HQ CPU 2.80GHz (Kaby Lake), 1 CPU, 8 logical and 4 physical cores
.NET Core SDK=3.1.201
  [Host]    : .NET Core 3.1.3 (CoreCLR 4.700.20.11803, CoreFX 4.700.20.12001), X64 RyuJIT
  RyuJitX64 : .NET Core 3.1.3 (CoreCLR 4.700.20.11803, CoreFX 4.700.20.12001), X64 RyuJIT

Job=RyuJitX64  Jit=RyuJit  Platform=X64  

MethodMeanErrorStdDevRatio
'10000 test rows'649.3 ms5.51 ms5.15 ms1.00
'10000 rows with 1 razor'850.6 ms7.03 ms6.58 ms1.31