Additional logging in APIs
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
using ReportingServices.Shared.HelperClasses;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using ReportingServices.Shared.HelperClasses;
|
||||||
using ReportingServices.Shared.Models.ProductionReport;
|
using ReportingServices.Shared.Models.ProductionReport;
|
||||||
using ReportingServices.Shared.ViewModels.ProductionReport;
|
using ReportingServices.Shared.ViewModels.ProductionReport;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
@ -9,19 +10,48 @@ namespace ReportingServices.Shared.Repositories
|
|||||||
public class FabTimeReportingRepository : IFabTimeReportingRepository
|
public class FabTimeReportingRepository : IFabTimeReportingRepository
|
||||||
{
|
{
|
||||||
private readonly string _toolFilter = "~R76%2C%20~R78%2C%20~R25%2C%20~R67%2C%20~R69%2C%20~R71%2C%20~R47%2C%20~R51%2C%20~R28";
|
private readonly string _toolFilter = "~R76%2C%20~R78%2C%20~R25%2C%20~R67%2C%20~R69%2C%20~R71%2C%20~R47%2C%20~R51%2C%20~R28";
|
||||||
|
private readonly ILogger<FabTimeReportingRepository> _logger;
|
||||||
|
|
||||||
|
public FabTimeReportingRepository(ILogger<FabTimeReportingRepository> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<List<ReactorOutsByRDS>> GetMovesTrendData(string startDate = "", string endDate = "")
|
public async Task<List<ReactorOutsByRDS>> GetMovesTrendData(string startDate = "", string endDate = "")
|
||||||
{
|
{
|
||||||
string url = APIHelperFunctions.GenerateURLWithParameters(startDate: startDate, endDate: endDate, chart: "MOVESLOTLIST", areasLike: "CLEANROOM", operationsLike: "1UNLOAD");
|
string url = APIHelperFunctions.GenerateURLWithParameters(startDate: startDate, endDate: endDate, chart: "MOVESLOTLIST", areasLike: "CLEANROOM", operationsLike: "1UNLOAD");
|
||||||
|
|
||||||
return await GetJsonData<List<ReactorOutsByRDS>>(url);
|
_logger.LogInformation("FabTime URL: {url}", url);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await GetJsonData<List<ReactorOutsByRDS>>(url);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogCritical(ex, "Error in API call.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<EquipmentStateByDay>> GetToolStateTrendData(string toolType)
|
public async Task<List<EquipmentStateByDay>> GetToolStateTrendData(string toolType)
|
||||||
{
|
{
|
||||||
string url = APIHelperFunctions.GenerateURLWithParameters(chart: "TOOLSTATE", periodLen: "24", capacityTypesLike: toolType, toolsLike: _toolFilter);
|
string url = APIHelperFunctions.GenerateURLWithParameters(chart: "TOOLSTATE", periodLen: "24", capacityTypesLike: toolType, toolsLike: _toolFilter);
|
||||||
|
|
||||||
return await GetJsonData<List<EquipmentStateByDay>>(url);
|
_logger.LogInformation("FabTime URL: {url}", url);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await GetJsonData<List<EquipmentStateByDay>>(url);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogCritical(ex, "Error in API call.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<ToolStateCurrent>> GetToolStateData(string toolType)
|
public async Task<List<ToolStateCurrent>> GetToolStateData(string toolType)
|
||||||
@ -32,25 +62,45 @@ namespace ReportingServices.Shared.Repositories
|
|||||||
string url = APIHelperFunctions.GenerateURLWithParameters(chart: "ToolStateGantt", periodLen: "24",
|
string url = APIHelperFunctions.GenerateURLWithParameters(chart: "ToolStateGantt", periodLen: "24",
|
||||||
capacityTypesLike: capacityFilter, toolsLike: _toolFilter, startDate: startDate);
|
capacityTypesLike: capacityFilter, toolsLike: _toolFilter, startDate: startDate);
|
||||||
|
|
||||||
return await GetJsonData<List<ToolStateCurrent>>(url);
|
_logger.LogInformation("FabTime URL: {url}", url);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await GetJsonData<List<ToolStateCurrent>>(url);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogCritical(ex, "Error in API call.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<T> GetJsonData<T>(string url)
|
public async Task<T> GetJsonData<T>(string url)
|
||||||
{
|
{
|
||||||
T deserializedJson;
|
T deserializedJson = default(T);
|
||||||
|
|
||||||
using (var client = new HttpClient())
|
using (var client = new HttpClient())
|
||||||
{
|
{
|
||||||
using (HttpResponseMessage response = await client.GetAsync(url))
|
using (HttpResponseMessage response = await client.GetAsync(url))
|
||||||
{
|
{
|
||||||
string apiResponse = await response.Content.ReadAsStringAsync();
|
string apiResponse = await response.Content.ReadAsStringAsync();
|
||||||
deserializedJson = JsonSerializer.Deserialize<T>(apiResponse);
|
|
||||||
|
_logger.LogInformation("API Response: {response}" + apiResponse);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
deserializedJson = JsonSerializer.Deserialize<T>(apiResponse);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogCritical(ex, "Failed to deserialize Json object.");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return deserializedJson;
|
return deserializedJson;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user