Cleanup .net warnings
This commit is contained in:
@@ -4,7 +4,7 @@ using System.Xml.Serialization;
|
|||||||
using Google.Apis.Sheets.v4;
|
using Google.Apis.Sheets.v4;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using WebAPI.dataParsers;
|
using WebAPI.dataParsers;
|
||||||
using WebAPI.Exports;
|
using WebAPI.Exports;
|
||||||
@@ -37,42 +37,42 @@ namespace WebAPI.Controllers
|
|||||||
logsController = new LogsController(googleSheetsHelper, googleDriveHelper, configuration);
|
logsController = new LogsController(googleSheetsHelper, googleDriveHelper, configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("BackupDatabase/{apiKey}")]
|
[Route("BackupDatabase/{apiKey}")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public IActionResult BackupDatabase(string apiKey)
|
public IActionResult BackupDatabase(string apiKey)
|
||||||
{
|
{
|
||||||
if (Request.Host.Value != configuration["apiLocalUrl"] || apiKey != configuration["apiKey"])
|
if (Request.Host.Value != configuration["apiLocalUrl"] || apiKey != configuration["apiKey"])
|
||||||
{
|
{
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string databaseName = "diunabi-morska";
|
string databaseName = "diunabi-morska";
|
||||||
string localDatabasePath = $"{configuration["dbBackupFile"]}-{DateTime.UtcNow.Day}.bak";
|
string localDatabasePath = $"{configuration["dbBackupFile"]}-{DateTime.UtcNow.Day}.bak";
|
||||||
var formatMediaName = $"DatabaseToolkitBackup_{databaseName}";
|
var formatMediaName = $"DatabaseToolkitBackup_{databaseName}";
|
||||||
var formatName = $"Full Backup of {databaseName}";
|
var formatName = $"Full Backup of {databaseName}";
|
||||||
|
|
||||||
var connection = new SqlConnection(configuration.GetConnectionString("SQLDatabase"));
|
var connection = new SqlConnection(configuration.GetConnectionString("SQLDatabase"));
|
||||||
|
|
||||||
var sql = @"BACKUP DATABASE @databaseName
|
var sql = @"BACKUP DATABASE @databaseName
|
||||||
TO DISK = @localDatabasePath
|
TO DISK = @localDatabasePath
|
||||||
WITH FORMAT,
|
WITH FORMAT,
|
||||||
MEDIANAME = @formatMediaName,
|
MEDIANAME = @formatMediaName,
|
||||||
NAME = @formatName";
|
NAME = @formatName";
|
||||||
|
|
||||||
connection.Open();
|
connection.Open();
|
||||||
var command = new SqlCommand(sql, connection);
|
var command = new SqlCommand(sql, connection);
|
||||||
|
|
||||||
command.CommandType = CommandType.Text;
|
command.CommandType = CommandType.Text;
|
||||||
command.CommandTimeout = 7200;
|
command.CommandTimeout = 7200;
|
||||||
command.Parameters.AddWithValue("@databaseName", databaseName);
|
command.Parameters.AddWithValue("@databaseName", databaseName);
|
||||||
command.Parameters.AddWithValue("@localDatabasePath", localDatabasePath);
|
command.Parameters.AddWithValue("@localDatabasePath", localDatabasePath);
|
||||||
command.Parameters.AddWithValue("@formatMediaName", formatMediaName);
|
command.Parameters.AddWithValue("@formatMediaName", formatMediaName);
|
||||||
command.Parameters.AddWithValue("@formatName", formatName);
|
command.Parameters.AddWithValue("@formatName", formatName);
|
||||||
|
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
|
|
||||||
Google.Apis.Drive.v3.Data.File body = new Google.Apis.Drive.v3.Data.File();
|
Google.Apis.Drive.v3.Data.File body = new Google.Apis.Drive.v3.Data.File();
|
||||||
body.Name = Path.GetFileName(localDatabasePath);
|
body.Name = Path.GetFileName(localDatabasePath);
|
||||||
body.Parents = new List<string?> { configuration["GDriveBackupDirectory"] };
|
body.Parents = new List<string?> { configuration["GDriveBackupDirectory"] };
|
||||||
@@ -80,12 +80,16 @@ namespace WebAPI.Controllers
|
|||||||
|
|
||||||
var fsSource = new FileStream(localDatabasePath, FileMode.Open, FileAccess.Read);
|
var fsSource = new FileStream(localDatabasePath, FileMode.Open, FileAccess.Read);
|
||||||
|
|
||||||
|
if (googleDriveHelper.Service is null)
|
||||||
|
{
|
||||||
|
throw new Exception("Google Drive API not initialized");
|
||||||
|
}
|
||||||
CreateMediaUpload request = googleDriveHelper.Service.Files.Create(body, fsSource, body.MimeType);
|
CreateMediaUpload request = googleDriveHelper.Service.Files.Create(body, fsSource, body.MimeType);
|
||||||
request.Fields = "id";
|
request.Fields = "id";
|
||||||
|
|
||||||
var response = request.Upload();
|
var response = request.Upload();
|
||||||
|
|
||||||
|
|
||||||
logsController.AddEntry(new LogEntry
|
logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = "Backup success",
|
Title = "Backup success",
|
||||||
@@ -96,7 +100,7 @@ namespace WebAPI.Controllers
|
|||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
logsController.AddEntry(new LogEntry
|
logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = "Backup error",
|
Title = "Backup error",
|
||||||
|
|||||||
@@ -1,121 +1,126 @@
|
|||||||
using System.Globalization;
|
|
||||||
using System.Xml.Serialization;
|
|
||||||
using DiunaBIWebAPI.dataImporters;
|
using DiunaBIWebAPI.dataImporters;
|
||||||
using Google.Apis.Sheets.v4;
|
using Google.Apis.Sheets.v4;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using WebAPI.dataParsers;
|
using WebAPI.dataProcessors;
|
||||||
using WebAPI.dataProcessors;
|
using WebAPI.Exports;
|
||||||
using WebAPI.Exports;
|
using WebAPI.Models;
|
||||||
using WebAPI.Models;
|
|
||||||
|
namespace WebAPI.Controllers
|
||||||
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;
|
private SpreadsheetsResource.ValuesResource? googleSheetValues;
|
||||||
private SpreadsheetsResource.ValuesResource googleSheetValues;
|
private GoogleDriveHelper googleDriveHelper;
|
||||||
private GoogleDriveHelper googleDriveHelper;
|
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,
|
GoogleDriveHelper _googleDriveHelper,
|
||||||
GoogleDriveHelper _googleDriveHelper,
|
IConfiguration _configuration)
|
||||||
IConfiguration _configuration)
|
{
|
||||||
{
|
db = _db;
|
||||||
db = _db;
|
if (_googleSheetsHelper.Service is not null) {
|
||||||
googleSheetValues = _googleSheetsHelper.Service.Spreadsheets.Values;
|
googleSheetValues = _googleSheetsHelper.Service.Spreadsheets.Values;
|
||||||
googleSheetsHelper = _googleSheetsHelper;
|
}
|
||||||
googleDriveHelper = _googleDriveHelper;
|
googleSheetsHelper = _googleSheetsHelper;
|
||||||
configuration = _configuration;
|
googleDriveHelper = _googleDriveHelper;
|
||||||
logsController = new LogsController(googleSheetsHelper, googleDriveHelper, configuration);
|
configuration = _configuration;
|
||||||
}
|
logsController = new LogsController(googleSheetsHelper, googleDriveHelper, configuration);
|
||||||
|
}
|
||||||
[HttpGet]
|
|
||||||
public IActionResult GetAll(int start, int limit, string? name, LayerType? type)
|
[HttpGet]
|
||||||
{
|
public IActionResult GetAll(int start, int limit, string? name, LayerType? type)
|
||||||
try
|
{
|
||||||
{
|
try
|
||||||
IQueryable<Layer> response = db.Layers.Where(x => !x.IsDeleted);
|
{
|
||||||
if (name != null)
|
IQueryable<Layer> response = db.Layers.Where(x => !x.IsDeleted);
|
||||||
{
|
if (name != null)
|
||||||
response = response.Where(x => 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);
|
||||||
|
}
|
||||||
return Ok(response
|
|
||||||
.OrderByDescending(x => x.Number)
|
return Ok(response
|
||||||
.Skip(start).Take(limit).ToList());
|
.OrderByDescending(x => x.Number)
|
||||||
|
.Skip(start).Take(limit).ToList());
|
||||||
}
|
|
||||||
catch (Exception e)
|
}
|
||||||
{
|
catch (Exception e)
|
||||||
return BadRequest(e.ToString());
|
{
|
||||||
}
|
return BadRequest(e.ToString());
|
||||||
}
|
}
|
||||||
[HttpPost]
|
}
|
||||||
public IActionResult Save(Layer input)
|
[HttpPost]
|
||||||
{
|
public IActionResult Save(Layer input)
|
||||||
try
|
{
|
||||||
{
|
try
|
||||||
//Request.Headers.TryGetValue("userId", out var value);
|
{
|
||||||
//Guid currentUserId = new Guid(value!);
|
//Request.Headers.TryGetValue("userId", out var value);
|
||||||
|
//Guid currentUserId = new Guid(value!);
|
||||||
|
|
||||||
return Ok();
|
|
||||||
}
|
return Ok();
|
||||||
catch (Exception e)
|
}
|
||||||
{
|
catch (Exception e)
|
||||||
return BadRequest(e.ToString());
|
{
|
||||||
}
|
return BadRequest(e.ToString());
|
||||||
}
|
}
|
||||||
[HttpGet]
|
}
|
||||||
[Route("{id}")]
|
[HttpGet]
|
||||||
public IActionResult Get(Guid id)
|
[Route("{id}")]
|
||||||
{
|
public IActionResult Get(Guid id)
|
||||||
try
|
{
|
||||||
{
|
try
|
||||||
return Ok(db.Layers
|
{
|
||||||
.Include(x => x.CreatedBy)
|
return Ok(db.Layers
|
||||||
.Include(x => x.Records)
|
.Include(x => x.CreatedBy)
|
||||||
.Where(x => x.Id == id && !x.IsDeleted).First());
|
.Include(x => x.Records)
|
||||||
}
|
.Where(x => x.Id == id && !x.IsDeleted).First());
|
||||||
catch (Exception e)
|
}
|
||||||
{
|
catch (Exception e)
|
||||||
return BadRequest(e.ToString());
|
{
|
||||||
}
|
return BadRequest(e.ToString());
|
||||||
}
|
}
|
||||||
[HttpGet]
|
}
|
||||||
[Route("exportToGoogleSheet/{id}")]
|
[HttpGet]
|
||||||
public IActionResult ExportToGoogleSheet(Guid id)
|
[Route("exportToGoogleSheet/{id}")]
|
||||||
{
|
public IActionResult ExportToGoogleSheet(Guid id)
|
||||||
Layer layer = db.Layers
|
{
|
||||||
.Include(x => x.Records!.OrderByDescending(x => x.Code))
|
if (googleSheetValues is null) {
|
||||||
.Where(x => x.Id == id && !x.IsDeleted).First();
|
throw new Exception("Google Sheets API not initialized");
|
||||||
|
}
|
||||||
var export = new googleSheetExport(googleDriveHelper, googleSheetValues, configuration);
|
Layer layer = db.Layers
|
||||||
export.export(layer);
|
.Include(x => x.Records!.OrderByDescending(x => x.Code))
|
||||||
return Ok(true);
|
.Where(x => x.Id == id && !x.IsDeleted).First();
|
||||||
}
|
|
||||||
|
var export = new googleSheetExport(googleDriveHelper, googleSheetValues, configuration);
|
||||||
[HttpGet]
|
export.export(layer);
|
||||||
[Route("AutoImport/{apiKey}")]
|
return Ok(true);
|
||||||
[AllowAnonymous]
|
}
|
||||||
public IActionResult AutoImport(string apiKey)
|
|
||||||
{
|
[HttpGet]
|
||||||
if (Request.Host.Value != configuration["apiLocalUrl"] || apiKey != configuration["apiKey"])
|
[Route("AutoImport/{apiKey}")]
|
||||||
{
|
[AllowAnonymous]
|
||||||
return Unauthorized();
|
public IActionResult AutoImport(string apiKey)
|
||||||
}
|
{
|
||||||
|
if (Request.Host.Value != configuration["apiLocalUrl"] || apiKey != configuration["apiKey"])
|
||||||
|
{
|
||||||
|
return Unauthorized();
|
||||||
|
}
|
||||||
|
if (googleSheetValues is null) {
|
||||||
|
throw new Exception("Google Sheets API not initialized");
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<Layer> importWorkerLayers;
|
List<Layer> importWorkerLayers;
|
||||||
@@ -136,7 +141,7 @@ namespace WebAPI.Controllers
|
|||||||
Type = LogEntryType.info,
|
Type = LogEntryType.info,
|
||||||
LogType = LogType.import,
|
LogType = LogType.import,
|
||||||
CreatedAt = DateTime.UtcNow,
|
CreatedAt = DateTime.UtcNow,
|
||||||
});
|
});
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,39 +201,42 @@ namespace WebAPI.Controllers
|
|||||||
return Ok();
|
return Ok();
|
||||||
} catch(Exception e)
|
} catch(Exception e)
|
||||||
{
|
{
|
||||||
logsController.AddEntry(new LogEntry
|
logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = "Process error",
|
Title = "Process error",
|
||||||
Type = LogEntryType.error,
|
Type = LogEntryType.error,
|
||||||
LogType = LogType.import,
|
LogType = LogType.import,
|
||||||
Message = e.ToString(),
|
Message = e.ToString(),
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
return BadRequest(e.ToString());
|
return BadRequest(e.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("AutoProcess/{apiKey}/{type}")]
|
[Route("AutoProcess/{apiKey}/{type}")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public IActionResult AutoProcess(string apiKey, string type)
|
public IActionResult AutoProcess(string apiKey, string type)
|
||||||
{
|
{
|
||||||
if (Request.Host.Value != configuration["apiLocalUrl"] || apiKey != configuration["apiKey"])
|
if (Request.Host.Value != configuration["apiLocalUrl"] || apiKey != configuration["apiKey"])
|
||||||
{
|
{
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
}
|
}
|
||||||
|
if (googleSheetValues is null) {
|
||||||
try
|
throw new Exception("Google Sheets API not initialized");
|
||||||
{
|
}
|
||||||
List<Layer> processWorkerLayers = db.Layers
|
|
||||||
.Include(x => x.Records)
|
try
|
||||||
.Where(x =>
|
{
|
||||||
x.Records!.Any(x => x.Code == "Type" && x.Desc1 == "ProcessWorker") &&
|
List<Layer> processWorkerLayers = db.Layers
|
||||||
x.Records!.Any(x => x.Code == "IsEnabled" && x.Desc1 == "True") &&
|
.Include(x => x.Records)
|
||||||
x.Records!.Any(x => x.Code == "ProcessType" && x.Desc1 == type)
|
.Where(x =>
|
||||||
)
|
x.Records!.Any(x => x.Code == "Type" && x.Desc1 == "ProcessWorker") &&
|
||||||
.OrderBy(x => x.CreatedAt)
|
x.Records!.Any(x => x.Code == "IsEnabled" && x.Desc1 == "True") &&
|
||||||
.ToList();
|
x.Records!.Any(x => x.Code == "ProcessType" && x.Desc1 == type)
|
||||||
|
)
|
||||||
|
.OrderBy(x => x.CreatedAt)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
if (processWorkerLayers.Count() == 0)
|
if (processWorkerLayers.Count() == 0)
|
||||||
{
|
{
|
||||||
logsController.AddEntry(new LogEntry
|
logsController.AddEntry(new LogEntry
|
||||||
@@ -237,15 +245,15 @@ namespace WebAPI.Controllers
|
|||||||
Type = LogEntryType.info,
|
Type = LogEntryType.info,
|
||||||
LogType = LogType.process,
|
LogType = LogType.process,
|
||||||
CreatedAt = DateTime.UtcNow,
|
CreatedAt = DateTime.UtcNow,
|
||||||
});
|
});
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Layer processWorker in processWorkerLayers)
|
foreach (Layer processWorker in processWorkerLayers)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
@@ -284,7 +292,7 @@ namespace WebAPI.Controllers
|
|||||||
});
|
});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
T3SourceYearSummaryProcessor processor = new T3SourceYearSummaryProcessor(db, googleSheetValues, this);
|
T3SourceYearSummaryProcessor processor = new T3SourceYearSummaryProcessor(db, googleSheetValues, this);
|
||||||
processor.process(processWorker!);
|
processor.process(processWorker!);
|
||||||
|
|
||||||
logsController.AddEntry(new LogEntry
|
logsController.AddEntry(new LogEntry
|
||||||
@@ -311,7 +319,7 @@ namespace WebAPI.Controllers
|
|||||||
});
|
});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
T3MultiSourceYearSummaryProcessor processor = new T3MultiSourceYearSummaryProcessor(db, googleSheetValues, this);
|
T3MultiSourceYearSummaryProcessor processor = new T3MultiSourceYearSummaryProcessor(db, googleSheetValues, this);
|
||||||
processor.process(processWorker!);
|
processor.process(processWorker!);
|
||||||
|
|
||||||
logsController.AddEntry(new LogEntry
|
logsController.AddEntry(new LogEntry
|
||||||
@@ -344,13 +352,13 @@ namespace WebAPI.Controllers
|
|||||||
{
|
{
|
||||||
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);
|
T3MultiSourceSummaryProcessor processor = new T3MultiSourceSummaryProcessor(db, googleSheetValues, this);
|
||||||
processor.process(processWorker!);
|
processor.process(processWorker!);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -374,45 +382,45 @@ namespace WebAPI.Controllers
|
|||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
logsController.AddEntry(new LogEntry
|
logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = "Process error",
|
Title = "Process error",
|
||||||
Type = LogEntryType.error,
|
Type = LogEntryType.error,
|
||||||
LogType = LogType.process,
|
LogType = LogType.process,
|
||||||
Message = e.ToString(),
|
Message = e.ToString(),
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
return BadRequest(e.ToString());
|
return BadRequest(e.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
internal void SaveRecords(Guid id, ICollection<Record> records, Guid currentUserId)
|
internal void SaveRecords(Guid id, ICollection<Record> records, Guid currentUserId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<Record> toDelete = db.Records.Where(x => x.LayerId == id).ToList();
|
List<Record> toDelete = db.Records.Where(x => x.LayerId == id).ToList();
|
||||||
if (toDelete.Count > 0)
|
if (toDelete.Count > 0)
|
||||||
{
|
{
|
||||||
db.Records.RemoveRange(toDelete);
|
db.Records.RemoveRange(toDelete);
|
||||||
}
|
}
|
||||||
foreach (Record record in records)
|
foreach (Record record in records)
|
||||||
{
|
{
|
||||||
record.CreatedById = currentUserId;
|
record.CreatedById = currentUserId;
|
||||||
record.CreatedAt = DateTime.UtcNow;
|
record.CreatedAt = DateTime.UtcNow;
|
||||||
record.ModifiedById = currentUserId;
|
record.ModifiedById = currentUserId;
|
||||||
record.ModifiedAt = DateTime.UtcNow;
|
record.ModifiedAt = DateTime.UtcNow;
|
||||||
record.LayerId = id;
|
record.LayerId = id;
|
||||||
db.Records.Add(record);
|
db.Records.Add(record);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@ namespace WebAPI.Controllers
|
|||||||
{
|
{
|
||||||
public class LogsController : Controller
|
public class LogsController : Controller
|
||||||
{
|
{
|
||||||
private SpreadsheetsResource.ValuesResource googleSheetValues;
|
private SpreadsheetsResource.ValuesResource? googleSheetValues;
|
||||||
private GoogleDriveHelper googleDriveHelper;
|
private GoogleDriveHelper googleDriveHelper;
|
||||||
private readonly IConfiguration configuration;
|
private readonly IConfiguration configuration;
|
||||||
public LogsController(
|
public LogsController(
|
||||||
@@ -17,13 +17,18 @@ namespace WebAPI.Controllers
|
|||||||
GoogleDriveHelper _googleDriveHelper,
|
GoogleDriveHelper _googleDriveHelper,
|
||||||
IConfiguration _configuration)
|
IConfiguration _configuration)
|
||||||
{
|
{
|
||||||
googleSheetValues = _googleSheetsHelper.Service.Spreadsheets.Values;
|
if (_googleSheetsHelper.Service is not null) {
|
||||||
|
googleSheetValues = _googleSheetsHelper.Service.Spreadsheets.Values;
|
||||||
|
}
|
||||||
googleDriveHelper = _googleDriveHelper;
|
googleDriveHelper = _googleDriveHelper;
|
||||||
configuration = _configuration;
|
configuration = _configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddEntry(LogEntry entry)
|
public void AddEntry(LogEntry entry)
|
||||||
{
|
{
|
||||||
|
if (googleSheetValues is null) {
|
||||||
|
throw new Exception("Google Sheets API not initialized");
|
||||||
|
}
|
||||||
String type;
|
String type;
|
||||||
switch (entry.LogType) {
|
switch (entry.LogType) {
|
||||||
case LogType.import:
|
case LogType.import:
|
||||||
@@ -42,8 +47,8 @@ namespace WebAPI.Controllers
|
|||||||
var response = googleSheetValues.Get(configuration["appLogsFile"], $"{type}!A:A").Execute();
|
var response = googleSheetValues.Get(configuration["appLogsFile"], $"{type}!A:A").Execute();
|
||||||
var data = response.Values;
|
var data = response.Values;
|
||||||
int row = 1;
|
int row = 1;
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
row = data.Count + 1;
|
row = data.Count + 1;
|
||||||
}
|
}
|
||||||
var range = $"{type}!A{row}:D{row}";
|
var range = $"{type}!A{row}:D{row}";
|
||||||
|
|
||||||
|
|||||||
@@ -23,51 +23,55 @@ namespace WebAPI.Exports
|
|||||||
}
|
}
|
||||||
public void export(Layer layer)
|
public void export(Layer layer)
|
||||||
{
|
{
|
||||||
|
if (googleDriveHelper.Service is null)
|
||||||
|
{
|
||||||
|
throw new Exception("Google Drive API not initialized");
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
List<IList<object>> data = new List<IList<object>>() { new List<object>() { layer.Name! } };
|
List<IList<object>> data = new List<IList<object>>() { new List<object>() { layer.Name! } };
|
||||||
|
|
||||||
switch (layer.Type)
|
switch (layer.Type)
|
||||||
{
|
{
|
||||||
case LayerType.import:
|
case LayerType.import:
|
||||||
{
|
{
|
||||||
data.Add(new List<object> { "Code", "Value1" });
|
data.Add(new List<object> { "Code", "Value1" });
|
||||||
foreach (Record record in layer.Records!)
|
foreach (Record record in layer.Records!)
|
||||||
{
|
{
|
||||||
data.Add(new List<object> { record.Code!, record.Value1! });
|
data.Add(new List<object> { record.Code!, record.Value1! });
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LayerType.administration:
|
case LayerType.administration:
|
||||||
{
|
{
|
||||||
data.Add(new List<object> { "Code", "Desc1"});
|
data.Add(new List<object> { "Code", "Desc1"});
|
||||||
foreach (Record record in layer.Records!)
|
foreach (Record record in layer.Records!)
|
||||||
{
|
{
|
||||||
data.Add(new List<object> { record.Code!, record.Desc1!});
|
data.Add(new List<object> { record.Code!, record.Desc1!});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LayerType.processed:
|
case LayerType.processed:
|
||||||
{
|
{
|
||||||
data.Add(new List<object> { "Code", "Value1", "Value2", "Value3", "Value3",
|
data.Add(new List<object> { "Code", "Value1", "Value2", "Value3", "Value3",
|
||||||
"Value5", "Value6", "Value7", "Value8", "Value9", "Value10",
|
"Value5", "Value6", "Value7", "Value8", "Value9", "Value10",
|
||||||
"Value11", "Value12", "Value13", "Value14", "Value15", "Value16",
|
"Value11", "Value12", "Value13", "Value14", "Value15", "Value16",
|
||||||
"Value17", "Value18", "Value19", "Value20", "Value21", "Value22",
|
"Value17", "Value18", "Value19", "Value20", "Value21", "Value22",
|
||||||
"Value23", "Value24", "Value25", "Value26", "Value27", "Value28",
|
"Value23", "Value24", "Value25", "Value26", "Value27", "Value28",
|
||||||
"Value29", "Value30", "Value31", "Value32"});
|
"Value29", "Value30", "Value31", "Value32"});
|
||||||
|
|
||||||
foreach (Record record in layer.Records!)
|
foreach (Record record in layer.Records!)
|
||||||
{
|
{
|
||||||
data.Add(new List<object> { record.Code!, record.Value1!, record.Value2!, record.Value3!, record.Value4!,
|
data.Add(new List<object> { record.Code!, record.Value1!, record.Value2!, record.Value3!, record.Value4!,
|
||||||
record.Value5!, record.Value6!, record.Value7!, record.Value8!, record.Value9!, record.Value10!,
|
record.Value5!, record.Value6!, record.Value7!, record.Value8!, record.Value9!, record.Value10!,
|
||||||
record.Value11!, record.Value12!, record.Value13!, record.Value14!, record.Value15!, record.Value16!,
|
record.Value11!, record.Value12!, record.Value13!, record.Value14!, record.Value15!, record.Value16!,
|
||||||
record.Value17!, record.Value18!, record.Value19!, record.Value20!, record.Value21!, record.Value22!,
|
record.Value17!, record.Value18!, record.Value19!, record.Value20!, record.Value21!, record.Value22!,
|
||||||
record.Value23!, record.Value24!, record.Value25!, record.Value26!, record.Value27!, record.Value28!,
|
record.Value23!, record.Value24!, record.Value25!, record.Value26!, record.Value27!, record.Value28!,
|
||||||
record.Value29!, record.Value30!, record.Value31!, record.Value32!});
|
record.Value29!, record.Value30!, record.Value31!, record.Value32!});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Google.Apis.Drive.v3.Data.File body = new Google.Apis.Drive.v3.Data.File();
|
Google.Apis.Drive.v3.Data.File body = new Google.Apis.Drive.v3.Data.File();
|
||||||
@@ -90,11 +94,11 @@ namespace WebAPI.Exports
|
|||||||
{
|
{
|
||||||
Console.WriteLine(e.ToString());
|
Console.WriteLine(e.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getNumberOfValues(List<Record> records)
|
private int getNumberOfValues(List<Record> records)
|
||||||
{
|
{
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace WebAPI
|
|||||||
{
|
{
|
||||||
public class GoogleDriveHelper
|
public class GoogleDriveHelper
|
||||||
{
|
{
|
||||||
public DriveService Service { get; set; }
|
public DriveService? Service { get; set; }
|
||||||
const string APPLICATION_NAME = "Diuna";
|
const string APPLICATION_NAME = "Diuna";
|
||||||
static readonly string[] Scopes = { DriveService.Scope.Drive };
|
static readonly string[] Scopes = { DriveService.Scope.Drive };
|
||||||
public GoogleDriveHelper()
|
public GoogleDriveHelper()
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace WebAPI
|
|||||||
{
|
{
|
||||||
public class GoogleSheetsHelper
|
public class GoogleSheetsHelper
|
||||||
{
|
{
|
||||||
public SheetsService Service { get; set; }
|
public SheetsService? Service { get; set; }
|
||||||
const string APPLICATION_NAME = "Diuna";
|
const string APPLICATION_NAME = "Diuna";
|
||||||
static readonly string[] Scopes = { SheetsService.Scope.Spreadsheets };
|
static readonly string[] Scopes = { SheetsService.Scope.Spreadsheets };
|
||||||
public GoogleSheetsHelper()
|
public GoogleSheetsHelper()
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
using Google.Apis.Sheets.v4;
|
|
||||||
using System.Globalization;
|
|
||||||
using WebAPI.Models;
|
|
||||||
|
|
||||||
namespace WebAPI.dataParsers
|
|
||||||
{
|
|
||||||
public class googleSheetParser
|
|
||||||
{
|
|
||||||
private SpreadsheetsResource.ValuesResource googleSheetValues;
|
|
||||||
|
|
||||||
public googleSheetParser(SpreadsheetsResource.ValuesResource _googleSheetValues)
|
|
||||||
{
|
|
||||||
googleSheetValues = _googleSheetValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
public dynamic parse(string sheetId)
|
|
||||||
{
|
|
||||||
var range = "Arkusz1!A:B";
|
|
||||||
|
|
||||||
var request = googleSheetValues.Get(sheetId, range);
|
|
||||||
var response = request.Execute();
|
|
||||||
var data = response.Values;
|
|
||||||
|
|
||||||
List<Record> records = new List<Record>();
|
|
||||||
|
|
||||||
string date = (string)data[0][0];
|
|
||||||
|
|
||||||
for (int i = 1; i < data.Count; i++)
|
|
||||||
{
|
|
||||||
float value = float.Parse(data[i][1].ToString(), CultureInfo.GetCultureInfo("pl-PL"));
|
|
||||||
if (value > 0)
|
|
||||||
{
|
|
||||||
Record record = new Record();
|
|
||||||
record.Id = Guid.NewGuid();
|
|
||||||
record.Code = data[i][0].ToString();
|
|
||||||
record.Value1 = value;
|
|
||||||
record.CreatedAt = DateTime.UtcNow;
|
|
||||||
record.ModifiedAt = DateTime.UtcNow;
|
|
||||||
records.Add(record);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new
|
|
||||||
{
|
|
||||||
records = records,
|
|
||||||
date = date
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using DiunaBIWebAPI.dataProcessors;
|
using DiunaBIWebAPI.dataProcessors;
|
||||||
using Google.Apis.Sheets.v4;
|
using Google.Apis.Sheets.v4;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using WebAPI.Controllers;
|
using WebAPI.Controllers;
|
||||||
@@ -69,7 +69,7 @@ namespace WebAPI.dataProcessors
|
|||||||
Layer? dataSource = db.Layers.Where(x =>
|
Layer? dataSource = db.Layers.Where(x =>
|
||||||
x.Type == LayerType.processed &&
|
x.Type == LayerType.processed &&
|
||||||
!x.IsDeleted &&
|
!x.IsDeleted &&
|
||||||
x.Name.Contains($"{year}/{month}-{source.Desc1}-T3")
|
x.Name!=null && x.Name.Contains($"{year}/{month}-{source.Desc1}-T3")
|
||||||
)
|
)
|
||||||
.Include(x => x.Records)
|
.Include(x => x.Records)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using DiunaBIWebAPI.dataProcessors;
|
using DiunaBIWebAPI.dataProcessors;
|
||||||
using Google.Apis.Sheets.v4;
|
using Google.Apis.Sheets.v4;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using WebAPI.Controllers;
|
using WebAPI.Controllers;
|
||||||
@@ -67,7 +67,7 @@ namespace WebAPI.dataProcessors
|
|||||||
Layer? dataSource = db.Layers.Where(x =>
|
Layer? dataSource = db.Layers.Where(x =>
|
||||||
x.Type == LayerType.processed &&
|
x.Type == LayerType.processed &&
|
||||||
!x.IsDeleted &&
|
!x.IsDeleted &&
|
||||||
x.Name.Contains($"{year}/13-{source.Desc1}-T3")
|
x.Name != null && x.Name.Contains($"{year}/13-{source.Desc1}-T3")
|
||||||
)
|
)
|
||||||
.Include(x => x.Records)
|
.Include(x => x.Records)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
@@ -87,7 +87,7 @@ namespace WebAPI.dataProcessors
|
|||||||
Layer? dataSource = db.Layers.Where(x =>
|
Layer? dataSource = db.Layers.Where(x =>
|
||||||
x.Type == LayerType.processed
|
x.Type == LayerType.processed
|
||||||
&& !x.IsDeleted
|
&& !x.IsDeleted
|
||||||
&& x.Name.Contains($"{year}/{i}-AA-T3"))
|
&& x.Name!=null && x.Name.Contains($"{year}/{i}-AA-T3"))
|
||||||
.Include(x => x.Records)
|
.Include(x => x.Records)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
if (dataSource != null)
|
if (dataSource != null)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using DiunaBIWebAPI.dataProcessors;
|
using DiunaBIWebAPI.dataProcessors;
|
||||||
using Google.Apis.Sheets.v4;
|
using Google.Apis.Sheets.v4;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using WebAPI.Controllers;
|
using WebAPI.Controllers;
|
||||||
@@ -67,7 +67,7 @@ namespace WebAPI.dataProcessors
|
|||||||
Layer? dataSource = db.Layers.Where(x =>
|
Layer? dataSource = db.Layers.Where(x =>
|
||||||
x.Type == LayerType.processed
|
x.Type == LayerType.processed
|
||||||
&& !x.IsDeleted
|
&& !x.IsDeleted
|
||||||
&& x.Name.Contains($"{year}/{i}-{source}-T3"))
|
&& x.Name!=null && x.Name.Contains($"{year}/{i}-{source}-T3"))
|
||||||
.Include(x => x.Records)
|
.Include(x => x.Records)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
if (dataSource != null)
|
if (dataSource != null)
|
||||||
|
|||||||
Reference in New Issue
Block a user