Skip to content

Commit 65daf19

Browse files
author
Roelant Vos
committed
Added example for running the CLI, and some code clean-up.
1 parent 8c95abb commit 65daf19

4 files changed

Lines changed: 97 additions & 54 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RunDwhAutomation -i D:\RunDwhAutomation\Input\HUB_CUSTOMER.json -p D:\RunDwhAutomation\Pattern\loadPatternHubView.handlebars -v -o -e sql

ClassLibrary/DataWarehouseAutomation/RunDwhAutomation/Program.cs

Lines changed: 43 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -45,60 +45,49 @@ static int Main(string[] args)
4545
Parser.Default.ParseArguments<Options>(localArgs).WithParsed(options =>
4646
{
4747
// Make sure there is a default directory set when output is enabled
48-
if (options.Output)
48+
if (options.output)
4949
{
50-
if (options.OutputDirectory == null)
50+
if (options.outputDirectory == null)
5151
{
52-
options.OutputDirectory = AppDomain.CurrentDomain.BaseDirectory;
52+
options.outputDirectory = AppDomain.CurrentDomain.BaseDirectory;
5353
}
5454

55-
if (options.OutputFileExtension == null)
55+
if (options.outputFileExtension == null)
5656
{
57-
options.OutputFileExtension = "txt";
57+
options.outputFileExtension = "txt";
5858
}
5959
}
6060

6161
// Determine if the output is a file or path
6262

63-
var path = Path.GetExtension(options.Input);
64-
bool IsPath;
65-
if (path == String.Empty)
66-
{
67-
IsPath = true;
68-
}
69-
else
70-
{
71-
IsPath = false;
72-
}
63+
var path = Path.GetExtension(options.input);
64+
bool isPath;
65+
isPath = path == String.Empty;
7366

7467
// Managing verbose information back to user
75-
if (options.Verbose)
68+
if (options.verbose)
7669
{
7770
Console.WriteLine("Verbose mode enabled.");
7871

79-
if (options.Input != null && options.Input.Length > 0)
72+
if (!string.IsNullOrEmpty(options.input))
8073
{
81-
Console.WriteLine($"The input (file or directory) provided is {options.Input}");
82-
if (IsPath)
83-
{
84-
Console.WriteLine($"{options.Input} is evaluated as a directory.");
85-
}
86-
else
87-
{
88-
Console.WriteLine($"{options.Input} is evaluated as a file.");
89-
}
74+
Console.WriteLine($"The input (file or directory) provided is {options.input}");
75+
76+
Console.WriteLine(isPath
77+
? $"{options.input} is evaluated as a directory."
78+
: $"{options.input} is evaluated as a file.");
9079
}
9180

92-
if (options.Pattern != null && options.Pattern.Length > 0)
81+
if (!string.IsNullOrEmpty(options.pattern))
9382
{
94-
Console.WriteLine($"The pattern used is {options.Pattern}");
83+
Console.WriteLine($"The pattern used is {options.pattern}");
9584
}
9685

97-
if (options.Output)
86+
if (options.output)
9887
{
9988
Console.WriteLine($"Output is enabled.");
100-
Console.WriteLine($"The Output Directory is {options.OutputDirectory}.");
101-
Console.WriteLine($"The File Exension for output file(s) is {options.OutputFileExtension}");
89+
Console.WriteLine($"The Output Directory is {options.outputDirectory}.");
90+
Console.WriteLine($"The File Extension for output file(s) is {options.outputFileExtension}");
10291
}
10392

10493
//Console.WriteLine();
@@ -108,38 +97,38 @@ static int Main(string[] args)
10897
// Do the main stuff
10998
HandleBarsHelpers.RegisterHandleBarsHelpers();
11099

111-
if (IsPath)
100+
if (isPath)
112101
{
113-
var localFiles = Directory.GetFiles(options.Input, "*.json");
102+
var localFiles = Directory.GetFiles(options.input, "*.json");
114103

115104
foreach (var file in localFiles)
116105
{
117-
if (options.OutputFileName == null)
106+
if (options.outputFileName == null)
118107
{
119-
RunAutomation(options, file, "");
108+
RunAutomation(options, file);
120109
}
121110
else
122111
{
123-
RunAutomation(options, file, options.OutputFileName + Array.IndexOf(localFiles, file));
112+
RunAutomation(options, file, options.outputFileName + Array.IndexOf(localFiles, file));
124113
}
125114
}
126115
}
127116
else
128117
{
129-
if (options.OutputFileName == null)
118+
if (options.outputFileName == null)
130119
{
131-
RunAutomation(options, options.Input, "");
120+
RunAutomation(options, options.input);
132121
}
133122
else
134123
{
135-
RunAutomation(options, options.Input, options.OutputFileName );
124+
RunAutomation(options, options.input, options.outputFileName );
136125
}
137126
}
138127
#endregion
139128

140129
}).WithNotParsed(e => {
141130
Console.WriteLine($"An error was encountered while parsing the parameters/arguments. Please review the above possible options.");
142-
}); ;
131+
});
143132

144133

145134
//var result = Parser.Default.ParseArguments<Options>(args);
@@ -159,27 +148,27 @@ private static void RunAutomation(Options options, string inputFileName, string
159148
try
160149
{
161150
var jsonInput = File.ReadAllText(inputFileName);
162-
var stringTemplate = File.ReadAllText(options.Pattern);
151+
var stringTemplate = File.ReadAllText(options.pattern);
163152
var template = Handlebars.Compile(stringTemplate);
164-
var deserialisedMapping = JsonConvert.DeserializeObject<DataObjectMappings>(jsonInput);
153+
var deserialisedMapping = JsonConvert.DeserializeObject<VdwDataObjectMappings>(jsonInput);
165154

166155
var result = template(deserialisedMapping);
167156

168-
if (options.Verbose)
157+
if (options.verbose)
169158
{
170159
Console.WriteLine(result);
171160
}
172161

173-
if (options.Output)
162+
if (options.output)
174163
{
175164
if (outputFileName == "")
176165
{
177166
outputFileName = deserialisedMapping.dataObjectMappings[0].mappingName;
178167
}
179168

180-
Console.WriteLine($"Generating {outputFileName}.{options.OutputFileExtension} to {options.OutputDirectory}.");
169+
Console.WriteLine($"Generating {outputFileName}.{options.outputFileExtension} to {options.outputDirectory}.");
181170

182-
using (StreamWriter file = new StreamWriter($"{options.OutputDirectory}\\{outputFileName}.{options.OutputFileExtension}"))
171+
using (StreamWriter file = new StreamWriter($"{options.outputDirectory}\\{outputFileName}.{options.outputFileExtension}"))
183172
{
184173
file.WriteLine(result);
185174
}
@@ -189,7 +178,7 @@ private static void RunAutomation(Options options, string inputFileName, string
189178
}
190179
catch (Exception ex)
191180
{
192-
if (options.Verbose)
181+
if (options.verbose)
193182
{
194183
Console.WriteLine($"An error has been encountered: {ex}");
195184
}
@@ -204,27 +193,27 @@ class Options
204193
{
205194
// Inputs
206195
[Option('i', "input", Required = true, HelpText = "The filename or directory of the (input) Json file(s) containing the automation metadata.")]
207-
public string Input { get; set; }
196+
public string input { get; set; }
208197

209198
[Option('p', "pattern", Required = true, HelpText = "The filename for the (input) Handlebars pattern.")]
210-
public string Pattern { get; set; }
199+
public string pattern { get; set; }
211200

212201
// Outputs
213202
[Option('o', "output", Required = false, HelpText = "Enable output to be spooled to disk (enable/disable) - default is disable.")]
214-
public bool Output { get; set; }
203+
public bool output { get; set; }
215204

216205
[Option('d', "outputdirectory", Required = false, HelpText = "The directory where spool files (output) are placed. If not provided, the execution directory will be assumed.")]
217-
public string OutputDirectory { get; set; }
206+
public string outputDirectory { get; set; }
218207

219208
[Option('e', "outputextension", Required = false, HelpText = "The extension used for the output file(s). This is defaulted to txt when left empty.")]
220-
public string OutputFileExtension { get; set; }
209+
public string outputFileExtension { get; set; }
221210

222211
[Option('f', "outputfilename", Required = false, HelpText = "The name of the output file(s). This is defaulted to the mapping name in the metadata object when left empty.")]
223-
public string OutputFileName { get; set; }
212+
public string outputFileName { get; set; }
224213

225214
// Other
226215
[Option('v', "verbose", Required = false, HelpText = "Set output to verbose messages.")]
227-
public bool Verbose { get; set; }
216+
public bool verbose { get; set; }
228217
}
229218

230219
/// <summary>

ClassLibrary/DataWarehouseAutomation/RunDwhAutomation/RunDwhAutomation.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@
7676
<Compile Include="HandleBarsHelpers.cs" />
7777
<Compile Include="Program.cs" />
7878
<Compile Include="Properties\AssemblyInfo.cs" />
79+
<Compile Include="VdwInterfaceObjectModel.cs" />
7980
</ItemGroup>
8081
<ItemGroup>
8182
<None Include="App.config" />
83+
<None Include="Example.bat" />
8284
<None Include="packages.config" />
8385
</ItemGroup>
8486
<ItemGroup>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using DataWarehouseAutomation;
7+
8+
namespace RunDwhAutomation
9+
{
10+
/// <summary>
11+
/// The parent object containing the list of source-to-target mappings. This is the highest level and contains the list of mappings (as individual objects
12+
/// but also the parameters inherited from TEAM and VDW.
13+
/// </summary>
14+
class VdwDataObjectMappings : DataObjectMappings
15+
{
16+
// Generic interface definitions
17+
//public List<DataObjectMapping> dataObjectMapping { get; set; }
18+
19+
// TEAM and VDW specific details
20+
public MetadataConfiguration metadataConfiguration { get; set; }
21+
public GenerationSpecificMetadata generationSpecificMetadata { get; set; }
22+
public string metadataFileName { get; set; }
23+
}
24+
25+
/// <summary>
26+
/// Specific metadata related for generation purposes, but which is relevant to use in templates.
27+
/// </summary>
28+
public class GenerationSpecificMetadata
29+
{
30+
public string selectedDataObject { get; set; }
31+
public DateTime generationDateTime { get; set; }
32+
}
33+
34+
/// <summary>
35+
/// The parameters that have been inherited from TEAM or are set in VDW, passed as properties of the metadata - and can be used in the templates.
36+
/// </summary>
37+
class MetadataConfiguration
38+
{
39+
public string vdwSchemaName { get; set; }
40+
41+
// Attributes
42+
public string changeDataCaptureAttribute { get; set; }
43+
public string recordSourceAttribute { get; set; }
44+
public string loadDateTimeAttribute { get; set; }
45+
public string expiryDateTimeAttribute { get; set; }
46+
public string eventDateTimeAttribute { get; set; }
47+
public string recordChecksumAttribute { get; set; }
48+
public string etlProcessAttribute { get; set; }
49+
public string sourceRowIdAttribute { get; set; }
50+
}
51+
}

0 commit comments

Comments
 (0)