Added Viewer and

change to App Setting File from Constants
This commit is contained in:
2022-07-27 10:47:57 -07:00
parent 2afec95704
commit b155863645
1012 changed files with 53014 additions and 110896 deletions

View File

@ -8,8 +8,8 @@ using System.IO;
namespace OI.Metrology.Archive.ApiControllers;
public class AttachmentsController : Controller
{
protected IMetrologyRepo _Repo;
protected IAttachmentsService _AttachmentsService;
private readonly IMetrologyRepo _Repo;
private readonly IAttachmentsService _AttachmentsService;
public AttachmentsController(IMetrologyRepo repo, IAttachmentsService attachmentsService)
{

View File

@ -9,7 +9,7 @@ using System.Text.Json;
public class AwaitingDispoController : Controller
{
protected IMetrologyRepo _Repo;
private readonly IMetrologyRepo _Repo;
public AwaitingDispoController(IMetrologyRepo repo) => _Repo = repo;

View File

@ -1,8 +1,8 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using OI.Metrology.Archive.Models;
using OI.Metrology.Shared.DataModels;
using OI.Metrology.Shared.Repositories;
using OI.Metrology.Shared.Services;
@ -15,20 +15,19 @@ namespace OI.Metrology.Archive.ApiContollers;
[ApiController]
public class InboundController : ControllerBase
{
private IConfiguration Config { get; }
private ILogger Logger { get; }
private readonly ILogger _Logger;
private readonly IMetrologyRepo _Repo;
private readonly AppSettings _AppSettings;
private readonly IAttachmentsService _AttachmentService;
private readonly IInboundDataService _InboundDataService;
protected IMetrologyRepo _Repo;
protected IAttachmentsService _AttachmentService;
protected IInboundDataService _InboundDataService;
public InboundController(IConfiguration config, ILogger<InboundController> logger, IMetrologyRepo repo, IInboundDataService inboundDataService, IAttachmentsService attachmentService)
public InboundController(AppSettings appSettings, ILogger<InboundController> logger, IMetrologyRepo repo, IInboundDataService inboundDataService, IAttachmentsService attachmentService)
{
Config = config;
Logger = logger;
_Repo = repo;
_InboundDataService = inboundDataService;
_Logger = logger;
_AppSettings = appSettings;
_AttachmentService = attachmentService;
_InboundDataService = inboundDataService;
}
// this class represents the API response back to the client
@ -57,7 +56,7 @@ public class InboundController : ControllerBase
if (!IsIPAddressAllowed())
{
Logger.LogInformation($"Rejected remote IP: {HttpContext.Connection.RemoteIpAddress}");
_Logger.LogInformation($"Rejected remote IP: {HttpContext.Connection.RemoteIpAddress}");
r.Errors.Add("Remote IP is not on allowed list");
return Unauthorized(r);
}
@ -115,7 +114,7 @@ public class InboundController : ControllerBase
{
if (!IsIPAddressAllowed())
{
Logger.LogInformation($"Rejected remote IP: {HttpContext.Connection.RemoteIpAddress}");
_Logger.LogInformation($"Rejected remote IP: {HttpContext.Connection.RemoteIpAddress}");
return Unauthorized("Remote IP is not on allowed list");
}
@ -145,14 +144,13 @@ public class InboundController : ControllerBase
protected bool IsIPAddressAllowed()
{
string allowedList = Config[Constants.InboundApiAllowedIPList];
if (string.IsNullOrWhiteSpace(allowedList))
if (string.IsNullOrWhiteSpace(_AppSettings.InboundApiAllowedIPList))
return true;
System.Net.IPAddress remoteIP = HttpContext.Connection.RemoteIpAddress;
byte[] remoteIPBytes = remoteIP.GetAddressBytes();
string[] allowedIPs = allowedList.Split(';');
string[] allowedIPs = _AppSettings.InboundApiAllowedIPList.Split(';');
foreach (string ip in allowedIPs)
{
System.Net.IPAddress parsedIP;

View File

@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
using System.IO;
@ -7,6 +6,7 @@ using System.Linq;
namespace OI.Metrology.Archive.ApiContollers;
using OI.Metrology.Archive.Models;
using OI.Metrology.Shared.DataModels;
using OI.Metrology.Shared.Repositories;
using OI.Metrology.Shared.Services;
@ -21,15 +21,14 @@ public class ToolTypesController : Controller
// it is named after the /api/tooltypes prefix
// the URL pattern is RESTful and the tool type is the root of every request
private IConfiguration Config { get; }
private readonly IMetrologyRepo _Repo;
private readonly AppSettings _AppSettings;
private readonly IAttachmentsService _AttachmentsService;
protected IMetrologyRepo _Repo;
protected IAttachmentsService _AttachmentsService;
public ToolTypesController(IConfiguration config, IMetrologyRepo repo, IAttachmentsService attachmentsService)
public ToolTypesController(AppSettings appSettings, IMetrologyRepo repo, IAttachmentsService attachmentsService)
{
Config = config;
_Repo = repo;
_AppSettings = appSettings;
_AttachmentsService = attachmentsService;
}
@ -67,7 +66,7 @@ public class ToolTypesController : Controller
};
return Json(r, new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
}
//Just Changed here
// Just Changed here
// Gets headers, request/response format is to allow paging with igniteUI
// The headerid parameter is used for navigating directly to a header, when the button is clicked in Awaiting Dispo
[HttpGet("/api/tooltypes/{id}/headers")]
@ -77,11 +76,11 @@ public class ToolTypesController : Controller
[FromQuery] DateTime? dateend,
[FromQuery] int? page,
[FromQuery] int? pagesize,
[FromQuery] long? headerid, bool isSharePoint)
[FromQuery] long? headerid)
{
long totalRecs;
System.Data.DataTable dt = _Repo.GetHeaders(id, datebegin, dateend, page, pagesize, headerid, out totalRecs, isSharePoint);
System.Data.DataTable dt = _Repo.GetHeaders(id, datebegin, dateend, page, pagesize, headerid, out totalRecs);
var r = new
{
@ -98,11 +97,11 @@ public class ToolTypesController : Controller
public IActionResult GetHeaderTitles(
int id,
[FromQuery] int? page,
[FromQuery] int? pagesize, bool isArchive)
[FromQuery] int? pagesize)
{
long totalRecs;
IEnumerable<HeaderCommon> dt = _Repo.GetHeaderTitles(id, page, pagesize, out totalRecs, isArchive);
IEnumerable<HeaderCommon> dt = _Repo.GetHeaderTitles(id, page, pagesize, out totalRecs);
var r = new
{
@ -118,11 +117,11 @@ public class ToolTypesController : Controller
[HttpGet("/api/tooltypes/{id}/headers/{headerid}/fields")]
public IActionResult GetHeaderFields(
int id,
long headerid, bool isArchive)
long headerid)
{
var r = new
{
Results = _Repo.GetHeaderFields(id, headerid, isArchive).Select(x => new { Column = x.Key, x.Value }).ToList()
Results = _Repo.GetHeaderFields(id, headerid).Select(x => new { Column = x.Key, x.Value }).ToList()
};
string json = JsonConvert.SerializeObject(r);
@ -148,12 +147,12 @@ public class ToolTypesController : Controller
[HttpGet("/api/tooltypes/{id}/headers/{headerid}/data")]
public IActionResult GetData(
int id,
long headerid, bool isSharePoint)
long headerid)
{
var r = new
{
Results = _Repo.GetData(id, headerid, isSharePoint)
Results = _Repo.GetData(id, headerid)
};
string json = JsonConvert.SerializeObject(r);
@ -166,7 +165,7 @@ public class ToolTypesController : Controller
int toolTypeId,
string tabletype,
string attachmentId,
string filename, bool isArchive)
string filename)
{
ToolType tt = _Repo.GetToolTypeByID(toolTypeId);
@ -177,8 +176,6 @@ public class ToolTypesController : Controller
if (!Guid.TryParse(attachmentId, out attachmentIdParsed))
return Content("Invalid attachment id");
//try
// {
// figure out what content type to use. this is very simple because there are only two types being used
string contenttype = "application/pdf";
if (filename.ToLower().TrimEnd().EndsWith(".txt"))
@ -186,18 +183,7 @@ public class ToolTypesController : Controller
// Get attachment stream and feed it to the client
Stream fs = _AttachmentsService.GetAttachmentStreamByAttachmentId(tt, header, attachmentIdParsed, filename);
/*if (isArchive)
{
fs = attachmentsService.GetAttachmentStreamByAttachmentIdArchive(tt, header, attachmentIdParsed, filename);
//fs = attachmentsService.GetAttachmentStreamByAttachmentId
}*/
return File(fs, contenttype);
//}
/*catch (Exception ex)
{
return Content(ex.Message);
}*/
}
// This endpoint triggers writing of the OI Export file
@ -247,13 +233,9 @@ public class ToolTypesController : Controller
// The output file will only have one line, the header columns are output first
// Then each detail rows has it's columns appended
// H1, H2, H3, D1.1, D1.2, D1.3, D2.1, D2.2, D2.3, etc
// Get the configured export path
string exportRootPath = Config[Constants.OIExportPathKey];
// Write the file
System.IO.File.WriteAllText(
Path.Join(exportRootPath, filename),
Path.Join(_AppSettings.OIExportPath, filename),
sb.ToString());
}