Importers refactor

This commit is contained in:
Michał Zieliński
2024-12-30 21:29:34 +01:00
parent 5ef9cf477e
commit a5a21305dd
3 changed files with 42 additions and 126 deletions

View File

@@ -23,18 +23,18 @@ public class MorskaD1Importer(
{
throw new Exception($"SheetTabName not found, {importWorker.Name}");
}
var importYearCell = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportYear")?.Desc1;
if (importYearCell == null)
var year = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportYear")?.Desc1;
if (year == null)
{
throw new Exception($"ImportYear not found, {importWorker.Name}");
}
var importMonthCell = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportMonth")?.Desc1;
if (importMonthCell == null)
var month = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportMonth")?.Desc1;
if (month == null)
{
throw new Exception($"ImportMonth not found, {importWorker.Name}");
}
var importNameCell = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportName")?.Desc1;
if (importNameCell == null)
var name = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportName")?.Desc1;
if (name == null)
{
throw new Exception($"ImportName not found, {importWorker.Name}");
}
@@ -44,25 +44,7 @@ public class MorskaD1Importer(
{
throw new Exception($"DataRange not found, {importWorker.Name}");
}
var nameResponse = googleSheetValues.Get(sheetId, $"{sheetTabName}!{importNameCell}:{importNameCell}").Execute();
var name = nameResponse.Values?[0][0].ToString();
if (name == null)
{
throw new Exception($"ImportName cell is empty, {importWorker.Name}");
}
var yearResponse = googleSheetValues.Get(sheetId, $"{sheetTabName}!{importYearCell}:{importYearCell}").Execute();
var year = yearResponse.Values[0][0].ToString();
if (year == null)
{
throw new Exception($"ImportYear cell is empty, {importWorker.Name}");
}
var monthResponse = googleSheetValues.Get(sheetId, $"{sheetTabName}!{importMonthCell}:{importMonthCell}").Execute();
var month = monthResponse.Values[0][0].ToString();
if (month == null)
{
throw new Exception($"ImportMonth cell is empty, {importWorker.Name}");
}
var layer = new Layer
{
Number = db.Layers.Count() + 1,