Moved all of the file paths to appsettings file.
This commit is contained in:
parent
7d2eb5ef0f
commit
afdd487b7d
@ -6,18 +6,15 @@ namespace ReportingServices.Shared.HelperClasses;
|
|||||||
|
|
||||||
public static class DailyReportHelper
|
public static class DailyReportHelper
|
||||||
{
|
{
|
||||||
private static readonly string _dailyRptFilePath = "wwwroot/Assets/DailyReportInfo.json";
|
public static DailyReport SetUpDailyReport(ILogger logger, Dictionary<string, string> filePaths, string baseUrlScrapeDb)
|
||||||
private static readonly string _SLLFilePath = "wwwroot/Assets/SLLTools.json";
|
|
||||||
|
|
||||||
public static DailyReport SetUpDailyReport(ILogger logger, string baseUrlScrapeDb)
|
|
||||||
{
|
{
|
||||||
DailyReport report = new();
|
DailyReport report = new();
|
||||||
DateTime currentDateTime = DateTime.Now;
|
DateTime currentDateTime = DateTime.Now;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<SLLTool> tools = JsonFileHandler.LoadJSONFile<List<SLLTool>>(_SLLFilePath);
|
List<SLLTool> tools = JsonFileHandler.LoadJSONFile<List<SLLTool>>(filePaths["SLL"]);
|
||||||
ManualReportEntries manualEntries = JsonFileHandler.LoadJSONFile<ManualReportEntries>(_dailyRptFilePath);
|
ManualReportEntries manualEntries = JsonFileHandler.LoadJSONFile<ManualReportEntries>(filePaths["DailyReport"]);
|
||||||
|
|
||||||
if (currentDateTime.DayOfWeek == DayOfWeek.Monday && tools[^1].Date == currentDateTime.Date.AddDays(-1))
|
if (currentDateTime.DayOfWeek == DayOfWeek.Monday && tools[^1].Date == currentDateTime.Date.AddDays(-1))
|
||||||
report.SLLTools = new List<SLLTool>();
|
report.SLLTools = new List<SLLTool>();
|
||||||
@ -26,12 +23,14 @@ public static class DailyReportHelper
|
|||||||
|
|
||||||
report.ManualReportEntries = manualEntries;
|
report.ManualReportEntries = manualEntries;
|
||||||
|
|
||||||
|
report.ToolStatesByOwner = JsonFileHandler.LoadJSONFile<Dictionary<string, List<string>>>(filePaths["ToolStateOwners"]);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.LogError(ex, "Failed to load JsonFiles.");
|
logger.LogError(ex, "Failed to load JsonFiles.");
|
||||||
logger.LogInformation("SLL File Path: {path}", _SLLFilePath);
|
logger.LogInformation("SLL File Path: {path}", filePaths["SLL"]);
|
||||||
logger.LogInformation("Manual Report Entries File Path: {path}", _dailyRptFilePath);
|
logger.LogInformation("Manual Report Entries File Path: {path}", filePaths["DailyReport"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<string> cleanTools = new()
|
List<string> cleanTools = new()
|
||||||
@ -169,8 +168,8 @@ public static class DailyReportHelper
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
JsonFileHandler.SaveJSONFile(entries, _dailyRptFilePath);
|
JsonFileHandler.SaveJSONFile(entries, filePaths["DailyReport"]);
|
||||||
JsonFileHandler.SaveJSONFile(sll, _SLLFilePath);
|
JsonFileHandler.SaveJSONFile(sll, filePaths["SLL"]);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
namespace ReportingServices.Shared.ViewModels.ProductionReport;
|
namespace ReportingServices.Shared.Models.ProductionReport;
|
||||||
|
|
||||||
public class SLLTool
|
public class SLLTool
|
||||||
{
|
{
|
@ -1,4 +1,4 @@
|
|||||||
namespace ReportingServices.Shared.ViewModels.ProductionReport;
|
namespace ReportingServices.Shared.Models.ProductionReport;
|
||||||
|
|
||||||
public class UnloadTempsByDay
|
public class UnloadTempsByDay
|
||||||
{
|
{
|
@ -9,16 +9,20 @@ namespace ReportingServices.UI.Controllers;
|
|||||||
public class ProductionReportController : Controller
|
public class ProductionReportController : Controller
|
||||||
{
|
{
|
||||||
private readonly ILogger<ProductionReportController> _logger;
|
private readonly ILogger<ProductionReportController> _logger;
|
||||||
private readonly string _dailyRptFilePath;
|
private readonly Dictionary<string, string> _filePaths;
|
||||||
private readonly string _toolStateOwnerFilePath;
|
|
||||||
private readonly string _baseDBUrl;
|
private readonly string _baseDBUrl;
|
||||||
|
|
||||||
public ProductionReportController(ILogger<ProductionReportController> logger, AppSettings appSettings)
|
public ProductionReportController(ILogger<ProductionReportController> logger, AppSettings appSettings)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_baseDBUrl = appSettings.BaseAPIAddress;
|
_baseDBUrl = appSettings.BaseAPIAddress;
|
||||||
_dailyRptFilePath = appSettings.DailyReportFilePath;
|
|
||||||
_toolStateOwnerFilePath = appSettings.ToolStateOwnerFilePath;
|
_filePaths = new()
|
||||||
|
{
|
||||||
|
{ "DailyReport", appSettings.DailyReportFilePath },
|
||||||
|
{ "ToolStateOwners", appSettings.ToolStateOwnerFilePath },
|
||||||
|
{ "SLL", appSettings.SLLFilePath },
|
||||||
|
};
|
||||||
|
|
||||||
_logger.LogInformation("Base Database Address: {baseUrl}", _baseDBUrl);
|
_logger.LogInformation("Base Database Address: {baseUrl}", _baseDBUrl);
|
||||||
}
|
}
|
||||||
@ -29,10 +33,7 @@ public class ProductionReportController : Controller
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DailyReport dailyReport = DailyReportHelper.SetUpDailyReport(_logger, _baseDBUrl);
|
DailyReport dailyReport = DailyReportHelper.SetUpDailyReport(_logger, _filePaths, _baseDBUrl);
|
||||||
Dictionary<string, List<string>> toolStateOwners = JsonFileHandler.LoadJSONFile<Dictionary<string, List<string>>>(_toolStateOwnerFilePath);
|
|
||||||
|
|
||||||
dailyReport.ToolStatesByOwner = toolStateOwners;
|
|
||||||
|
|
||||||
return View(dailyReport);
|
return View(dailyReport);
|
||||||
}
|
}
|
||||||
@ -45,7 +46,7 @@ public class ProductionReportController : Controller
|
|||||||
|
|
||||||
public IActionResult EditDailyReport()
|
public IActionResult EditDailyReport()
|
||||||
{
|
{
|
||||||
ManualReportEntries entries = JsonFileHandler.LoadJSONFile<ManualReportEntries>(_dailyRptFilePath);
|
ManualReportEntries entries = JsonFileHandler.LoadJSONFile<ManualReportEntries>(_filePaths["DailyReport"]);
|
||||||
|
|
||||||
return View(entries);
|
return View(entries);
|
||||||
}
|
}
|
||||||
@ -53,7 +54,7 @@ public class ProductionReportController : Controller
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public IActionResult EditDailyReport(ManualReportEntries rpt)
|
public IActionResult EditDailyReport(ManualReportEntries rpt)
|
||||||
{
|
{
|
||||||
JsonFileHandler.SaveJSONFile(rpt, _dailyRptFilePath);
|
JsonFileHandler.SaveJSONFile(rpt, _filePaths["DailyReport"]);
|
||||||
|
|
||||||
return RedirectToAction("DailyReport");
|
return RedirectToAction("DailyReport");
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ public record AppSettings(string BaseAPIAddress,
|
|||||||
bool IsStaging,
|
bool IsStaging,
|
||||||
string MonAResource,
|
string MonAResource,
|
||||||
string MonASite,
|
string MonASite,
|
||||||
|
string SLLFilePath,
|
||||||
string ToolStateOwnerFilePath)
|
string ToolStateOwnerFilePath)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ public class AppSettings
|
|||||||
[Display(Name = "Is Staging"), Required] public bool? IsStaging { get; set; }
|
[Display(Name = "Is Staging"), Required] public bool? IsStaging { get; set; }
|
||||||
[Display(Name = "MonA Resource"), Required] public string MonAResource { get; set; }
|
[Display(Name = "MonA Resource"), Required] public string MonAResource { get; set; }
|
||||||
[Display(Name = "MonA Site"), Required] public string MonASite { get; set; }
|
[Display(Name = "MonA Site"), Required] public string MonASite { get; set; }
|
||||||
|
[Display(Name = "SLL File Path"), Required] public string SLLFilePath { get; set; }
|
||||||
[Display(Name = "Tool State Owner File Path"), Required] public string ToolStateOwnerFilePath { get; set; }
|
[Display(Name = "Tool State Owner File Path"), Required] public string ToolStateOwnerFilePath { get; set; }
|
||||||
|
|
||||||
#nullable enable
|
#nullable enable
|
||||||
@ -53,6 +54,8 @@ public class AppSettings
|
|||||||
throw new NullReferenceException(nameof(MonAResource));
|
throw new NullReferenceException(nameof(MonAResource));
|
||||||
if (appSettings.MonASite is null)
|
if (appSettings.MonASite is null)
|
||||||
throw new NullReferenceException(nameof(MonASite));
|
throw new NullReferenceException(nameof(MonASite));
|
||||||
|
if (appSettings.SLLFilePath is null)
|
||||||
|
throw new NullReferenceException(nameof(SLLFilePath));
|
||||||
if (appSettings.ToolStateOwnerFilePath is null)
|
if (appSettings.ToolStateOwnerFilePath is null)
|
||||||
throw new NullReferenceException(nameof(ToolStateOwnerFilePath));
|
throw new NullReferenceException(nameof(ToolStateOwnerFilePath));
|
||||||
result = new(
|
result = new(
|
||||||
@ -66,6 +69,7 @@ public class AppSettings
|
|||||||
appSettings.IsStaging.Value,
|
appSettings.IsStaging.Value,
|
||||||
appSettings.MonAResource,
|
appSettings.MonAResource,
|
||||||
appSettings.MonASite,
|
appSettings.MonASite,
|
||||||
|
appSettings.SLLFilePath,
|
||||||
appSettings.ToolStateOwnerFilePath);
|
appSettings.ToolStateOwnerFilePath);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -55,5 +55,6 @@
|
|||||||
"Application": "Sample"
|
"Application": "Sample"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"SLLFilePath": "wwwroot/Assets/SLLTools.json",
|
||||||
"ToolStateOwnerFilePath": "wwwroot/Assets/ToolStates.json"
|
"ToolStateOwnerFilePath": "wwwroot/Assets/ToolStates.json"
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user