Plugins engine is working
This commit is contained in:
@@ -8,9 +8,6 @@ using DiunaBI.Core.Models;
|
||||
using DiunaBI.Database.Context;
|
||||
using DiunaBI.Core.Services;
|
||||
using Google.Cloud.Firestore;
|
||||
using DiunaBI.Plugins.Morska.Importers;
|
||||
using DiunaBI.Plugins.Morska.Processors;
|
||||
using DiunaBI.Core.Services.Exports;
|
||||
|
||||
namespace DiunaBI.WebAPI.Controllers;
|
||||
|
||||
@@ -23,13 +20,15 @@ public class LayersController : Controller
|
||||
private readonly GoogleDriveHelper _googleDriveHelper;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly LogsController _logsController;
|
||||
private readonly PluginManager _pluginManager;
|
||||
|
||||
public LayersController(
|
||||
AppDbContext db,
|
||||
GoogleSheetsHelper googleSheetsHelper,
|
||||
GoogleDriveHelper googleDriveHelper,
|
||||
IConfiguration configuration,
|
||||
FirestoreDb firestoreDb
|
||||
FirestoreDb firestoreDb,
|
||||
PluginManager pluginManager
|
||||
)
|
||||
{
|
||||
_db = db;
|
||||
@@ -41,6 +40,7 @@ public class LayersController : Controller
|
||||
_googleDriveHelper = googleDriveHelper;
|
||||
_configuration = configuration;
|
||||
_logsController = new LogsController(firestoreDb);
|
||||
_pluginManager = pluginManager;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@@ -237,7 +237,11 @@ public class LayersController : Controller
|
||||
var layer = _db.Layers
|
||||
.Include(x => x.Records!.OrderByDescending(y => y.Code)).AsNoTracking().First(x => x.Id == id && !x.IsDeleted);
|
||||
|
||||
var export = new GoogleSheetExport(_googleDriveHelper, _googleSheetValues, _configuration);
|
||||
var export = _pluginManager.GetExporter("GoogleSheet");
|
||||
if (export == null)
|
||||
{
|
||||
throw new Exception("GoogleSheet exporter not found");
|
||||
}
|
||||
export.Export(layer);
|
||||
return Ok(true);
|
||||
}
|
||||
@@ -376,8 +380,13 @@ public class LayersController : Controller
|
||||
"GoogleSheet";
|
||||
if (source == "DataInbox" && type == "Import-D3")
|
||||
{
|
||||
var d3Importer = new MorskaD3Importer(_db);
|
||||
var d3Importer = _pluginManager.GetImporter("MorskaD3");
|
||||
if (d3Importer == null)
|
||||
{
|
||||
throw new Exception("MorskaD3 importer not found");
|
||||
}
|
||||
d3Importer.Import(importWorker);
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{importWorker.Name}, {importWorker.Id}",
|
||||
@@ -391,8 +400,13 @@ public class LayersController : Controller
|
||||
switch (type)
|
||||
{
|
||||
case "D1":
|
||||
var d1Importer = new MorskaD1Importer(_db, _googleSheetValues);
|
||||
d1Importer.Import(importWorker);
|
||||
var d1importer = _pluginManager.GetImporter("MorskaD1");
|
||||
if (d1importer == null)
|
||||
{
|
||||
throw new Exception("MorskaD1 importer not found");
|
||||
}
|
||||
d1importer.Import(importWorker);
|
||||
|
||||
Thread.Sleep(5000); // be aware of GSheet API quota
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
@@ -406,8 +420,12 @@ public class LayersController : Controller
|
||||
break;
|
||||
case "FK2":
|
||||
{
|
||||
var fk2Importer = new MorskaFk2Importer(_db, _googleSheetValues);
|
||||
fk2Importer.Import(importWorker);
|
||||
var fk2importer = _pluginManager.GetImporter("MorskaFK2");
|
||||
if (fk2importer == null)
|
||||
{
|
||||
throw new Exception("MorskaFK2 importer not found");
|
||||
}
|
||||
fk2importer.Import(importWorker);
|
||||
Thread.Sleep(5000); // be aware of GSheet API quota
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
@@ -439,7 +457,11 @@ public class LayersController : Controller
|
||||
if (startDateParsed.Date <= DateTime.UtcNow.Date &&
|
||||
endDateParsed.Date >= DateTime.UtcNow.Date)
|
||||
{
|
||||
var importer = new MorskaImporter(_db, _googleSheetValues);
|
||||
var importer = _pluginManager.GetImporter("MorskaImporter");
|
||||
if (importer == null)
|
||||
{
|
||||
throw new Exception("MorskaImporter not found");
|
||||
}
|
||||
importer.Import(importWorker);
|
||||
Thread.Sleep(5000); // be aware of GSheet API quota
|
||||
|
||||
@@ -454,7 +476,11 @@ public class LayersController : Controller
|
||||
}
|
||||
else if (IsImportedLayerUpToDate(importWorker) == false)
|
||||
{
|
||||
var importer = new MorskaImporter(_db, _googleSheetValues);
|
||||
var importer = _pluginManager.GetImporter("MorskaImporter");
|
||||
if (importer == null)
|
||||
{
|
||||
throw new Exception("MorskaImporter not found");
|
||||
}
|
||||
importer.Import(importWorker);
|
||||
Thread.Sleep(5000); // be aware of GSheet API quota
|
||||
|
||||
@@ -610,8 +636,11 @@ public class LayersController : Controller
|
||||
throw new Exception("ProcessType record not found");
|
||||
case "T3-SourceYearSummary":
|
||||
{
|
||||
var processor =
|
||||
new T3SourceYearSummaryProcessor(_db);
|
||||
var processor = _pluginManager.GetProcessor("T3.SourceYearSummary");
|
||||
if (processor == null)
|
||||
{
|
||||
throw new Exception("T3.SourceYearSummary processor not found");
|
||||
}
|
||||
processor.Process(processWorker);
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
@@ -626,8 +655,11 @@ public class LayersController : Controller
|
||||
}
|
||||
case "T3-MultiSourceYearSummary":
|
||||
{
|
||||
var processor =
|
||||
new T3MultiSourceYearSummaryProcessor(_db);
|
||||
var processor = _pluginManager.GetProcessor("T3.MultiSourceYearSummary");
|
||||
if (processor == null)
|
||||
{
|
||||
throw new Exception("T3.MultiSourceYearSummary processor not found");
|
||||
}
|
||||
processor.Process(processWorker);
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
@@ -642,8 +674,11 @@ public class LayersController : Controller
|
||||
}
|
||||
case "T3-MultiSourceCopySelectedCodesYearSummary":
|
||||
{
|
||||
var processor =
|
||||
new T3MultiSourceCopySelectedCodesYearSummaryProcessor(_db);
|
||||
var processor = _pluginManager.GetProcessor("T3.MultiSourceCopySelectedCodesYearSummary");
|
||||
if (processor == null)
|
||||
{
|
||||
throw new Exception("T3.MultiSourceCopySelectedCodesYearSummary processor not found");
|
||||
}
|
||||
processor.Process(processWorker);
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
@@ -658,7 +693,11 @@ public class LayersController : Controller
|
||||
}
|
||||
case "T1-R1":
|
||||
{
|
||||
var processor = new T1R1Processor(_db, _googleSheetValues);
|
||||
var processor = _pluginManager.GetProcessor("T1.R1");
|
||||
if (processor == null)
|
||||
{
|
||||
throw new Exception("T1.R1 processor not found");
|
||||
}
|
||||
processor.Process(processWorker);
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
@@ -673,7 +712,11 @@ public class LayersController : Controller
|
||||
}
|
||||
case "T4-R2":
|
||||
{
|
||||
var processor = new T4R2Processor(_db, _googleSheetValues);
|
||||
var processor = _pluginManager.GetProcessor("T4.R2");
|
||||
if (processor == null)
|
||||
{
|
||||
throw new Exception("T4.R2 processor not found");
|
||||
}
|
||||
processor.Process(processWorker);
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
@@ -688,7 +731,11 @@ public class LayersController : Controller
|
||||
}
|
||||
case "T1-R3":
|
||||
{
|
||||
var processor = new T1R3Processor(_db, _googleSheetValues);
|
||||
var processor = _pluginManager.GetProcessor("T1.R3");
|
||||
if (processor == null)
|
||||
{
|
||||
throw new Exception("T1.R3 processor not found");
|
||||
}
|
||||
processor.Process(processWorker);
|
||||
|
||||
_logsController.AddEntry(new LogEntry
|
||||
@@ -713,33 +760,51 @@ public class LayersController : Controller
|
||||
{
|
||||
case "T3-SingleSource":
|
||||
{
|
||||
var t3SingleSource = new T3SingleSourceProcessor(_db);
|
||||
var t3SingleSource = _pluginManager.GetProcessor("T3.SingleSource");
|
||||
if (t3SingleSource == null)
|
||||
{
|
||||
throw new Exception("T3.SingleSource processor not found");
|
||||
}
|
||||
t3SingleSource.Process(processWorker);
|
||||
break;
|
||||
}
|
||||
case "T4-SingleSource":
|
||||
{
|
||||
var t4SingleSource = new T4SingleSourceProcessor(_db);
|
||||
var t4SingleSource = _pluginManager.GetProcessor("T4.SingleSource");
|
||||
if (t4SingleSource == null)
|
||||
{
|
||||
throw new Exception("T4.SingleSource processor not found");
|
||||
}
|
||||
t4SingleSource.Process(processWorker);
|
||||
break;
|
||||
}
|
||||
case "T5-LastValues":
|
||||
{
|
||||
var t5LastValues = new T5LastValuesProcessor(_db);
|
||||
var t5LastValues = _pluginManager.GetProcessor("T5.LastValues");
|
||||
if (t5LastValues == null)
|
||||
{
|
||||
throw new Exception("T5.LastValues processor not found");
|
||||
}
|
||||
t5LastValues.Process(processWorker);
|
||||
break;
|
||||
}
|
||||
case "T3-MultiSourceSummary":
|
||||
{
|
||||
var t3MultiSourceSummary =
|
||||
new T3MultiSourceSummaryProcessor(_db);
|
||||
var t3MultiSourceSummary = _pluginManager.GetProcessor("T3.MultiSourceSummary");
|
||||
if (t3MultiSourceSummary == null)
|
||||
{
|
||||
throw new Exception("T3.MultiSourceSummary processor not found");
|
||||
}
|
||||
t3MultiSourceSummary.Process(processWorker);
|
||||
break;
|
||||
}
|
||||
case "T3-MultiSourceCopySelectedCodes":
|
||||
{
|
||||
var t3MultiSourceCopySelectedCode =
|
||||
new T3MultiSourceCopySelectedCodesProcessor(_db);
|
||||
var t3MultiSourceCopySelectedCode = _pluginManager.GetProcessor("T3.MultiSourceCopySelectedCodes");
|
||||
if (t3MultiSourceCopySelectedCode == null)
|
||||
{
|
||||
throw new Exception("T3.MultiSourceCopySelectedCodes processor not found");
|
||||
}
|
||||
t3MultiSourceCopySelectedCode.Process(processWorker);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user