Skip to content

Commit 7ae0b06

Browse files
committed
Exception handling added around incorrectly formatted template collection files.
1 parent 1e578b1 commit 7ae0b06

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

Virtual_EDW/Form_Main.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public FormMain()
165165
private void RefreshTemplateGrid()
166166
{
167167
// Load the template collection into memory.
168-
VdwConfigurationSettings.templateList = TemplateHandling.LoadTemplateCollection();
168+
VdwConfigurationSettings.templateList = TemplateHandling.LoadTemplateCollection(VdwConfigurationSettings.VdwEventLog);
169169

170170
if ((VdwConfigurationSettings.templateList != null) && (!VdwConfigurationSettings.templateList.Any()))
171171
{
@@ -1136,7 +1136,7 @@ private void PictureBoxUpdateTemplatePath_Click(object sender, EventArgs e)
11361136

11371137
// Reload the files into the grid
11381138
VdwConfigurationSettings.templateList.Clear();
1139-
VdwConfigurationSettings.templateList = TemplateHandling.LoadTemplateCollection();
1139+
VdwConfigurationSettings.templateList = TemplateHandling.LoadTemplateCollection(VdwConfigurationSettings.VdwEventLog);
11401140
PopulateTemplateCollectionDataGrid();
11411141
}
11421142
}

Virtual_EDW/TemplateHandling.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using Microsoft.SqlServer.Management.Smo;
45
using Newtonsoft.Json;
6+
using TEAM_Library;
7+
using static System.Net.Mime.MediaTypeNames;
8+
using static System.Runtime.InteropServices.JavaScript.JSType;
59

610
namespace Virtual_Data_Warehouse
711
{
@@ -77,17 +81,24 @@ internal static string SaveTemplateCollection(string templateFilePath, string fi
7781
return returnMessage;
7882
}
7983

80-
internal static List<TemplateHandling> LoadTemplateCollection()
84+
internal static List<TemplateHandling> LoadTemplateCollection(EventLog eventLog)
8185
{
8286
List<TemplateHandling> templateList = new List<TemplateHandling>();
8387

84-
// Retrieve the file contents and store in a string.
85-
if (File.Exists(FormBase.VdwConfigurationSettings.TemplatePath + FormBase.GlobalParameters.TemplateCollectionFileName))
88+
try
8689
{
87-
var jsonInput = File.ReadAllText(FormBase.VdwConfigurationSettings.TemplatePath + FormBase.GlobalParameters.TemplateCollectionFileName);
90+
// Retrieve the file contents and store in a string.
91+
if (File.Exists(FormBase.VdwConfigurationSettings.TemplatePath + FormBase.GlobalParameters.TemplateCollectionFileName))
92+
{
93+
var jsonInput = File.ReadAllText(FormBase.VdwConfigurationSettings.TemplatePath + FormBase.GlobalParameters.TemplateCollectionFileName);
8894

89-
//Move the (json) string into a List object (a list of the type Template).
90-
templateList = JsonConvert.DeserializeObject<List<TemplateHandling>>(jsonInput);
95+
//Move the (json) string into a List object (a list of the type Template).
96+
templateList = JsonConvert.DeserializeObject<List<TemplateHandling>>(jsonInput);
97+
}
98+
}
99+
catch (Exception exception)
100+
{
101+
eventLog.Add(Event.CreateNewEvent(EventTypes.Error, $"An error was encountered loading the template collection from '{FormBase.VdwConfigurationSettings.TemplatePath + FormBase.GlobalParameters.TemplateCollectionFileName}. The error encountered was '{exception.Message}'."));
91102
}
92103

93104
// Return the list to the instance

Virtual_EDW/Templates/templateCollection.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"TemplateOutputFileConvention": "{targetDataObject.name}.sql",
4747
"TemplateFilePath": "templateSatelliteViewWithDeliveryKey.handlebars",
4848
"TemplateNotes": "Regular Satellite pattern extended with delivery key concept."
49-
}.
49+
},
5050
{
5151
"TemplateName": "100 Dimension / PIT Select Template",
5252
"TemplateType": "Presentation",

0 commit comments

Comments
 (0)