Cleanup .net warnings
This commit is contained in:
@@ -80,6 +80,10 @@ namespace WebAPI.Controllers
|
||||
|
||||
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);
|
||||
request.Fields = "id";
|
||||
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
using System.Globalization;
|
||||
using System.Xml.Serialization;
|
||||
using DiunaBIWebAPI.dataImporters;
|
||||
using Google.Apis.Sheets.v4;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WebAPI.dataParsers;
|
||||
using WebAPI.dataProcessors;
|
||||
using WebAPI.Exports;
|
||||
using WebAPI.Models;
|
||||
@@ -18,7 +15,7 @@ namespace WebAPI.Controllers
|
||||
public class LayersController : Controller
|
||||
{
|
||||
private readonly AppDbContext db;
|
||||
private SpreadsheetsResource.ValuesResource googleSheetValues;
|
||||
private SpreadsheetsResource.ValuesResource? googleSheetValues;
|
||||
private GoogleDriveHelper googleDriveHelper;
|
||||
private GoogleSheetsHelper googleSheetsHelper;
|
||||
private readonly IConfiguration configuration;
|
||||
@@ -30,7 +27,9 @@ namespace WebAPI.Controllers
|
||||
IConfiguration _configuration)
|
||||
{
|
||||
db = _db;
|
||||
if (_googleSheetsHelper.Service is not null) {
|
||||
googleSheetValues = _googleSheetsHelper.Service.Spreadsheets.Values;
|
||||
}
|
||||
googleSheetsHelper = _googleSheetsHelper;
|
||||
googleDriveHelper = _googleDriveHelper;
|
||||
configuration = _configuration;
|
||||
@@ -45,7 +44,7 @@ namespace WebAPI.Controllers
|
||||
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)
|
||||
{
|
||||
@@ -98,6 +97,9 @@ namespace WebAPI.Controllers
|
||||
[Route("exportToGoogleSheet/{id}")]
|
||||
public IActionResult ExportToGoogleSheet(Guid id)
|
||||
{
|
||||
if (googleSheetValues is null) {
|
||||
throw new Exception("Google Sheets API not initialized");
|
||||
}
|
||||
Layer layer = db.Layers
|
||||
.Include(x => x.Records!.OrderByDescending(x => x.Code))
|
||||
.Where(x => x.Id == id && !x.IsDeleted).First();
|
||||
@@ -116,6 +118,9 @@ namespace WebAPI.Controllers
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
if (googleSheetValues is null) {
|
||||
throw new Exception("Google Sheets API not initialized");
|
||||
}
|
||||
try
|
||||
{
|
||||
List<Layer> importWorkerLayers;
|
||||
@@ -216,6 +221,9 @@ namespace WebAPI.Controllers
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
if (googleSheetValues is null) {
|
||||
throw new Exception("Google Sheets API not initialized");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
@@ -245,7 +253,7 @@ namespace WebAPI.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
string name = processWorker.Name;
|
||||
string? name = processWorker.Name;
|
||||
string? year = processWorker?.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1;
|
||||
if (year == null)
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace WebAPI.Controllers
|
||||
{
|
||||
public class LogsController : Controller
|
||||
{
|
||||
private SpreadsheetsResource.ValuesResource googleSheetValues;
|
||||
private SpreadsheetsResource.ValuesResource? googleSheetValues;
|
||||
private GoogleDriveHelper googleDriveHelper;
|
||||
private readonly IConfiguration configuration;
|
||||
public LogsController(
|
||||
@@ -17,13 +17,18 @@ namespace WebAPI.Controllers
|
||||
GoogleDriveHelper _googleDriveHelper,
|
||||
IConfiguration _configuration)
|
||||
{
|
||||
if (_googleSheetsHelper.Service is not null) {
|
||||
googleSheetValues = _googleSheetsHelper.Service.Spreadsheets.Values;
|
||||
}
|
||||
googleDriveHelper = _googleDriveHelper;
|
||||
configuration = _configuration;
|
||||
}
|
||||
|
||||
public void AddEntry(LogEntry entry)
|
||||
{
|
||||
if (googleSheetValues is null) {
|
||||
throw new Exception("Google Sheets API not initialized");
|
||||
}
|
||||
String type;
|
||||
switch (entry.LogType) {
|
||||
case LogType.import:
|
||||
|
||||
@@ -23,6 +23,10 @@ namespace WebAPI.Exports
|
||||
}
|
||||
public void export(Layer layer)
|
||||
{
|
||||
if (googleDriveHelper.Service is null)
|
||||
{
|
||||
throw new Exception("Google Drive API not initialized");
|
||||
}
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace WebAPI
|
||||
{
|
||||
public class GoogleDriveHelper
|
||||
{
|
||||
public DriveService Service { get; set; }
|
||||
public DriveService? Service { get; set; }
|
||||
const string APPLICATION_NAME = "Diuna";
|
||||
static readonly string[] Scopes = { DriveService.Scope.Drive };
|
||||
public GoogleDriveHelper()
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace WebAPI
|
||||
{
|
||||
public class GoogleSheetsHelper
|
||||
{
|
||||
public SheetsService Service { get; set; }
|
||||
public SheetsService? Service { get; set; }
|
||||
const string APPLICATION_NAME = "Diuna";
|
||||
static readonly string[] Scopes = { SheetsService.Scope.Spreadsheets };
|
||||
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 =>
|
||||
x.Type == LayerType.processed &&
|
||||
!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)
|
||||
.FirstOrDefault();
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace WebAPI.dataProcessors
|
||||
Layer? dataSource = db.Layers.Where(x =>
|
||||
x.Type == LayerType.processed &&
|
||||
!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)
|
||||
.FirstOrDefault();
|
||||
@@ -87,7 +87,7 @@ namespace WebAPI.dataProcessors
|
||||
Layer? dataSource = db.Layers.Where(x =>
|
||||
x.Type == LayerType.processed
|
||||
&& !x.IsDeleted
|
||||
&& x.Name.Contains($"{year}/{i}-AA-T3"))
|
||||
&& x.Name!=null && x.Name.Contains($"{year}/{i}-AA-T3"))
|
||||
.Include(x => x.Records)
|
||||
.FirstOrDefault();
|
||||
if (dataSource != null)
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace WebAPI.dataProcessors
|
||||
Layer? dataSource = db.Layers.Where(x =>
|
||||
x.Type == LayerType.processed
|
||||
&& !x.IsDeleted
|
||||
&& x.Name.Contains($"{year}/{i}-{source}-T3"))
|
||||
&& x.Name!=null && x.Name.Contains($"{year}/{i}-{source}-T3"))
|
||||
.Include(x => x.Records)
|
||||
.FirstOrDefault();
|
||||
if (dataSource != null)
|
||||
|
||||
Reference in New Issue
Block a user