Skip to content

Commit d77c94e

Browse files
author
Roelant Vos
committed
Added some more exception handling
1 parent b572a3c commit d77c94e

2 files changed

Lines changed: 28 additions & 16 deletions

File tree

Virtual_EDW/CustomTabPage.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -581,12 +581,12 @@ private void GenerateFromPattern()
581581
for (int x = 0; x <= _localCheckedListBox.CheckedItems.Count - 1; x++)
582582
{
583583
var targetTableName = _localCheckedListBox.CheckedItems[x].ToString();
584-
RaiseOnChangeMainText(@"Processing generation for " + targetTableName + ".\r\n");
584+
RaiseOnChangeMainText(@"Generating code for " + targetTableName + ".\r\n");
585585

586-
// Only process the selected items in the total of available source-to-target mappings
586+
// Only process the selected items in the total of available source-to-target mappings.
587587
ItemList.TryGetValue(targetTableName, out var dataObjectMappingList);
588588

589-
// Return the result to the user
589+
// Return the result to the user.
590590
try
591591
{
592592
// Compile the template, and merge it with the metadata.
@@ -601,9 +601,9 @@ private void GenerateFromPattern()
601601
var json = JsonConvert.SerializeObject(dataObjectMappingList, Formatting.Indented);
602602
localRichTextBoxGenerationOutput.AppendText(json + "\r\n\r\n");
603603
}
604-
catch (Exception ex)
604+
catch (Exception exception)
605605
{
606-
RaiseOnChangeMainText("An error was encountered while generating the Json metadata. The error message is: " + ex);
606+
RaiseOnChangeMainText("An error was encountered while parsing the Json metadata. The error message is: " + exception.Message);
607607
}
608608
}
609609

@@ -622,7 +622,7 @@ private void GenerateFromPattern()
622622
//Generate in database.
623623
if (GenerateInDatabaseFlag)
624624
{
625-
// Find the right connection for the pattern connection key
625+
// Find the right connection for the pattern connection key.
626626
var localConnection = TeamConfiguration.GetTeamConnectionByInternalId(localLabelActiveConnectionKeyValue.Text, FormBase.TeamConfigurationSettings.ConnectionDictionary);
627627

628628
if (localConnection != null)
@@ -635,7 +635,9 @@ private void GenerateFromPattern()
635635
}
636636
catch
637637
{
638-
FormBase.VdwConfigurationSettings.VdwEventLog.Add(Event.CreateNewEvent(EventTypes.Error, $"There was an issue creating the schema {FormBase.VdwConfigurationSettings.VdwSchema} in database {conn.Database}."));
638+
var errorMessage = $"There was an issue creating the schema '{FormBase.VdwConfigurationSettings.VdwSchema}' in database '{conn.Database}'.";
639+
RaiseOnChangeMainText(errorMessage);
640+
FormBase.VdwConfigurationSettings.VdwEventLog.Add(Event.CreateNewEvent(EventTypes.Error, errorMessage));
639641
}
640642

641643
try
@@ -644,19 +646,24 @@ private void GenerateFromPattern()
644646
}
645647
catch
646648
{
647-
FormBase.VdwConfigurationSettings.VdwEventLog.Add(Event.CreateNewEvent(EventTypes.Error, $"There was an issue executing the query {result} in database {conn.Database}."));
649+
var errorMessage = $"There was an issue executing the query '{result}' in database '{conn.Database}'.";
650+
RaiseOnChangeMainText(errorMessage);
651+
FormBase.VdwConfigurationSettings.VdwEventLog.Add(Event.CreateNewEvent(EventTypes.Error, errorMessage));
648652
}
649653
}
650654
else
651655
{
652-
FormBase.VdwConfigurationSettings.VdwEventLog.Add(Event.CreateNewEvent(EventTypes.Error, $"There was an issue establishing a connection to generate the output for {targetTableName}. Is there a TEAM connections file in the configuration directory?"));
656+
var errorMessage = $"There was an issue establishing a connection to generate the output for '{targetTableName}'. Is there a TEAM connections file in the configuration directory?";
657+
RaiseOnChangeMainText(errorMessage);
658+
FormBase.VdwConfigurationSettings.VdwEventLog.Add(Event.CreateNewEvent(EventTypes.Error, errorMessage));
653659
}
654660
}
655-
656661
}
657-
catch (Exception ex)
662+
catch (Exception exception)
658663
{
659-
FormBase.VdwConfigurationSettings.VdwEventLog.Add(Event.CreateNewEvent(EventTypes.Error, $"The template could not be compiled. The error message is: {ex.Message}"));
664+
var errorMessage = $"The template could not be compiled. The error message is: {exception.Message}";
665+
RaiseOnChangeMainText(errorMessage);
666+
FormBase.VdwConfigurationSettings.VdwEventLog.Add(Event.CreateNewEvent(EventTypes.Error, errorMessage));
660667
}
661668
}
662669
}

Virtual_EDW/VdwUtility.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public static void CreateVdwSchema(SqlConnection connection)
201201

202202
// Execute the check to see if the schema exists or not
203203
var checkCommand = new SqlCommand($"SELECT CASE WHEN EXISTS (SELECT * FROM sys.schemas WHERE name = '{FormBase.VdwConfigurationSettings.VdwSchema}') THEN 1 ELSE 0 END", connection);
204-
var exists = (int) checkCommand.ExecuteScalar() == 1;
204+
var exists = (int)checkCommand.ExecuteScalar() == 1;
205205

206206
if (exists == false)
207207
{
@@ -218,7 +218,6 @@ public static void CreateVdwSchema(SqlConnection connection)
218218
//createStatement.AppendLine("END");
219219

220220
createStatement.AppendLine("IF SCHEMA_ID('" + FormBase.VdwConfigurationSettings.VdwSchema + "') IS NULL EXEC('CREATE SCHEMA " + FormBase.VdwConfigurationSettings.VdwSchema + "')");
221-
222221

223222
var commandVersion = new SqlCommand(createStatement.ToString(), connection);
224223

@@ -227,9 +226,15 @@ public static void CreateVdwSchema(SqlConnection connection)
227226
FormBase.VdwConfigurationSettings.VdwEventLog.Add(Event.CreateNewEvent(EventTypes.Information, $"The VDW schema '{FormBase.VdwConfigurationSettings.VdwSchema}' was created for database '{connection.Database}'."));
228227
}
229228
}
230-
catch (Exception ex)
229+
catch (Exception exception)
230+
{
231+
var errorMessage = $"An issue occurred creating the VDW schema '{FormBase.VdwConfigurationSettings.VdwSchema}' in the '{connection.Database}' database. The reported error is {exception.Message}";
232+
FormBase.VdwConfigurationSettings.VdwEventLog.Add(Event.CreateNewEvent(EventTypes.Error, errorMessage));
233+
}
234+
finally
231235
{
232-
FormBase.VdwConfigurationSettings.VdwEventLog.Add(Event.CreateNewEvent(EventTypes.Error, $"An issue occurred creating the VDW schema '{FormBase.VdwConfigurationSettings.VdwSchema}'. The reported error is {ex}"));
236+
connection.Close();
237+
connection.Dispose();
233238
}
234239
}
235240

0 commit comments

Comments
 (0)