Log powerBI requests
This commit is contained in:
@@ -13,7 +13,6 @@ namespace WebAPI.Controllers
|
|||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
|
|
||||||
public class LayersController : Controller
|
public class LayersController : Controller
|
||||||
{
|
{
|
||||||
private readonly AppDbContext db;
|
private readonly AppDbContext db;
|
||||||
@@ -22,6 +21,7 @@ namespace WebAPI.Controllers
|
|||||||
private GoogleSheetsHelper googleSheetsHelper;
|
private GoogleSheetsHelper googleSheetsHelper;
|
||||||
private readonly IConfiguration configuration;
|
private readonly IConfiguration configuration;
|
||||||
private readonly LogsController logsController;
|
private readonly LogsController logsController;
|
||||||
|
|
||||||
public LayersController(
|
public LayersController(
|
||||||
AppDbContext _db,
|
AppDbContext _db,
|
||||||
GoogleSheetsHelper _googleSheetsHelper,
|
GoogleSheetsHelper _googleSheetsHelper,
|
||||||
@@ -33,6 +33,7 @@ namespace WebAPI.Controllers
|
|||||||
{
|
{
|
||||||
googleSheetValues = _googleSheetsHelper.Service.Spreadsheets.Values;
|
googleSheetValues = _googleSheetsHelper.Service.Spreadsheets.Values;
|
||||||
}
|
}
|
||||||
|
|
||||||
googleSheetsHelper = _googleSheetsHelper;
|
googleSheetsHelper = _googleSheetsHelper;
|
||||||
googleDriveHelper = _googleDriveHelper;
|
googleDriveHelper = _googleDriveHelper;
|
||||||
configuration = _configuration;
|
configuration = _configuration;
|
||||||
@@ -49,6 +50,7 @@ namespace WebAPI.Controllers
|
|||||||
{
|
{
|
||||||
response = response.Where(x => x.Name != null && x.Name.Contains(name));
|
response = response.Where(x => x.Name != null && x.Name.Contains(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type != null)
|
if (type != null)
|
||||||
{
|
{
|
||||||
response = response.Where(x => x.Type == type);
|
response = response.Where(x => x.Type == type);
|
||||||
@@ -57,13 +59,13 @@ namespace WebAPI.Controllers
|
|||||||
return Ok(response
|
return Ok(response
|
||||||
.OrderByDescending(x => x.Number)
|
.OrderByDescending(x => x.Number)
|
||||||
.Skip(start).Take(limit).ToList());
|
.Skip(start).Take(limit).ToList());
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
return BadRequest(e.ToString());
|
return BadRequest(e.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public IActionResult Save(Layer input)
|
public IActionResult Save(Layer input)
|
||||||
{
|
{
|
||||||
@@ -80,6 +82,7 @@ namespace WebAPI.Controllers
|
|||||||
return BadRequest(e.ToString());
|
return BadRequest(e.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{id}")]
|
[Route("{id}")]
|
||||||
public IActionResult Get(Guid id)
|
public IActionResult Get(Guid id)
|
||||||
@@ -96,35 +99,74 @@ namespace WebAPI.Controllers
|
|||||||
return BadRequest(e.ToString());
|
return BadRequest(e.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("getForPowerBI/{apiKey}/{number}")]
|
[Route("getForPowerBI/{apiKey}/{number}")]
|
||||||
public IActionResult GetByNumber(string apiKey, int number)
|
public IActionResult GetByNumber(string apiKey, int number)
|
||||||
{
|
{
|
||||||
if (apiKey != configuration["apiKey"])
|
if (apiKey != configuration["apiKey"])
|
||||||
{
|
{
|
||||||
|
logsController.AddEntry(new LogEntry
|
||||||
|
{
|
||||||
|
Title = $"Unauthorized request - wrong apiKey ({number})",
|
||||||
|
Type = LogEntryType.warning,
|
||||||
|
LogType = LogType.powerBI,
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
});
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
|
||||||
!Request.Headers.TryGetValue("Authorization", out var authHeader))
|
|
||||||
{
|
|
||||||
return Unauthorized();
|
|
||||||
}
|
|
||||||
string[] credentialsArr = authHeader.ToString().Split(" ");
|
|
||||||
if (credentialsArr.Length != 2)
|
|
||||||
{
|
|
||||||
return Unauthorized();
|
|
||||||
}
|
|
||||||
var authValue = Encoding.UTF8.GetString(Convert.FromBase64String(credentialsArr[1]));
|
|
||||||
var username = authValue.Split(':')[0];
|
|
||||||
var password = authValue.Split(':')[1];
|
|
||||||
if (username != configuration["powerBI-user"] || password != configuration["powerBI-pass"])
|
|
||||||
{
|
|
||||||
return Unauthorized();
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (
|
||||||
|
!Request.Headers.TryGetValue("Authorization", out var authHeader))
|
||||||
|
{
|
||||||
|
logsController.AddEntry(new LogEntry
|
||||||
|
{
|
||||||
|
Title = $"Unauthorized request - no authorization header ({number})",
|
||||||
|
Type = LogEntryType.warning,
|
||||||
|
LogType = LogType.powerBI,
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
});
|
||||||
|
return Unauthorized();
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] credentialsArr = authHeader.ToString().Split(" ");
|
||||||
|
if (credentialsArr.Length != 2)
|
||||||
|
{
|
||||||
|
logsController.AddEntry(new LogEntry
|
||||||
|
{
|
||||||
|
Title = $"Unauthorized request - wrong auth header format ({number})",
|
||||||
|
Type = LogEntryType.warning,
|
||||||
|
LogType = LogType.powerBI,
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
});
|
||||||
|
return Unauthorized();
|
||||||
|
}
|
||||||
|
|
||||||
|
var authValue = Encoding.UTF8.GetString(Convert.FromBase64String(credentialsArr[1]));
|
||||||
|
var username = authValue.Split(':')[0];
|
||||||
|
var password = authValue.Split(':')[1];
|
||||||
|
if (username != configuration["powerBI-user"] || password != configuration["powerBI-pass"])
|
||||||
|
{
|
||||||
|
logsController.AddEntry(new LogEntry
|
||||||
|
{
|
||||||
|
Title = $"Unauthorized request - bad credentials ({number})",
|
||||||
|
Type = LogEntryType.warning,
|
||||||
|
LogType = LogType.powerBI,
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
});
|
||||||
|
return Unauthorized();
|
||||||
|
}
|
||||||
|
|
||||||
|
logsController.AddEntry(new LogEntry
|
||||||
|
{
|
||||||
|
Title = $"Sending data for layer {number}",
|
||||||
|
Type = LogEntryType.info,
|
||||||
|
LogType = LogType.powerBI,
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
});
|
||||||
|
|
||||||
return Ok(db.Layers
|
return Ok(db.Layers
|
||||||
.Include(x => x.CreatedBy)
|
.Include(x => x.CreatedBy)
|
||||||
.Include(x => x.Records)
|
.Include(x => x.Records)
|
||||||
@@ -132,9 +174,17 @@ namespace WebAPI.Controllers
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
logsController.AddEntry(new LogEntry
|
||||||
|
{
|
||||||
|
Title = e.ToString(),
|
||||||
|
Type = LogEntryType.error,
|
||||||
|
LogType = LogType.powerBI,
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
});
|
||||||
return BadRequest(e.ToString());
|
return BadRequest(e.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("exportToGoogleSheet/{id}")]
|
[Route("exportToGoogleSheet/{id}")]
|
||||||
public IActionResult ExportToGoogleSheet(Guid id)
|
public IActionResult ExportToGoogleSheet(Guid id)
|
||||||
@@ -143,9 +193,10 @@ namespace WebAPI.Controllers
|
|||||||
{
|
{
|
||||||
throw new Exception("Google Sheets API not initialized");
|
throw new Exception("Google Sheets API not initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
Layer layer = db.Layers
|
Layer layer = db.Layers
|
||||||
.Include(x => x.Records!.OrderByDescending(x => x.Code))
|
.Include(x => x.Records!.OrderByDescending(x => x.Code))
|
||||||
.Where(x => x.Id == id && !x.IsDeleted).First();
|
.Where(x => x.Id == id && !x.IsDeleted).First();
|
||||||
|
|
||||||
var export = new googleSheetExport(googleDriveHelper, googleSheetValues, configuration);
|
var export = new googleSheetExport(googleDriveHelper, googleSheetValues, configuration);
|
||||||
export.export(layer);
|
export.export(layer);
|
||||||
@@ -161,20 +212,22 @@ namespace WebAPI.Controllers
|
|||||||
{
|
{
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (googleSheetValues is null)
|
if (googleSheetValues is null)
|
||||||
{
|
{
|
||||||
throw new Exception("Google Sheets API not initialized");
|
throw new Exception("Google Sheets API not initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<Layer> importWorkerLayers;
|
List<Layer> importWorkerLayers;
|
||||||
importWorkerLayers = db.Layers
|
importWorkerLayers = db.Layers
|
||||||
.Include(x => x.Records)
|
.Include(x => x.Records)
|
||||||
.Where(x =>
|
.Where(x =>
|
||||||
x.Records!.Any(x => x.Code == "Type" && x.Desc1 == "ImportWorker") &&
|
x.Records!.Any(x => x.Code == "Type" && x.Desc1 == "ImportWorker") &&
|
||||||
x.Records!.Any(x => x.Code == "IsEnabled" && x.Desc1 == "True")
|
x.Records!.Any(x => x.Code == "IsEnabled" && x.Desc1 == "True")
|
||||||
//&& x.Records!.Any(x => x.Code == "ImportType" && x.Desc1 == "FK2")
|
//&& x.Records!.Any(x => x.Code == "ImportType" && x.Desc1 == "FK2")
|
||||||
)
|
)
|
||||||
.OrderBy(x => x.CreatedAt)
|
.OrderBy(x => x.CreatedAt)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
@@ -204,7 +257,7 @@ namespace WebAPI.Controllers
|
|||||||
{
|
{
|
||||||
MorskaFk2Importer importer = new MorskaFk2Importer(db, googleSheetValues, this);
|
MorskaFk2Importer importer = new MorskaFk2Importer(db, googleSheetValues, this);
|
||||||
importer.import(importWorker);
|
importer.import(importWorker);
|
||||||
|
|
||||||
logsController.AddEntry(new LogEntry
|
logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"{importWorker!.Name}, {importWorker.Id}",
|
Title = $"{importWorker!.Name}, {importWorker.Id}",
|
||||||
@@ -216,9 +269,6 @@ namespace WebAPI.Controllers
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
string? startDate = importWorker.Records!.FirstOrDefault(x => x.Code == "StartDate")?.Desc1;
|
string? startDate = importWorker.Records!.FirstOrDefault(x => x.Code == "StartDate")?.Desc1;
|
||||||
if (startDate == null)
|
if (startDate == null)
|
||||||
{
|
{
|
||||||
@@ -289,6 +339,7 @@ namespace WebAPI.Controllers
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -304,6 +355,7 @@ namespace WebAPI.Controllers
|
|||||||
return BadRequest(e.ToString());
|
return BadRequest(e.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("AutoProcess/{apiKey}")]
|
[Route("AutoProcess/{apiKey}")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
@@ -313,18 +365,20 @@ namespace WebAPI.Controllers
|
|||||||
{
|
{
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (googleSheetValues is null)
|
if (googleSheetValues is null)
|
||||||
{
|
{
|
||||||
throw new Exception("Google Sheets API not initialized");
|
throw new Exception("Google Sheets API not initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] processTypes = new string[] {
|
string[] processTypes = new string[]
|
||||||
"T3-SingleSource",
|
{
|
||||||
|
"T3-SingleSource",
|
||||||
"T3-SourceYearSummary",
|
"T3-SourceYearSummary",
|
||||||
"T3-MultiSourceSummary", // AA
|
"T3-MultiSourceSummary", // AA
|
||||||
"T3-MultiSourceYearSummary", // AA/13
|
"T3-MultiSourceYearSummary", // AA/13
|
||||||
"T3-R1"
|
"T3-R1"
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (string type in processTypes)
|
foreach (string type in processTypes)
|
||||||
{
|
{
|
||||||
@@ -344,7 +398,7 @@ namespace WebAPI.Controllers
|
|||||||
x.Records!.Any(x => x.Code == "Type" && x.Desc1 == "ProcessWorker") &&
|
x.Records!.Any(x => x.Code == "Type" && x.Desc1 == "ProcessWorker") &&
|
||||||
x.Records!.Any(x => x.Code == "IsEnabled" && x.Desc1 == "True") &&
|
x.Records!.Any(x => x.Code == "IsEnabled" && x.Desc1 == "True") &&
|
||||||
x.Records!.Any(x => x.Code == "ProcessType" && x.Desc1 == type)
|
x.Records!.Any(x => x.Code == "ProcessType" && x.Desc1 == type)
|
||||||
)
|
)
|
||||||
.OrderBy(x => x.CreatedAt)
|
.OrderBy(x => x.CreatedAt)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
@@ -390,14 +444,17 @@ namespace WebAPI.Controllers
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void ProcessLayer(Layer processWorker)
|
internal void ProcessLayer(Layer processWorker)
|
||||||
{
|
{
|
||||||
if (googleSheetValues == null)
|
if (googleSheetValues == null)
|
||||||
{
|
{
|
||||||
throw new Exception("Google Sheets API not initialized");
|
throw new Exception("Google Sheets API not initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
string? name = processWorker.Name;
|
string? name = processWorker.Name;
|
||||||
string? year = processWorker?.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1;
|
string? year = processWorker?.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1;
|
||||||
if (year == null)
|
if (year == null)
|
||||||
@@ -410,6 +467,7 @@ namespace WebAPI.Controllers
|
|||||||
{
|
{
|
||||||
throw new Exception("ProcessType record not found");
|
throw new Exception("ProcessType record not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (processType == "T3-SourceYearSummary")
|
if (processType == "T3-SourceYearSummary")
|
||||||
{
|
{
|
||||||
T3SourceYearSummaryProcessor processor = new T3SourceYearSummaryProcessor(db, googleSheetValues, this);
|
T3SourceYearSummaryProcessor processor = new T3SourceYearSummaryProcessor(db, googleSheetValues, this);
|
||||||
@@ -425,9 +483,11 @@ namespace WebAPI.Controllers
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (processType == "T3-MultiSourceYearSummary")
|
if (processType == "T3-MultiSourceYearSummary")
|
||||||
{
|
{
|
||||||
T3MultiSourceYearSummaryProcessor processor = new T3MultiSourceYearSummaryProcessor(db, googleSheetValues, this, logsController);
|
T3MultiSourceYearSummaryProcessor processor =
|
||||||
|
new T3MultiSourceYearSummaryProcessor(db, googleSheetValues, this, logsController);
|
||||||
processor.process(processWorker!);
|
processor.process(processWorker!);
|
||||||
|
|
||||||
logsController.AddEntry(new LogEntry
|
logsController.AddEntry(new LogEntry
|
||||||
@@ -440,9 +500,11 @@ namespace WebAPI.Controllers
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (processType == "T3-MultiSourceCopySelectedCodesYearSummary")
|
if (processType == "T3-MultiSourceCopySelectedCodesYearSummary")
|
||||||
{
|
{
|
||||||
T3MultiSourceCopySelectedCodesYearSummaryProcessor processor = new T3MultiSourceCopySelectedCodesYearSummaryProcessor(db, googleSheetValues, this);
|
T3MultiSourceCopySelectedCodesYearSummaryProcessor processor =
|
||||||
|
new T3MultiSourceCopySelectedCodesYearSummaryProcessor(db, googleSheetValues, this);
|
||||||
processor.process(processWorker!);
|
processor.process(processWorker!);
|
||||||
|
|
||||||
logsController.AddEntry(new LogEntry
|
logsController.AddEntry(new LogEntry
|
||||||
@@ -455,6 +517,7 @@ namespace WebAPI.Controllers
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (processType == "T3-R1")
|
if (processType == "T3-R1")
|
||||||
{
|
{
|
||||||
T3R1Processor processor = new T3R1Processor(db, googleSheetValues, this, logsController);
|
T3R1Processor processor = new T3R1Processor(db, googleSheetValues, this, logsController);
|
||||||
@@ -470,32 +533,37 @@ namespace WebAPI.Controllers
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string? month = processWorker?.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1;
|
string? month = processWorker?.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1;
|
||||||
if (month == null)
|
if (month == null)
|
||||||
{
|
{
|
||||||
throw new Exception("Month record not found");
|
throw new Exception("Month record not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (processType!)
|
switch (processType!)
|
||||||
{
|
{
|
||||||
case "T3-SingleSource":
|
case "T3-SingleSource":
|
||||||
{
|
{
|
||||||
T3SingleSourceProcessor processor = new T3SingleSourceProcessor(db, googleSheetValues, this);
|
T3SingleSourceProcessor processor = new T3SingleSourceProcessor(db, googleSheetValues, this);
|
||||||
processor.process(processWorker!);
|
processor.process(processWorker!);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "T3-MultiSourceSummary":
|
case "T3-MultiSourceSummary":
|
||||||
{
|
{
|
||||||
T3MultiSourceSummaryProcessor processor = new T3MultiSourceSummaryProcessor(db, googleSheetValues, this, logsController);
|
T3MultiSourceSummaryProcessor processor =
|
||||||
processor.process(processWorker!);
|
new T3MultiSourceSummaryProcessor(db, googleSheetValues, this, logsController);
|
||||||
break;
|
processor.process(processWorker!);
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
case "T3-MultiSourceCopySelectedCodes":
|
case "T3-MultiSourceCopySelectedCodes":
|
||||||
{
|
{
|
||||||
T3MultiSourceCopySelectedCodesProcessor processor = new T3MultiSourceCopySelectedCodesProcessor(db, googleSheetValues, this);
|
T3MultiSourceCopySelectedCodesProcessor processor =
|
||||||
processor.process(processWorker!);
|
new T3MultiSourceCopySelectedCodesProcessor(db, googleSheetValues, this);
|
||||||
break;
|
processor.process(processWorker!);
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logsController.AddEntry(new LogEntry
|
logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
||||||
@@ -505,6 +573,7 @@ namespace WebAPI.Controllers
|
|||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void SaveRecords(Guid id, ICollection<Record> records, Guid currentUserId)
|
internal void SaveRecords(Guid id, ICollection<Record> records, Guid currentUserId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -514,6 +583,7 @@ namespace WebAPI.Controllers
|
|||||||
{
|
{
|
||||||
db.Records.RemoveRange(toDelete);
|
db.Records.RemoveRange(toDelete);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Record record in records)
|
foreach (Record record in records)
|
||||||
{
|
{
|
||||||
record.CreatedById = currentUserId;
|
record.CreatedById = currentUserId;
|
||||||
@@ -529,6 +599,7 @@ namespace WebAPI.Controllers
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void WriteToConsole(params string[] messages)
|
internal void WriteToConsole(params string[] messages)
|
||||||
{
|
{
|
||||||
foreach (string message in messages)
|
foreach (string message in messages)
|
||||||
@@ -536,6 +607,7 @@ namespace WebAPI.Controllers
|
|||||||
Console.WriteLine($"DiunaLog: {message}");
|
Console.WriteLine($"DiunaLog: {message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsImportedLayerUpToDate(Layer importWorker)
|
private bool IsImportedLayerUpToDate(Layer importWorker)
|
||||||
{
|
{
|
||||||
if (googleSheetValues is null)
|
if (googleSheetValues is null)
|
||||||
@@ -559,16 +631,19 @@ namespace WebAPI.Controllers
|
|||||||
{
|
{
|
||||||
throw new Exception($"SheetId not found, {importWorker.Name}");
|
throw new Exception($"SheetId not found, {importWorker.Name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
string? sheetTabName = importWorker.Records!.Where(x => x.Code == "SheetTabName").FirstOrDefault()?.Desc1;
|
string? sheetTabName = importWorker.Records!.Where(x => x.Code == "SheetTabName").FirstOrDefault()?.Desc1;
|
||||||
if (sheetTabName == null)
|
if (sheetTabName == null)
|
||||||
{
|
{
|
||||||
throw new Exception($"SheetTabName not found, {importWorker.Name}");
|
throw new Exception($"SheetTabName not found, {importWorker.Name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
string? dataRange = importWorker.Records!.Where(x => x.Code == "DataRange").FirstOrDefault()?.Desc1;
|
string? dataRange = importWorker.Records!.Where(x => x.Code == "DataRange").FirstOrDefault()?.Desc1;
|
||||||
if (dataRange == null)
|
if (dataRange == null)
|
||||||
{
|
{
|
||||||
throw new Exception($"DataRange not found, {importWorker.Name}");
|
throw new Exception($"DataRange not found, {importWorker.Name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
var dataRangeResponse = googleSheetValues.Get(sheetId, $"{sheetTabName}!{dataRange}").Execute();
|
var dataRangeResponse = googleSheetValues.Get(sheetId, $"{sheetTabName}!{dataRange}").Execute();
|
||||||
var data = dataRangeResponse.Values;
|
var data = dataRangeResponse.Values;
|
||||||
|
|
||||||
@@ -590,20 +665,24 @@ namespace WebAPI.Controllers
|
|||||||
double.TryParse(data[1][i].ToString(), CultureInfo.GetCultureInfo("pl-PL"), out value) &&
|
double.TryParse(data[1][i].ToString(), CultureInfo.GetCultureInfo("pl-PL"), out value) &&
|
||||||
record.Value1 != value)
|
record.Value1 != value)
|
||||||
{
|
{
|
||||||
WriteToConsole($"Code: {data[0][i]}. DiunaBI: {string.Format("{0:N2}", record.Value1)}. GoogleSheet: {data[1][i]}");
|
WriteToConsole(
|
||||||
|
$"Code: {data[0][i]}. DiunaBI: {string.Format("{0:N2}", record.Value1)}. GoogleSheet: {data[1][i]}");
|
||||||
isUpToDate = false;
|
isUpToDate = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Record record in newestLayer.Records!)
|
foreach (Record record in newestLayer.Records!)
|
||||||
{
|
{
|
||||||
if (data[0].Contains(record.Code))
|
if (data[0].Contains(record.Code))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteToConsole($"Code not found in GoogleSheet: {record.Code}");
|
WriteToConsole($"Code not found in GoogleSheet: {record.Code}");
|
||||||
isUpToDate = false;
|
isUpToDate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return isUpToDate;
|
return isUpToDate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ namespace WebAPI.Controllers
|
|||||||
case LogType.process:
|
case LogType.process:
|
||||||
type = "Process";
|
type = "Process";
|
||||||
break;
|
break;
|
||||||
|
case LogType.powerBI:
|
||||||
|
type = "PowerBIAccess";
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
type = "Other"; // should never happen
|
type = "Other"; // should never happen
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ namespace WebAPI.Models
|
|||||||
public enum LogType {
|
public enum LogType {
|
||||||
import,
|
import,
|
||||||
backup,
|
backup,
|
||||||
process
|
process,
|
||||||
|
powerBI
|
||||||
}
|
}
|
||||||
public class LogEntry
|
public class LogEntry
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user