TargetFramework update,
reference updates and added tests for Viewer
This commit is contained in:
@ -1,7 +1,5 @@
|
||||
using Microsoft.AspNetCore.Diagnostics;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace OI.Metrology.Viewer.Controllers;
|
||||
|
||||
@ -14,8 +12,8 @@ public class ErrorHandlerController : Controller
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
IExceptionHandlerFeature error = HttpContext.Features.Get<IExceptionHandlerFeature>();
|
||||
if (error == null)
|
||||
IExceptionHandlerFeature? error = HttpContext.Features.Get<IExceptionHandlerFeature>();
|
||||
if (error is null)
|
||||
{
|
||||
return Redirect("~/");
|
||||
}
|
||||
@ -24,7 +22,7 @@ public class ErrorHandlerController : Controller
|
||||
_Logger.LogError("Unhandled exception: " + error.Error.ToString());
|
||||
dynamic r = new
|
||||
{
|
||||
Message = error.Error == null ? "Error" : error.Error.Message
|
||||
Message = error.Error is null ? "Error" : error.Error.Message
|
||||
};
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, r);
|
||||
}
|
||||
|
@ -1,14 +1,10 @@
|
||||
using Infineon.Monitoring.MonA;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Repositories;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using OI.Metrology.Shared.ViewModels;
|
||||
using OI.Metrology.Viewer.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OI.Metrology.Viewer.Controllers;
|
||||
@ -17,14 +13,14 @@ public class ExportController : Controller
|
||||
{
|
||||
private readonly ILogger _Logger;
|
||||
private readonly bool _IsTestDatabase;
|
||||
private readonly IMetrologyRepo _Repo;
|
||||
private readonly AppSettings _AppSettings;
|
||||
private readonly IMetrologyRepository _MetrologyRepository;
|
||||
|
||||
public ExportController(AppSettings appSettings, ILogger<ExportController> logger, IMetrologyRepo repo)
|
||||
public ExportController(AppSettings appSettings, ILogger<ExportController> logger, IMetrologyRepository metrologyRepository)
|
||||
{
|
||||
_Repo = repo;
|
||||
_Logger = logger;
|
||||
_AppSettings = appSettings;
|
||||
_MetrologyRepository = metrologyRepository;
|
||||
_IsTestDatabase = appSettings.ConnectionString.Contains("test", StringComparison.InvariantCultureIgnoreCase);
|
||||
}
|
||||
|
||||
@ -52,14 +48,14 @@ public class ExportController : Controller
|
||||
[Route("/ExportData")]
|
||||
public ActionResult ExportData(Export model)
|
||||
{
|
||||
ToolType toolType = null;
|
||||
ToolType? toolType = null;
|
||||
if (string.IsNullOrEmpty(model.ToolType))
|
||||
ModelState.AddModelError("Exception", "Invalid selection");
|
||||
else
|
||||
{
|
||||
if (model.StartTime > model.EndTime)
|
||||
ModelState.AddModelError("EndTime", "End time must be after start time");
|
||||
IEnumerable<ToolType> toolTypes = _Repo.GetToolTypes();
|
||||
IEnumerable<ToolType> toolTypes = _MetrologyRepository.GetToolTypes();
|
||||
toolType = toolTypes.Where(tt => tt.ID.ToString() == model.ToolType).SingleOrDefault();
|
||||
if (toolType is null)
|
||||
ModelState.AddModelError("ToolType", "Invalid selection");
|
||||
@ -73,7 +69,7 @@ public class ExportController : Controller
|
||||
DateTime startDT = model.StartDate.Date.Add(model.StartTime.TimeOfDay);
|
||||
DateTime endDT = model.EndDate.Date.Add(model.EndTime.TimeOfDay);
|
||||
|
||||
return DoCSVExport(toolType.ToolTypeName, toolType.ExportSPName, startDT, endDT);
|
||||
return DoCSVExport(toolType?.ToolTypeName, toolType?.ExportSPName, startDT, endDT);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -86,22 +82,17 @@ public class ExportController : Controller
|
||||
return View("Index", model);
|
||||
}
|
||||
|
||||
protected ActionResult DoCSVExport(string toolTypeName, string spName, DateTime startTime, DateTime endTime)
|
||||
protected ActionResult DoCSVExport(string? toolTypeName, string? spName, DateTime startTime, DateTime endTime)
|
||||
{
|
||||
string fileName = string.Format("Export_{0}_{1:yyyyMMddHHmm}_to_{2:yyyyMMddHHmm}.csv", toolTypeName, startTime, endTime);
|
||||
StringBuilder sb = new();
|
||||
|
||||
System.Data.DataTable dt = _Repo.ExportData(spName, startTime, endTime);
|
||||
|
||||
if (spName is null)
|
||||
throw new NullReferenceException(nameof(spName));
|
||||
System.Data.DataTable dt = _MetrologyRepository.ExportData(spName, startTime, endTime);
|
||||
_ = sb.AppendLine(GetColumnHeaders(dt));
|
||||
|
||||
foreach (System.Data.DataRow dr in dt.Rows)
|
||||
{
|
||||
_ = sb.AppendLine(GetRowData(dr));
|
||||
}
|
||||
|
||||
byte[] contents = Encoding.UTF8.GetBytes(sb.ToString());
|
||||
|
||||
return File(contents, "application/octet-stream", fileName);
|
||||
}
|
||||
|
||||
@ -112,10 +103,13 @@ public class ExportController : Controller
|
||||
{
|
||||
if (i > 0)
|
||||
_ = r.Append(',');
|
||||
|
||||
object v = dr[i];
|
||||
if (!Convert.IsDBNull(v))
|
||||
_ = r.Append(FormatForCSV(Convert.ToString(v)));
|
||||
{
|
||||
string? c = Convert.ToString(v);
|
||||
if (c is not null)
|
||||
_ = r.Append(FormatForCSV(c));
|
||||
}
|
||||
}
|
||||
return r.ToString();
|
||||
}
|
||||
@ -135,16 +129,13 @@ public class ExportController : Controller
|
||||
|
||||
protected static string FormatForCSV(string v)
|
||||
{
|
||||
StringBuilder r = new(v.Length + 2);
|
||||
|
||||
bool doubleQuoted = false;
|
||||
|
||||
StringBuilder r = new(v.Length + 2);
|
||||
if (v.StartsWith(' ') || v.EndsWith(' ') || v.Contains(',') || v.Contains('"'))
|
||||
{
|
||||
_ = r.Append('"');
|
||||
doubleQuoted = true;
|
||||
}
|
||||
|
||||
foreach (char c in v)
|
||||
{
|
||||
_ = c switch
|
||||
@ -154,10 +145,8 @@ public class ExportController : Controller
|
||||
_ => r.Append(c),
|
||||
};
|
||||
}
|
||||
|
||||
if (doubleQuoted)
|
||||
_ = r.Append('"');
|
||||
|
||||
return r.ToString();
|
||||
}
|
||||
|
||||
|
@ -1,20 +1,19 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using OI.Metrology.Shared.Repositories;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using OI.Metrology.Shared.ViewModels;
|
||||
using OI.Metrology.Viewer.Models;
|
||||
using System;
|
||||
|
||||
namespace OI.Metrology.Viewer.Controllers;
|
||||
|
||||
public class PagesController : Controller
|
||||
{
|
||||
private readonly IMetrologyRepo _Repo;
|
||||
private readonly bool _IsTestDatabase;
|
||||
private readonly IMetrologyRepository _MetrologyRepository;
|
||||
|
||||
public PagesController(AppSettings appSettings, IMetrologyRepo repo)
|
||||
public PagesController(AppSettings appSettings, IMetrologyRepository metrologyRepository)
|
||||
{
|
||||
_Repo = repo;
|
||||
_MetrologyRepository = metrologyRepository;
|
||||
_IsTestDatabase = appSettings.ConnectionString.Contains("test", StringComparison.InvariantCultureIgnoreCase);
|
||||
}
|
||||
|
||||
@ -48,7 +47,7 @@ public class PagesController : Controller
|
||||
};
|
||||
if (headerid > 0)
|
||||
{
|
||||
m.HeaderAttachmentID = _Repo.GetHeaderAttachmentID(tooltypeid, headerid);
|
||||
m.HeaderAttachmentID = _MetrologyRepository.GetHeaderAttachmentID(tooltypeid, headerid);
|
||||
}
|
||||
return View(m);
|
||||
}
|
||||
|
Reference in New Issue
Block a user