Cleanup .net warnings
This commit is contained in:
@@ -80,6 +80,10 @@ 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";
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
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;
|
||||||
@@ -18,7 +15,7 @@ namespace WebAPI.Controllers
|
|||||||
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;
|
||||||
@@ -30,7 +27,9 @@ namespace WebAPI.Controllers
|
|||||||
IConfiguration _configuration)
|
IConfiguration _configuration)
|
||||||
{
|
{
|
||||||
db = _db;
|
db = _db;
|
||||||
googleSheetValues = _googleSheetsHelper.Service.Spreadsheets.Values;
|
if (_googleSheetsHelper.Service is not null) {
|
||||||
|
googleSheetValues = _googleSheetsHelper.Service.Spreadsheets.Values;
|
||||||
|
}
|
||||||
googleSheetsHelper = _googleSheetsHelper;
|
googleSheetsHelper = _googleSheetsHelper;
|
||||||
googleDriveHelper = _googleDriveHelper;
|
googleDriveHelper = _googleDriveHelper;
|
||||||
configuration = _configuration;
|
configuration = _configuration;
|
||||||
@@ -45,7 +44,7 @@ namespace WebAPI.Controllers
|
|||||||
IQueryable<Layer> response = db.Layers.Where(x => !x.IsDeleted);
|
IQueryable<Layer> response = db.Layers.Where(x => !x.IsDeleted);
|
||||||
if (name != null)
|
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)
|
||||||
{
|
{
|
||||||
@@ -98,6 +97,9 @@ namespace WebAPI.Controllers
|
|||||||
[Route("exportToGoogleSheet/{id}")]
|
[Route("exportToGoogleSheet/{id}")]
|
||||||
public IActionResult ExportToGoogleSheet(Guid id)
|
public IActionResult ExportToGoogleSheet(Guid id)
|
||||||
{
|
{
|
||||||
|
if (googleSheetValues is null) {
|
||||||
|
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();
|
||||||
@@ -116,6 +118,9 @@ namespace WebAPI.Controllers
|
|||||||
{
|
{
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
}
|
}
|
||||||
|
if (googleSheetValues is null) {
|
||||||
|
throw new Exception("Google Sheets API not initialized");
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<Layer> importWorkerLayers;
|
List<Layer> importWorkerLayers;
|
||||||
@@ -216,6 +221,9 @@ namespace WebAPI.Controllers
|
|||||||
{
|
{
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
}
|
}
|
||||||
|
if (googleSheetValues is null) {
|
||||||
|
throw new Exception("Google Sheets API not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -245,7 +253,7 @@ namespace WebAPI.Controllers
|
|||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ 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
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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();
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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