|
3 | 3 | using DataWarehouseAutomation; |
4 | 4 | using HandlebarsDotNet; |
5 | 5 | using Newtonsoft.Json; |
| 6 | +using Newtonsoft.Json.Linq; |
6 | 7 |
|
7 | 8 | namespace Example_Handlebars |
8 | 9 | { |
9 | 10 | class Program |
10 | 11 | { |
11 | 12 | static void Main(string[] args) |
12 | 13 | { |
13 | | - HandleBarsHelpers.RegisterHandleBarsHelpers(); |
| 14 | + HandleBarsHelpers.RegisterHandleBarsHelpers();; |
14 | 15 |
|
15 | | - // Local variables |
| 16 | + // Local variables, for reuse |
16 | 17 | string stringTemplate = ""; |
17 | 18 | string jsonInput = ""; |
18 | 19 | string result = ""; |
19 | | - DataObjectMappings deserialisedMapping = new DataObjectMappings(); |
| 20 | + //DataObjectMappings deserialisedMapping = new DataObjectMappings(); |
| 21 | + var deserialisedMapping = new JObject(); |
| 22 | + var template = Handlebars.Compile(""); |
20 | 23 |
|
21 | 24 | // Simple example template |
22 | | - stringTemplate = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"..\..\..\Sample_Templates\TemplateSampleBasic.handlebars"); |
23 | | - var template = Handlebars.Compile(stringTemplate); |
24 | | - jsonInput = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"..\..\..\Sample_Metadata\sampleBasic.json"); |
25 | | - deserialisedMapping = JsonConvert.DeserializeObject<DataObjectMappings>(jsonInput); |
26 | | - result = template(deserialisedMapping); |
27 | | - Console.WriteLine(result); |
| 25 | + try |
| 26 | + { |
| 27 | + stringTemplate = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"..\..\..\Sample_Templates\TemplateSampleBasic.handlebars"); |
| 28 | + template = Handlebars.Compile(stringTemplate); |
| 29 | + jsonInput = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"..\..\..\Sample_Metadata\sampleBasic.json"); |
| 30 | + //deserialisedMapping = JsonConvert.DeserializeObject<DataObjectMappings>(jsonInput); |
| 31 | + deserialisedMapping = JObject.Parse(jsonInput); |
| 32 | + result = template(deserialisedMapping); |
| 33 | + Console.WriteLine(result); |
| 34 | + } |
| 35 | + catch (Exception ex) |
| 36 | + { |
| 37 | + Console.WriteLine($"An issue was encountered: {ex}"); |
| 38 | + } |
28 | 39 |
|
29 | 40 | // Example using extensions |
30 | 41 | stringTemplate = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"..\..\..\Sample_Templates\TemplateSampleBasicWithExtensions.handlebars"); |
31 | 42 | template = Handlebars.Compile(stringTemplate); |
32 | 43 | jsonInput = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"..\..\..\Sample_Metadata\sampleBasicWithExtensions.json"); |
33 | | - deserialisedMapping = JsonConvert.DeserializeObject<DataObjectMappings>(jsonInput); |
| 44 | + //deserialisedMapping = JsonConvert.DeserializeObject<DataObjectMappings>(jsonInput); |
| 45 | + deserialisedMapping = JObject.Parse(jsonInput); |
34 | 46 | result = template(deserialisedMapping); |
35 | 47 | Console.WriteLine(result); |
36 | 48 |
|
37 | 49 | // Example using more than one mapping at data item level |
38 | 50 | stringTemplate = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"..\..\..\Sample_Templates\TemplateSampleMultipleDataItemMappings.handlebars"); |
39 | 51 | template = Handlebars.Compile(stringTemplate); |
40 | 52 | jsonInput = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"..\..\..\Sample_Metadata\sampleMultipleDataItemMappings.json"); |
41 | | - deserialisedMapping = JsonConvert.DeserializeObject<DataObjectMappings>(jsonInput); |
| 53 | + //deserialisedMapping = JsonConvert.DeserializeObject<DataObjectMappings>(jsonInput); |
| 54 | + deserialisedMapping = JObject.Parse(jsonInput); |
42 | 55 | result = template(deserialisedMapping); |
43 | 56 | Console.WriteLine(result); |
44 | 57 |
|
45 | 58 | // Example generating DDL statements |
46 | 59 | stringTemplate = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"..\..\..\Sample_Templates\TemplateSampleSimpleDDL.handlebars"); |
47 | 60 | template = Handlebars.Compile(stringTemplate); |
48 | 61 | jsonInput = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"..\..\..\Sample_Metadata\sampleSimpleDDL.json"); |
49 | | - deserialisedMapping = JsonConvert.DeserializeObject<DataObjectMappings>(jsonInput); |
| 62 | + //deserialisedMapping = JsonConvert.DeserializeObject<DataObjectMappings>(jsonInput); |
| 63 | + deserialisedMapping = JObject.Parse(jsonInput); |
50 | 64 | result = template(deserialisedMapping); |
51 | 65 | Console.WriteLine(result); |
52 | 66 |
|
53 | 67 | // Example using OneOf / swapping a source for a query |
54 | 68 | stringTemplate = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"..\..\..\Sample_Templates\TemplateSampleCalculation.handlebars"); |
55 | 69 | template = Handlebars.Compile(stringTemplate); |
56 | 70 | jsonInput = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"..\..\..\Sample_Metadata\sampleCalculation.json"); |
57 | | - deserialisedMapping = JsonConvert.DeserializeObject<DataObjectMappings>(jsonInput); |
| 71 | + //deserialisedMapping = JsonConvert.DeserializeObject<DataObjectMappings>(jsonInput); |
| 72 | + deserialisedMapping = JObject.Parse(jsonInput); |
58 | 73 | result = template(deserialisedMapping); |
59 | 74 | Console.WriteLine(result); |
60 | 75 |
|
61 | 76 | // Data Vault Satellite example |
62 | 77 | stringTemplate = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"..\..\..\Sample_Templates\TemplateSatelliteView.handlebars"); |
63 | 78 | template = Handlebars.Compile(stringTemplate); |
64 | 79 | jsonInput = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"..\..\..\Sample_Metadata\sampeVDW_Sat_Customer_v161.json"); |
65 | | - deserialisedMapping = JsonConvert.DeserializeObject<DataObjectMappings>(jsonInput); |
| 80 | + //deserialisedMapping = JsonConvert.DeserializeObject<DataObjectMappings>(jsonInput); |
| 81 | + deserialisedMapping = JObject.Parse(jsonInput); |
| 82 | + result = template(deserialisedMapping); |
| 83 | + Console.WriteLine(result); |
| 84 | + |
| 85 | + //Free form example |
| 86 | + stringTemplate = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"..\..\..\Sample_Templates\TemplateSampleFreeForm.handlebars"); |
| 87 | + template = Handlebars.Compile(stringTemplate); |
| 88 | + jsonInput = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"..\..\..\Sample_Metadata\sampleFreeForm.json"); |
| 89 | + //deserialisedMapping = JsonConvert.DeserializeObject<DataObjectMappings>(jsonInput); |
| 90 | + deserialisedMapping = JObject.Parse(jsonInput); |
66 | 91 | result = template(deserialisedMapping); |
67 | 92 | Console.WriteLine(result); |
68 | 93 |
|
|
0 commit comments