Added exception handling.

This commit is contained in:
2024-02-15 22:32:57 +00:00
parent fc86c91b01
commit 31b48d795a
5 changed files with 231 additions and 147 deletions

View File

@@ -28,10 +28,11 @@ namespace lottery_co_uk_scraper.EuroMillions
}
catch (Exception ex)
{
// ToDo: _logger.LogError
throw new Exception(ex.Message);
}
return null;
throw new Exception("Failed to Process Millionaire Maker Code.");
}
public static void AssignMillionaireMakerToModelProperty(string propertyName, List<string> raffleNumbers, EurosResult eurosResult)

View File

@@ -23,7 +23,8 @@ namespace lottery_co_uk_scraper.EuroMillions
}
else
{
return null;
// ToDo: _logger.LogError
throw new Exception("machineName is null");
}
}
catch (Exception ex)

View File

@@ -28,11 +28,9 @@ namespace lottery_co_uk_scraper.EuroMillions
}
catch (Exception ex)
{
// ToDo: _logger.LogError
throw new Exception(ex.Message);
}
//ToDo: This isn't ideal how will i know if it fails.
return false;
}
public static void AssignDrawStatusToModelProperty(bool status, EurosResult eurosResult)
@@ -43,7 +41,8 @@ namespace lottery_co_uk_scraper.EuroMillions
}
catch (Exception ex)
{
// ToDo: _logger.LogError
throw new Exception(ex.Message);
}
}
}

View File

@@ -126,11 +126,9 @@ namespace lottery_co_uk_scraper.EuroMillions
}
catch (Exception ex)
{
// ToDo Logger
Console.WriteLine();
// ToDo: _logger.LogError
throw new Exception(ex.Message);
}
return null;
}
private static HtmlNode GetNodeByDataTitle(HtmlNode sectionRow, string dataTitle)
@@ -143,10 +141,11 @@ namespace lottery_co_uk_scraper.EuroMillions
}
catch (Exception ex)
{
// ToDo: _logger.LogError
throw new Exception(ex.Message);
}
return null;
throw new Exception("Failed to get node by data title.");
}
public static void ProcessUKWinners(string sectionTitle, HtmlNode winnersNode, EurosResult eurosResult)
@@ -166,8 +165,8 @@ namespace lottery_co_uk_scraper.EuroMillions
}
catch (Exception ex)
{
// ToDo: Logger
Console.WriteLine("Nothing to match");
// ToDo: _logger.LogError
throw new Exception(ex.Message);
}
}
@@ -179,8 +178,8 @@ namespace lottery_co_uk_scraper.EuroMillions
}
catch (Exception ex)
{
// ToDo: Logger
Console.WriteLine("Nothing to match");
// ToDo: _logger.LogError
throw new Exception(ex.Message);
}
}
@@ -211,8 +210,8 @@ namespace lottery_co_uk_scraper.EuroMillions
}
catch (Exception ex)
{
// ToDo: Logger
Console.WriteLine("Nothing to match");
// ToDo: _logger.LogError
throw new Exception(ex.Message);
}
}
@@ -255,8 +254,8 @@ namespace lottery_co_uk_scraper.EuroMillions
}
catch (Exception ex)
{
// ToDo: Logger
Console.WriteLine("Nothing to match");
// ToDo: _logger.LogError
throw new Exception(ex.Message);
}
}
@@ -268,8 +267,8 @@ namespace lottery_co_uk_scraper.EuroMillions
}
catch (Exception ex)
{
// ToDo: Logger
Console.WriteLine("Nothing to match");
// ToDo: _logger.LogError
throw new Exception(ex.Message);
}
}
@@ -290,8 +289,8 @@ namespace lottery_co_uk_scraper.EuroMillions
}
catch (Exception ex)
{
// ToDo: Logger
Console.WriteLine("Nothing to match");
// ToDo: _logger.LogError
throw new Exception(ex.Message);
}
}
@@ -303,8 +302,8 @@ namespace lottery_co_uk_scraper.EuroMillions
}
catch (Exception ex)
{
// ToDo: Logger
Console.WriteLine("Nothing to match");
// ToDo: _logger.LogError
throw new Exception(ex.Message);
}
}
@@ -339,7 +338,7 @@ namespace lottery_co_uk_scraper.EuroMillions
catch (Exception ex)
{
// ToDo: Logger
Console.WriteLine(ex);
throw new Exception(ex.Message);
}
break;
@@ -372,7 +371,7 @@ namespace lottery_co_uk_scraper.EuroMillions
catch (Exception ex)
{
// ToDo: Logger
Console.WriteLine(ex);
throw new Exception(ex.Message);
}
break;
@@ -403,7 +402,7 @@ namespace lottery_co_uk_scraper.EuroMillions
catch (Exception ex)
{
// ToDo: Logger
Console.WriteLine("Nothing to match");
throw new Exception(ex.Message);
}
break;
@@ -434,7 +433,7 @@ namespace lottery_co_uk_scraper.EuroMillions
catch (Exception ex)
{
// ToDo: Logger
Console.WriteLine("Nothing to match");
throw new Exception(ex.Message);
}
break;
@@ -467,7 +466,7 @@ namespace lottery_co_uk_scraper.EuroMillions
catch (Exception ex)
{
// ToDo: Logger
Console.WriteLine("Nothing to match");
throw new Exception(ex.Message);
}
break;
@@ -498,7 +497,7 @@ namespace lottery_co_uk_scraper.EuroMillions
catch (Exception ex)
{
// ToDo: Logger
Console.WriteLine("Nothing to match");
throw new Exception(ex.Message);
}
break;
@@ -529,7 +528,7 @@ namespace lottery_co_uk_scraper.EuroMillions
catch (Exception ex)
{
// ToDo: Logger
Console.WriteLine("Nothing to match");
throw new Exception(ex.Message);
}
break;
@@ -562,7 +561,7 @@ namespace lottery_co_uk_scraper.EuroMillions
catch (Exception ex)
{
// ToDo: Logger
Console.WriteLine("Nothing to match");
throw new Exception(ex.Message);
}
break;
@@ -593,7 +592,7 @@ namespace lottery_co_uk_scraper.EuroMillions
catch (Exception ex)
{
// ToDo: Logger
Console.WriteLine("Nothing to match");
throw new Exception(ex.Message);
}
break;
@@ -624,7 +623,7 @@ namespace lottery_co_uk_scraper.EuroMillions
catch (Exception ex)
{
// ToDo: Logger
Console.WriteLine("Nothing to match");
throw new Exception(ex.Message);
}
break;
@@ -724,7 +723,7 @@ namespace lottery_co_uk_scraper.EuroMillions
catch
{
// ToDo: Logger
Console.WriteLine("Nothing to match");
throw new Exception(ex.Message);
}
break;

View File

@@ -66,7 +66,8 @@ namespace lottery_co_uk_scraper.NationalLottery
}
catch (Exception ex)
{
// ToDo: _logger.LogError
throw new Exception(ex.Message);
}
}
@@ -83,15 +84,17 @@ namespace lottery_co_uk_scraper.NationalLottery
}
else
{
return null;
// ToDo: _logger.LogError
throw new Exception("sectionRow is null.");
}
}
catch (Exception ex)
{
// ToDo: _logger.LogError
throw new Exception(ex.Message);
}
return null;
throw new Exception("Failed to get section by row title.");
}
private static HtmlNode GetNodeByDataTitle(HtmlNode sectionRow, string dataTitle)
@@ -102,6 +105,8 @@ namespace lottery_co_uk_scraper.NationalLottery
}
public static void ProcessWinnersTable(HtmlDocument doc, LottoResult lottoResult)
{
try
{
var table = doc.DocumentNode.Descendants("table")
.FirstOrDefault(x => x.Attributes["class"] != null && x.Attributes["class"].Value.Contains("lotto mobFormat"));
@@ -115,8 +120,11 @@ namespace lottery_co_uk_scraper.NationalLottery
}
else
{
// ToDo: I don't need this write line, log the information about it being a draw with no match twos.
//_logger.LogInformation("");
Console.WriteLine("Section row with title 'Match 2' not found. Continuing without processing Match 2.");
}
ProcessTableSection(table, LotteryTableRow.Match3, lottoResult);
ProcessTableSection(table, LotteryTableRow.Match4, lottoResult);
ProcessTableSection(table, LotteryTableRow.Match5, lottoResult);
@@ -125,12 +133,21 @@ namespace lottery_co_uk_scraper.NationalLottery
ProcessTableSection(table, LotteryTableRow.Total, lottoResult);
}
}
catch (Exception ex)
{
//_logger.LogError("");
throw new Exception(ex.Message);
}
}
public static void AssignValueToModelProperty(string sectionTitle, string propertyName, string columnTitle, int value, LottoResult lottoResult)
{
switch (sectionTitle)
{
#region Match 2
case LotteryTableRow.Match2:
try
{
if (columnTitle == LotteryTableRow.Winners)
{
PropertyManager.SetProperty(nameof(lottoResult.TotalMatched2), lottoResult, value);
@@ -145,10 +162,20 @@ namespace lottery_co_uk_scraper.NationalLottery
{
PropertyManager.SetProperty(nameof(lottoResult.Matched2PrizeFund), lottoResult, value);
}
}
catch(Exception ex)
{
// ToDo: _logger.LogError
throw new Exception(ex.Message);
}
break;
#endregion
#region Match 3
case LotteryTableRow.Match3:
try
{
if (columnTitle == LotteryTableRow.Winners)
{
PropertyManager.SetProperty(nameof(lottoResult.TotalMatched3), lottoResult, value);
@@ -163,10 +190,20 @@ namespace lottery_co_uk_scraper.NationalLottery
{
PropertyManager.SetProperty(nameof(lottoResult.Matched3PrizeFund), lottoResult, value);
}
}
catch (Exception ex)
{
// ToDo: _logger.LogError
throw new Exception(ex.Message);
}
break;
#endregion
#region Match 4
case LotteryTableRow.Match4:
try
{
if (columnTitle == LotteryTableRow.Winners)
{
PropertyManager.SetProperty(nameof(lottoResult.TotalMatched4), lottoResult, value);
@@ -181,10 +218,20 @@ namespace lottery_co_uk_scraper.NationalLottery
{
PropertyManager.SetProperty(nameof(lottoResult.Matched4PrizeFund), lottoResult, value);
}
}
catch (Exception ex)
{
// ToDo: _logger.LogError
throw new Exception(ex.Message);
}
break;
#endregion
#region Match 5
case LotteryTableRow.Match5:
try
{
if (columnTitle == LotteryTableRow.Winners)
{
PropertyManager.SetProperty(nameof(lottoResult.TotalMatched5), lottoResult, value);
@@ -199,10 +246,20 @@ namespace lottery_co_uk_scraper.NationalLottery
{
PropertyManager.SetProperty(nameof(lottoResult.Matched5PrizeFund), lottoResult, value);
}
}
catch (Exception ex)
{
// ToDo: _logger.LogError
throw new Exception(ex.Message);
}
break;
#endregion
#region Match 5 + Bonus
case LotteryTableRow.Match5Bonus:
try
{
if (columnTitle == LotteryTableRow.Winners)
{
PropertyManager.SetProperty(nameof(lottoResult.TotalMatched5PlusBonus), lottoResult, value);
@@ -217,10 +274,20 @@ namespace lottery_co_uk_scraper.NationalLottery
{
PropertyManager.SetProperty(nameof(lottoResult.Matched5PlusBonusPrizeFund), lottoResult, value);
}
}
catch (Exception ex)
{
// ToDo: _logger.LogError
throw new Exception(ex.Message);
}
break;
#endregion
#region Match 6
case LotteryTableRow.Match6:
try
{
if (columnTitle == LotteryTableRow.Winners)
{
PropertyManager.SetProperty(nameof(lottoResult.TotalMatched6), lottoResult, value);
@@ -235,10 +302,20 @@ namespace lottery_co_uk_scraper.NationalLottery
{
PropertyManager.SetProperty(nameof(lottoResult.Matched6PrizeFund), lottoResult, value);
}
}
catch (Exception ex)
{
// ToDo: _logger.LogError
throw new Exception(ex.Message);
}
break;
#endregion
#region Totals
case LotteryTableRow.Total:
try
{
if (columnTitle == LotteryTableRow.Winners)
{
PropertyManager.SetProperty(nameof(lottoResult.TotalWinners), lottoResult, value);
@@ -248,8 +325,15 @@ namespace lottery_co_uk_scraper.NationalLottery
{
PropertyManager.SetProperty(nameof(lottoResult.TotalPrizeFund), lottoResult, value);
}
}
catch (Exception ex)
{
// ToDo: _logger.LogError
throw new Exception(ex.Message);
}
break;
#endregion
}
}