Skip to content

Commit 03f32e1

Browse files
committed
Added output file pattern.
1 parent 98ab9ff commit 03f32e1

File tree

9 files changed

+366
-281
lines changed

9 files changed

+366
-281
lines changed

Virtual_EDW/CustomTabPage.cs

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System.Windows.Forms;
99
using HandlebarsDotNet;
1010
using Newtonsoft.Json;
11-
using TEAM;
1211
using DataWarehouseAutomation;
1312
using TEAM_Library;
1413

@@ -54,11 +53,16 @@ class CustomTabPage : TabPage
5453
readonly RichTextBox localRichTextBoxGenerationOutput;
5554

5655
readonly TabPage tabPageGenerationPattern;
56+
// Active pattern
5757
readonly Label localLabelActivePattern;
5858
readonly Label localLabelFilePath;
5959
readonly Label localLabelFullFilePath;
60+
// Assigned connection
6061
readonly Label localLabelActiveConnectionKey;
6162
readonly Label localLabelActiveConnectionKeyValue;
63+
// Output file pattern
64+
readonly Label localLabelOutputFilePattern;
65+
readonly Label localLabelOutputFilePatternValue;
6266

6367
readonly ComboBox localComboBoxGenerationPattern;
6468
readonly RichTextBox localRichTextBoxGenerationPattern;
@@ -180,7 +184,7 @@ public CustomTabPage(string classification, string notes, Dictionary<string, VDW
180184
_localRichTextBox.Size = new Size(393, 120);
181185
_localRichTextBox.BorderStyle = BorderStyle.None;
182186
_localRichTextBox.BackColor = SystemColors.Window;
183-
_localRichTextBox.TextChanged += new EventHandler(ScrollToCaret);
187+
_localRichTextBox.TextChanged += ScrollToCaret;
184188

185189
// Add 'Filter' Group Box
186190
var localGroupBoxFilter = new GroupBox();
@@ -198,7 +202,7 @@ public CustomTabPage(string classification, string notes, Dictionary<string, VDW
198202
_localTextBoxFilter.Location = new Point(6, 15);
199203
_localTextBoxFilter.Size = new Size(151, 20);
200204
_localTextBoxFilter.Name = $"textBoxFilterCriterion{_inputNiceName}";
201-
_localTextBoxFilter.TextChanged += new EventHandler(FilterItemList);
205+
_localTextBoxFilter.TextChanged += FilterItemList;
202206

203207
#endregion
204208

@@ -212,8 +216,7 @@ public CustomTabPage(string classification, string notes, Dictionary<string, VDW
212216
localTabControl.Size = new Size(896, 573);
213217
localTabControl.Name = $"tabControl{classification}";
214218
localTabControl.BackColor = Color.White;
215-
//localTabControl.SelectedIndexChanged += new EventHandler(SyntaxHighlightsHandlebars);
216-
localTabControl.SelectedIndexChanged += new EventHandler(SubTabClick);
219+
localTabControl.SelectedIndexChanged += SubTabClick;
217220

218221
// Add 'Generation Output' Tab Page on Sub Tab
219222
tabPageGenerationOutput = new TabPage($"{_inputNiceName} Generation Output");
@@ -247,7 +250,7 @@ public CustomTabPage(string classification, string notes, Dictionary<string, VDW
247250
localComboBoxGenerationPattern.Location = new Point(108, 8);
248251
localComboBoxGenerationPattern.Size = new Size(496, 21);
249252
localComboBoxGenerationPattern.Name = $"comboBox{classification}Pattern";
250-
localComboBoxGenerationPattern.SelectedIndexChanged += new EventHandler(DisplayPattern);
253+
localComboBoxGenerationPattern.SelectedIndexChanged += DisplayPattern;
251254

252255
// Add 'Active Pattern' Label
253256
localLabelActivePattern = new Label();
@@ -290,10 +293,28 @@ public CustomTabPage(string classification, string notes, Dictionary<string, VDW
290293
tabPageGenerationPattern.Controls.Add(localLabelActiveConnectionKeyValue);
291294
localLabelActiveConnectionKeyValue.Anchor = (AnchorStyles.Top | AnchorStyles.Left);
292295
localLabelActiveConnectionKeyValue.Location = new Point(105, 57);
293-
localLabelActiveConnectionKeyValue.Size = new Size(650, 13);
296+
localLabelActiveConnectionKeyValue.Size = new Size(240, 13);
294297
localLabelActiveConnectionKeyValue.Name = $"label{classification}ConnectionKeyValue";
295298
localLabelActiveConnectionKeyValue.Text = @"<connection key>";
296299

300+
// Add 'Output File Pattern' Label
301+
localLabelOutputFilePattern = new Label();
302+
tabPageGenerationPattern.Controls.Add(localLabelOutputFilePattern);
303+
localLabelOutputFilePattern.Anchor = (AnchorStyles.Top | AnchorStyles.Left);
304+
localLabelOutputFilePattern.Location = new Point(350, 57);
305+
localLabelOutputFilePattern.Size = new Size(100, 13);
306+
localLabelOutputFilePattern.Name = $"label{classification}OutputFilePattern";
307+
localLabelOutputFilePattern.Text = @"Output file pattern:";
308+
309+
// Add 'Output File Pattern Value' Label
310+
localLabelOutputFilePatternValue = new Label();
311+
tabPageGenerationPattern.Controls.Add(localLabelOutputFilePatternValue);
312+
localLabelOutputFilePatternValue.Anchor = (AnchorStyles.Top | AnchorStyles.Left);
313+
localLabelOutputFilePatternValue.Location = new Point(460, 57);
314+
localLabelOutputFilePatternValue.Size = new Size(250, 13);
315+
localLabelOutputFilePatternValue.Name = $"label{classification}OutputFilePatternValue";
316+
localLabelOutputFilePatternValue.Text = @"<output file pattern>";
317+
297318
// Add 'Save Pattern' Button
298319
localSavePattern = new Button();
299320
tabPageGenerationPattern.Controls.Add(localSavePattern);
@@ -302,7 +323,7 @@ public CustomTabPage(string classification, string notes, Dictionary<string, VDW
302323
localSavePattern.Size = new Size(101, 23);
303324
localSavePattern.Text = $"Save updates";
304325
localSavePattern.Name = $"Save{classification}";
305-
localSavePattern.Click += (SavePattern);
326+
localSavePattern.Click += SavePattern;
306327

307328
// Add 'Generation Pattern' RichTextBox to Pattern tab
308329
localRichTextBoxGenerationPattern = new RichTextBox();
@@ -311,7 +332,7 @@ public CustomTabPage(string classification, string notes, Dictionary<string, VDW
311332
localRichTextBoxGenerationPattern.Location = new Point(3, 82);
312333
localRichTextBoxGenerationPattern.Size = new Size(195, 30);
313334
localRichTextBoxGenerationPattern.BorderStyle = BorderStyle.None;
314-
localRichTextBoxGenerationPattern.TextChanged += new EventHandler(CommitPatternToMemory);
335+
localRichTextBoxGenerationPattern.TextChanged += CommitPatternToMemory;
315336
#endregion
316337

317338
#region Constructor Methods
@@ -325,8 +346,7 @@ public CustomTabPage(string classification, string notes, Dictionary<string, VDW
325346
// Report back to the user if there is not metadata available
326347
if (itemList == null || itemList.Count == 0)
327348
{
328-
_localRichTextBox.Text =
329-
$"There was no metadata available to display {_inputNiceName} content. Please check the associated metadata schema (are there any {_inputNiceName} records available?) or the database connection.\r\n\r\n";
349+
_localRichTextBox.Text = $"There was no metadata available to display {_inputNiceName} content. Please check the associated metadata schema (are there any {_inputNiceName} records available?) or the database connection.\r\n\r\n";
330350
}
331351

332352
// Initial documentation as per the definition notes
@@ -449,8 +469,7 @@ public void SetItemList(Dictionary<string, VDW_DataObjectMappingList> itemList)
449469
// Report back to the user if there is not metadata available
450470
if (_localCheckedListBox.Items.Count == 0)
451471
{
452-
_localRichTextBox.Text =
453-
$"There was no metadata available to display {_inputNiceName} content. Please check the associated metadata schema (are there any {_inputNiceName} records available?) or the database connection.";
472+
_localRichTextBox.Text = $"There was no metadata available to display {_inputNiceName} content. Please check the associated metadata schema (are there any {_inputNiceName} records available?) or the database connection.";
454473
}
455474

456475
// Set all the Check Boxes to 'checked'
@@ -481,6 +500,16 @@ private void DisplayPattern(object o, EventArgs e)
481500
localLabelFullFilePath.Text = localFullPath;
482501
localLabelActiveConnectionKeyValue.Text = loadPattern.LoadPatternConnectionKey;
483502

503+
if (!string.IsNullOrEmpty(loadPattern.LoadPatternOutputFilePattern))
504+
{
505+
localLabelOutputFilePatternValue.Text = loadPattern.LoadPatternOutputFilePattern;
506+
}
507+
else
508+
{
509+
localLabelOutputFilePatternValue.Text = "Undefined";
510+
}
511+
512+
484513
// Read the file from the path
485514
string loadPatternTemplate ="";
486515
try
@@ -530,13 +559,13 @@ public void RaiseOnClearMainText()
530559
void SavePattern(object o, EventArgs e)
531560
{
532561
RaiseOnClearMainText();
533-
string backupResponse = LoadPattern.BackupLoadPattern(localLabelFullFilePath.Text);
562+
string backupResponse = LoadPatternFileHandling.BackupPatternCollection(localLabelFullFilePath.Text);
534563
string saveResponse = "";
535564

536565
if (backupResponse.StartsWith("A backup was created"))
537566
{
538567
RaiseOnChangeMainText(backupResponse);
539-
saveResponse = LoadPattern.SaveLoadPattern(localLabelFullFilePath.Text, localRichTextBoxGenerationPattern.Text);
568+
saveResponse = LoadPatternFileHandling.SavePatternCollection(localLabelFullFilePath.Text, localRichTextBoxGenerationPattern.Text);
540569
RaiseOnChangeMainText("\r\n\r\n" + saveResponse);
541570
}
542571
else
@@ -570,7 +599,7 @@ private void GenerateFromPattern()
570599
RaiseOnClearMainText();
571600
localTabControl.SelectedIndex = 0;
572601

573-
// Loop through the checked items, select the right mapping and generate the pattern
602+
// Loop through the checked items, select the right mapping and generate the pattern.
574603
if (_localCheckedListBox.CheckedItems.Count != 0)
575604
{
576605
for (int x = 0; x <= _localCheckedListBox.CheckedItems.Count - 1; x++)
@@ -584,11 +613,11 @@ private void GenerateFromPattern()
584613
// Return the result to the user
585614
try
586615
{
587-
// Compile the template, and merge it with the metadata
616+
// Compile the template, and merge it with the metadata.
588617
var template = Handlebars.Compile(localRichTextBoxGenerationPattern.Text);
589618
var result = template(dataObjectMappingList);
590619

591-
// Check if the metadata needs to be displayed
620+
// Check if the metadata needs to be displayed.
592621
if (DisplayJsonFlag)
593622
{
594623
try
@@ -602,16 +631,19 @@ private void GenerateFromPattern()
602631
}
603632
}
604633

605-
// Display the output of the template to the user
634+
// Display the output of the template to the user.
606635
localRichTextBoxGenerationOutput.AppendText(result);
607636

608-
// Spool the output to disk
637+
// Spool the output to disk.
609638
if (SaveOutputFileFlag)
610639
{
611-
VdwUtility.SaveOutputToDisk(FormBase.VdwConfigurationSettings.VdwOutputPath + targetTableName + ".sql", result);
640+
// Assert file output pattern.
641+
var outputFile = localLabelOutputFilePatternValue.Text;
642+
outputFile = outputFile.Replace("{targetDataObject.name}", targetTableName);
643+
VdwUtility.SaveOutputToDisk(FormBase.VdwConfigurationSettings.VdwOutputPath + outputFile, result);
612644
}
613645

614-
//Generate in database
646+
//Generate in database.
615647
if (GenerateInDatabaseFlag)
616648
{
617649
// Find the right connection for the pattern connection key
@@ -659,6 +691,7 @@ private void GenerateFromPattern()
659691

660692
// Report back to the user
661693
int errorCounter = 0;
694+
662695
foreach (Event individualEvent in FormBase.VdwConfigurationSettings.VdwEventLog)
663696
{
664697
if (individualEvent.eventCode == 1 && individualEvent.eventTime>currentTime)

Virtual_EDW/Form_Base.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public FormBase(FormMain myParent)
1818
MyParent = myParent;
1919
InitializeComponent();
2020
}
21+
internal static LoadPatternGridView _loadPatternGridView;
2122

2223
// List of TEAM working environments.
2324
public static TeamEnvironmentCollection TeamEnvironmentCollection { get; set; } = new TeamEnvironmentCollection();
@@ -49,7 +50,6 @@ internal static class GlobalParameters
4950
public static string JsonSchemaForDataWarehouseAutomationFileName { get; } = "interfaceDataWarehouseAutomationMetadata.json";
5051
}
5152

52-
5353
/// <summary>
5454
/// These are the VDW specific configuration settings (i.e. not TEAM driven)
5555
/// Elements in this class are saved to / retrieved from the VDW Core Settings file
@@ -64,7 +64,7 @@ internal static class VdwConfigurationSettings
6464
public static string VdwOutputPath { get; set; } = Application.StartupPath + @"\Output\";
6565
public static string VdwExamplesPath { get; set; } = Application.StartupPath + @"\Examples\";
6666

67-
public static List<LoadPattern> patternList { get; set; }
67+
public static List<LoadPatternFileHandling> patternList { get; set; }
6868

6969
// Related to TEAM configuration settings
7070
//public static string TeamEnvironmentFilePath { get; set; } = GlobalParameters.RootPath + @"\Configuration\";

0 commit comments

Comments
 (0)