Move logs into FirebaseDB
This commit is contained in:
@@ -2,6 +2,7 @@ using System.Globalization;
|
||||
using System.Text;
|
||||
using DiunaBIWebAPI.dataImporters;
|
||||
using Google.Apis.Sheets.v4;
|
||||
using Google.Cloud.Firestore;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -25,7 +26,8 @@ public class LayersController : Controller
|
||||
AppDbContext db,
|
||||
GoogleSheetsHelper googleSheetsHelper,
|
||||
GoogleDriveHelper googleDriveHelper,
|
||||
IConfiguration configuration
|
||||
IConfiguration configuration,
|
||||
FirestoreDb firestoreDb
|
||||
)
|
||||
{
|
||||
_db = db;
|
||||
@@ -36,7 +38,7 @@ public class LayersController : Controller
|
||||
|
||||
_googleDriveHelper = googleDriveHelper;
|
||||
_configuration = configuration;
|
||||
_logsController = new LogsController(googleSheetsHelper, _configuration);
|
||||
_logsController = new LogsController(firestoreDb);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@@ -330,42 +332,9 @@ public class LayersController : Controller
|
||||
});
|
||||
break;
|
||||
case "FK2":
|
||||
{
|
||||
var fk2Importer = new MorskaFk2Importer(_db, _googleSheetValues, this);
|
||||
fk2Importer.Import(importWorker);
|
||||
Thread.Sleep(5000); // be aware of GSheet API quota
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{importWorker.Name}, {importWorker.Id}",
|
||||
Type = LogEntryType.Info,
|
||||
LogType = LogType.Import,
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
var startDate = importWorker.Records!.FirstOrDefault(x => x.Code == "StartDate")?.Desc1;
|
||||
if (startDate == null)
|
||||
{
|
||||
throw new Exception("StartDate record nod found");
|
||||
}
|
||||
|
||||
var endDate = importWorker.Records!.First(x => x.Code == "EndDate").Desc1;
|
||||
if (endDate == null)
|
||||
{
|
||||
throw new Exception("EndDate record nod found");
|
||||
}
|
||||
|
||||
var startDateParsed = DateTime.ParseExact(startDate, "yyyy.MM.dd", null);
|
||||
var endDateParsed = DateTime.ParseExact(endDate, "yyyy.MM.dd", null);
|
||||
if (startDateParsed.Date <= DateTime.UtcNow.Date &&
|
||||
endDateParsed.Date >= DateTime.UtcNow.Date)
|
||||
{
|
||||
var importer = new MorskaImporter(_db, _googleSheetValues, this);
|
||||
importer.Import(importWorker);
|
||||
var fk2Importer = new MorskaFk2Importer(_db, _googleSheetValues, this);
|
||||
fk2Importer.Import(importWorker);
|
||||
Thread.Sleep(5000); // be aware of GSheet API quota
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
@@ -376,36 +345,69 @@ public class LayersController : Controller
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
break;
|
||||
}
|
||||
else if (IsImportedLayerUpToDate(importWorker) == false)
|
||||
default:
|
||||
{
|
||||
var importer = new MorskaImporter(_db, _googleSheetValues, this);
|
||||
importer.Import(importWorker);
|
||||
Thread.Sleep(5000); // be aware of GSheet API quota
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
var startDate = importWorker.Records!.FirstOrDefault(x => x.Code == "StartDate")?.Desc1;
|
||||
if (startDate == null)
|
||||
{
|
||||
Title = $"{importWorker.Name}, {importWorker.Id}",
|
||||
Type = LogEntryType.Warning,
|
||||
LogType = LogType.Import,
|
||||
Message = "Success (reimported)",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
_logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{importWorker.Name}, {importWorker.Id}",
|
||||
Type = LogEntryType.Warning,
|
||||
LogType = LogType.Import,
|
||||
Message = "importLayer records are up to date. Not processed.",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
}
|
||||
throw new Exception("StartDate record nod found");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
var endDate = importWorker.Records!.First(x => x.Code == "EndDate").Desc1;
|
||||
if (endDate == null)
|
||||
{
|
||||
throw new Exception("EndDate record nod found");
|
||||
}
|
||||
|
||||
var startDateParsed = DateTime.ParseExact(startDate, "yyyy.MM.dd", null);
|
||||
var endDateParsed = DateTime.ParseExact(endDate, "yyyy.MM.dd", null);
|
||||
if (startDateParsed.Date <= DateTime.UtcNow.Date &&
|
||||
endDateParsed.Date >= DateTime.UtcNow.Date)
|
||||
{
|
||||
var importer = new MorskaImporter(_db, _googleSheetValues, this);
|
||||
importer.Import(importWorker);
|
||||
Thread.Sleep(5000); // be aware of GSheet API quota
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{importWorker.Name}, {importWorker.Id}",
|
||||
Type = LogEntryType.Info,
|
||||
LogType = LogType.Import,
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
}
|
||||
else if (IsImportedLayerUpToDate(importWorker) == false)
|
||||
{
|
||||
var importer = new MorskaImporter(_db, _googleSheetValues, this);
|
||||
importer.Import(importWorker);
|
||||
Thread.Sleep(5000); // be aware of GSheet API quota
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{importWorker.Name}, {importWorker.Id}",
|
||||
Type = LogEntryType.Warning,
|
||||
LogType = LogType.Import,
|
||||
Message = "Success (reimported)",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
_logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{importWorker.Name}, {importWorker.Id}",
|
||||
Type = LogEntryType.Warning,
|
||||
LogType = LogType.Import,
|
||||
Message = "importLayer records are up to date. Not processed.",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -483,6 +485,7 @@ public class LayersController : Controller
|
||||
x.Records!.Any(y => y.Code == "Type" && y.Desc1 == "ProcessWorker") &&
|
||||
x.Records!.Any(y => y.Code == "IsEnabled" && y.Desc1 == "True") &&
|
||||
x.Records!.Any(y => y.Code == "ProcessType" && y.Desc1 == type)
|
||||
&& x.Number == 5586
|
||||
)
|
||||
.OrderBy(x => x.CreatedAt)
|
||||
.AsNoTracking()
|
||||
@@ -553,98 +556,98 @@ public class LayersController : Controller
|
||||
case null:
|
||||
throw new Exception("ProcessType record not found");
|
||||
case "T3-SourceYearSummary":
|
||||
{
|
||||
var processor =
|
||||
new T3SourceYearSummaryProcessor(_db, this);
|
||||
processor.Process(processWorker);
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.Info,
|
||||
LogType = LogType.Process,
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return;
|
||||
}
|
||||
var processor =
|
||||
new T3SourceYearSummaryProcessor(_db, this);
|
||||
processor.Process(processWorker);
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.Info,
|
||||
LogType = LogType.Process,
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return;
|
||||
}
|
||||
case "T3-MultiSourceYearSummary":
|
||||
{
|
||||
var processor =
|
||||
new T3MultiSourceYearSummaryProcessor(_db, this, _logsController);
|
||||
processor.Process(processWorker);
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.Info,
|
||||
LogType = LogType.Process,
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return;
|
||||
}
|
||||
var processor =
|
||||
new T3MultiSourceYearSummaryProcessor(_db, this, _logsController);
|
||||
processor.Process(processWorker);
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.Info,
|
||||
LogType = LogType.Process,
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return;
|
||||
}
|
||||
case "T3-MultiSourceCopySelectedCodesYearSummary":
|
||||
{
|
||||
var processor =
|
||||
new T3MultiSourceCopySelectedCodesYearSummaryProcessor(_db, this);
|
||||
processor.Process(processWorker);
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.Info,
|
||||
LogType = LogType.Process,
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return;
|
||||
}
|
||||
var processor =
|
||||
new T3MultiSourceCopySelectedCodesYearSummaryProcessor(_db, this);
|
||||
processor.Process(processWorker);
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.Info,
|
||||
LogType = LogType.Process,
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return;
|
||||
}
|
||||
case "T1-R1":
|
||||
{
|
||||
var processor = new T1R1Processor(_db, _googleSheetValues, this, _logsController);
|
||||
processor.Process(processWorker);
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.Info,
|
||||
LogType = LogType.Process,
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return;
|
||||
}
|
||||
var processor = new T1R1Processor(_db, _googleSheetValues, this, _logsController);
|
||||
processor.Process(processWorker);
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.Info,
|
||||
LogType = LogType.Process,
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return;
|
||||
}
|
||||
case "T4-R2":
|
||||
{
|
||||
var processor = new T4R2Processor(_db, this, _logsController, _googleSheetValues);
|
||||
processor.Process(processWorker);
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.Info,
|
||||
LogType = LogType.Process,
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return;
|
||||
}
|
||||
var processor = new T4R2Processor(_db, this, _logsController, _googleSheetValues);
|
||||
processor.Process(processWorker);
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.Info,
|
||||
LogType = LogType.Process,
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return;
|
||||
}
|
||||
case "T1-R3":
|
||||
{
|
||||
var processor = new T1R3Processor(_db, this, _googleSheetValues);
|
||||
processor.Process(processWorker);
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.Info,
|
||||
LogType = LogType.Process,
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return;
|
||||
}
|
||||
var processor = new T1R3Processor(_db, this, _googleSheetValues);
|
||||
processor.Process(processWorker);
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.Info,
|
||||
LogType = LogType.Process,
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var month = processWorker.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1;
|
||||
@@ -656,37 +659,37 @@ public class LayersController : Controller
|
||||
switch (processType!)
|
||||
{
|
||||
case "T3-SingleSource":
|
||||
{
|
||||
var t3SingleSource = new T3SingleSourceProcessor(_db, this, _logsController);
|
||||
t3SingleSource.Process(processWorker);
|
||||
break;
|
||||
}
|
||||
{
|
||||
var t3SingleSource = new T3SingleSourceProcessor(_db, this);
|
||||
t3SingleSource.Process(processWorker);
|
||||
break;
|
||||
}
|
||||
case "T4-SingleSource":
|
||||
{
|
||||
var t4SingleSource = new T4SingleSourceProcessor(_db, this);
|
||||
t4SingleSource.Process(processWorker);
|
||||
break;
|
||||
}
|
||||
{
|
||||
var t4SingleSource = new T4SingleSourceProcessor(_db, this);
|
||||
t4SingleSource.Process(processWorker);
|
||||
break;
|
||||
}
|
||||
case "T5-LastValues":
|
||||
{
|
||||
var t5LastValues = new T5LastValuesProcessor(_db, this);
|
||||
t5LastValues.Process(processWorker);
|
||||
break;
|
||||
}
|
||||
{
|
||||
var t5LastValues = new T5LastValuesProcessor(_db, this);
|
||||
t5LastValues.Process(processWorker);
|
||||
break;
|
||||
}
|
||||
case "T3-MultiSourceSummary":
|
||||
{
|
||||
var t3MultiSourceSummary =
|
||||
new T3MultiSourceSummaryProcessor(_db, this, _logsController);
|
||||
t3MultiSourceSummary.Process(processWorker);
|
||||
break;
|
||||
}
|
||||
{
|
||||
var t3MultiSourceSummary =
|
||||
new T3MultiSourceSummaryProcessor(_db, this, _logsController);
|
||||
t3MultiSourceSummary.Process(processWorker);
|
||||
break;
|
||||
}
|
||||
case "T3-MultiSourceCopySelectedCodes":
|
||||
{
|
||||
var t3MultiSourceCopySelectedCode =
|
||||
new T3MultiSourceCopySelectedCodesProcessor(_db, this);
|
||||
t3MultiSourceCopySelectedCode.Process(processWorker);
|
||||
break;
|
||||
}
|
||||
{
|
||||
var t3MultiSourceCopySelectedCode =
|
||||
new T3MultiSourceCopySelectedCodesProcessor(_db, this);
|
||||
t3MultiSourceCopySelectedCode.Process(processWorker);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
|
||||
Reference in New Issue
Block a user