Skip to content

Commit 99ef657

Browse files
committed
Tidy-ups
Re-added lookupExtension (accidentally overwritten earlier) Remove DV Hub, old example
1 parent 111436b commit 99ef657

File tree

4 files changed

+46
-8
lines changed

4 files changed

+46
-8
lines changed

DataWarehouseAutomation/DataWarehouseAutomation.sln

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sample Metadata", "Sample M
2525
Sample_Metadata\sampleBasicWithExtensions.json = Sample_Metadata\sampleBasicWithExtensions.json
2626
Sample_Metadata\sampleCalculation.json = Sample_Metadata\sampleCalculation.json
2727
Sample_Metadata\sampleCustomFunctions.json = Sample_Metadata\sampleCustomFunctions.json
28-
Sample_Metadata\sampleDataVaultHub.json = Sample_Metadata\sampleDataVaultHub.json
2928
Sample_Metadata\sampleFreeForm.json = Sample_Metadata\sampleFreeForm.json
3029
Sample_Metadata\sampleMultipleDataItemMappings.json = Sample_Metadata\sampleMultipleDataItemMappings.json
3130
Sample_Metadata\sampleSimpleDDL.json = Sample_Metadata\sampleSimpleDDL.json

DataWarehouseAutomation/DataWarehouseAutomation/Utils/HandleBarsHelpers.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace DataWarehouseAutomation.Utils;
1+
using HandlebarsDotNet;
2+
3+
namespace DataWarehouseAutomation.Utils;
24

35
public static class HandlebarsHelpers
46
{
@@ -530,5 +532,42 @@ public static void RegisterHandlebarsHelpers()
530532
throw new HandlebarsException($"The {{{{hasStringValue}}}} function encountered an error. The list of strings provided as the first argument could not be deserialized. The reported error is: '{ex.Message}'.");
531533
}
532534
});
535+
536+
// lookupExtension allows a lookup of an extension value by key value. Pass in the Extensions list and the string key value.
537+
Handlebars.RegisterHelper("lookupExtension", (writer, _, parameters) =>
538+
{
539+
// Check if the parameters are valid.
540+
if (parameters.Length != 2 || parameters[1] is not string)
541+
{
542+
throw new HandlebarsException("\rThe {{lookupExtension}} helper expects two arguments: a List<Extension> and a string lookup key");
543+
}
544+
545+
var extensionList = new List<Extension>();
546+
547+
// Deserialize the extensions.
548+
try
549+
{
550+
extensionList = JsonSerializer.Deserialize<List<Extension>>(parameters[0].ToString() ?? string.Empty);
551+
}
552+
catch (Exception exception)
553+
{
554+
throw new HandlebarsException($"\rThe {{{{lookupExtension}}}} helper function encountered an error. \r\rThe list of extensions provided as the first argument could not be deserialized, it probably wasn't available or found. Can you check the location of the extension? \r\rThe code so far is:\r\r{writer}\r\rThe reported error is:\r\r'{exception.Message}'");
555+
}
556+
557+
// Write the result.
558+
string key = "";
559+
try
560+
{
561+
key = (string)parameters[1];
562+
var result = extensionList?.Find(i => i.Key.Equals(key, StringComparison.OrdinalIgnoreCase))?.Value ?? "";
563+
564+
writer.WriteSafeString($"{result}");
565+
}
566+
catch (Exception exception)
567+
{
568+
throw new HandlebarsException($"The {{{{lookupExtension}}}} helper function encountered an error. \r\rNo extension could be found for {key}. \r\rThe reported error is :\r\r'{exception.Message}'");
569+
}
570+
571+
});
533572
}
534573
}

DataWarehouseAutomation/Example_Project/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private static void DisplayPatternResult(string patternFile, string jsonMetadata
5656
}
5757
catch (Exception ex)
5858
{
59-
Console.WriteLine($"An issue was encountered: {ex}");
59+
Console.WriteLine($"An issue was encountered while generating {patternFile} from {jsonMetadataFile}: {ex}");
6060
Console.ReadKey();
6161
}
6262
}

DataWarehouseAutomation/Sample_Templates/TemplateSampleMultipleDataItemMappings.Handlebars

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
--Example where multiple sources map to a single target.
33
{{#each dataObjectMappings }}
44

5-
--Working on {{name}}
5+
--Working on '{{name}}'
66

7-
Explaining mappings of multiple sources to one target, in this case {{targetDataObject.name}}.
7+
Explaining mappings of multiple sources to one target, in this case '{{targetDataObject.name}}'.
88

99
The following source Data Objects map to a single target:
1010
{{#each sourceDataObjects}}
11-
- {{name}}
11+
- '{{name}}'
1212
{{/each}}
1313

14-
Or, in other words {{sourceDataObjects.0.name}} and {{sourceDataObjects.1.name}} map to {{targetDataObject.name}}.
14+
Or, in other words '{{sourceDataObjects.0.name}}' and '{{sourceDataObjects.1.name}}' map to '{{targetDataObject.name}}'.
1515

1616
The same applies at Data Item Mapping level, where the following Data Item mappings are defined:
1717

1818
{{#each dataItemMappings}}
19-
{{#each sourceDataItems}} {{name}}{{#unless @last}} and{{/unless}}{{/each}} map(s) to {{targetDataItem.name}}.
19+
{{#each sourceDataItems}} '{{name}}'{{#unless @last}} and{{/unless}}{{/each}} map(s) to '{{targetDataItem.name}}'.
2020

2121
{{/each}}
2222

0 commit comments

Comments
 (0)