Viewer to Server
This commit is contained in:
@ -6,27 +6,27 @@ namespace OI.Metrology.Archive.Services;
|
||||
|
||||
using OI.Metrology.Archive.Models;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Repositories;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using OI.Metrology.Shared.Services;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
public class AttachmentsService : IAttachmentsService
|
||||
{
|
||||
|
||||
private readonly IMetrologyRepo _Repo;
|
||||
private readonly AppSettings _AppSettings;
|
||||
private readonly IMetrologyRepository _MetrologyRepository;
|
||||
|
||||
public AttachmentsService(AppSettings appSettings, IMetrologyRepo repo)
|
||||
public AttachmentsService(AppSettings appSettings, IMetrologyRepository metrologyRepository)
|
||||
{
|
||||
_Repo = repo;
|
||||
_AppSettings = appSettings;
|
||||
_MetrologyRepository = metrologyRepository;
|
||||
}
|
||||
protected Stream GetAttachmentStream(string tableName, Guid attachmentId, string filename)
|
||||
{
|
||||
if (attachmentId.Equals(Guid.Empty))
|
||||
throw new Exception("No attachments found");
|
||||
|
||||
DateTime insertDate = Convert.ToDateTime(_Repo.GetAttachmentInsertDateByGUID(tableName, attachmentId));
|
||||
DateTime insertDate = Convert.ToDateTime(_MetrologyRepository.GetAttachmentInsertDateByGUID(tableName, attachmentId));
|
||||
int year = insertDate.Year;
|
||||
DateTime d = insertDate;
|
||||
CultureInfo cul = CultureInfo.CurrentCulture;
|
||||
@ -63,7 +63,7 @@ public class AttachmentsService : IAttachmentsService
|
||||
|
||||
public Stream GetAttachmentStreamByTitle(ToolType toolType, bool header, string title, string filename)
|
||||
{
|
||||
if (toolType == null)
|
||||
if (toolType is null)
|
||||
throw new Exception("Invalid tool type");
|
||||
|
||||
string queryString = "SELECT * FROM " + toolType.DataTableName + " WHERE AttachmentId = @attachmentId";
|
||||
@ -103,19 +103,19 @@ public class AttachmentsService : IAttachmentsService
|
||||
if (header)
|
||||
{
|
||||
tableName = toolType.HeaderTableName;
|
||||
attachmentId = _Repo.GetHeaderAttachmentIDByTitle(toolType.ID, title);
|
||||
attachmentId = _MetrologyRepository.GetHeaderAttachmentIDByTitle(toolType.ID, title);
|
||||
}
|
||||
else
|
||||
{
|
||||
tableName = toolType.DataTableName;
|
||||
attachmentId = _Repo.GetDataAttachmentIDByTitle(toolType.ID, title);
|
||||
attachmentId = _MetrologyRepository.GetDataAttachmentIDByTitle(toolType.ID, title);
|
||||
}
|
||||
return GetAttachmentStream(tableName, attachmentId, filename);
|
||||
}
|
||||
|
||||
public Stream GetAttachmentStreamByAttachmentId(ToolType toolType, bool header, Guid attachmentId, string filename)
|
||||
{
|
||||
if (toolType == null)
|
||||
if (toolType is null)
|
||||
throw new Exception("Invalid tool type");
|
||||
string tableName;
|
||||
if (header)
|
||||
@ -126,7 +126,7 @@ public class AttachmentsService : IAttachmentsService
|
||||
}
|
||||
public Stream GetAttachmentStreamByAttachmentIdArchive(ToolType toolType, bool header, Guid attachmentId, string filename)
|
||||
{
|
||||
if (toolType == null)
|
||||
if (toolType is null)
|
||||
throw new Exception("Invalid tool type");
|
||||
string tableName;
|
||||
if (header)
|
||||
@ -139,21 +139,21 @@ public class AttachmentsService : IAttachmentsService
|
||||
|
||||
private void SaveAttachment(ToolType toolType, long headerId, string dataUniqueId, string filename, Microsoft.AspNetCore.Http.IFormFile uploadedFile)
|
||||
{
|
||||
if (toolType == null)
|
||||
if (toolType is null)
|
||||
throw new Exception("Invalid tool type");
|
||||
|
||||
using System.Transactions.TransactionScope trans = _Repo.StartTransaction();
|
||||
using System.Transactions.TransactionScope trans = _MetrologyRepository.StartTransaction();
|
||||
Guid attachmentId = Guid.Empty;
|
||||
string tableName = "";
|
||||
|
||||
if (string.IsNullOrWhiteSpace(dataUniqueId))
|
||||
{
|
||||
attachmentId = _Repo.GetHeaderAttachmentID(toolType.ID, headerId);
|
||||
attachmentId = _MetrologyRepository.GetHeaderAttachmentID(toolType.ID, headerId);
|
||||
tableName = toolType.HeaderTableName;
|
||||
}
|
||||
else
|
||||
{
|
||||
attachmentId = _Repo.GetDataAttachmentID(toolType.ID, headerId, dataUniqueId);
|
||||
attachmentId = _MetrologyRepository.GetDataAttachmentID(toolType.ID, headerId, dataUniqueId);
|
||||
tableName = toolType.DataTableName;
|
||||
}
|
||||
if (Equals(attachmentId, Guid.Empty))
|
||||
|
@ -1,6 +1,6 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Repositories;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using OI.Metrology.Shared.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -10,9 +10,9 @@ namespace OI.Metrology.Archive.Services;
|
||||
|
||||
public class InboundDataService : IInboundDataService
|
||||
{
|
||||
private readonly IMetrologyRepo _Repo;
|
||||
private readonly IMetrologyRepository _MetrologyRepository;
|
||||
|
||||
public InboundDataService(IMetrologyRepo repo) => _Repo = repo;
|
||||
public InboundDataService(IMetrologyRepository metrologyRepository) => _MetrologyRepository = metrologyRepository;
|
||||
|
||||
public long DoSQLInsert(JToken jsonbody, ToolType toolType, List<ToolTypeMetadata> metaData)
|
||||
{
|
||||
@ -37,11 +37,11 @@ public class InboundDataService : IInboundDataService
|
||||
|
||||
long headerId = 0;
|
||||
|
||||
using (System.Transactions.TransactionScope transScope = _Repo.StartTransaction())
|
||||
using (System.Transactions.TransactionScope transScope = _MetrologyRepository.StartTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
_Repo.PurgeExistingData(toolType.ID, uniqueId);
|
||||
_MetrologyRepository.PurgeExistingData(toolType.ID, uniqueId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -50,7 +50,7 @@ public class InboundDataService : IInboundDataService
|
||||
|
||||
try
|
||||
{
|
||||
headerId = _Repo.InsertToolDataJSON(jsonbody, -1, metaData, toolType.HeaderTableName);
|
||||
headerId = _MetrologyRepository.InsertToolDataJSON(jsonbody, -1, metaData, toolType.HeaderTableName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -60,11 +60,11 @@ public class InboundDataService : IInboundDataService
|
||||
int detailrow = 1;
|
||||
try
|
||||
{
|
||||
if (detailsArray != null)
|
||||
if (detailsArray is not null)
|
||||
{
|
||||
foreach (JToken detail in detailsArray)
|
||||
{
|
||||
_ = _Repo.InsertToolDataJSON(detail, headerId, metaData, toolType.DataTableName);
|
||||
_ = _MetrologyRepository.InsertToolDataJSON(detail, headerId, metaData, toolType.DataTableName);
|
||||
detailrow += 1;
|
||||
}
|
||||
}
|
||||
@ -133,7 +133,7 @@ public class InboundDataService : IInboundDataService
|
||||
|
||||
if (jp.First is JArray array)
|
||||
detailsArray = array;
|
||||
else if ((jp.First is JValue value) && (value.Value == null))
|
||||
else if ((jp.First is JValue value) && (value.Value is null))
|
||||
detailsArray = null;
|
||||
else
|
||||
errors.Add("Invalid details field");
|
||||
@ -169,7 +169,7 @@ public class InboundDataService : IInboundDataService
|
||||
}
|
||||
|
||||
// if a Details container if found, process it by recursion
|
||||
if (detailsArray != null)
|
||||
if (detailsArray is not null)
|
||||
{
|
||||
int i = 1;
|
||||
foreach (JToken detail in detailsArray)
|
||||
@ -189,7 +189,7 @@ public class InboundDataService : IInboundDataService
|
||||
{
|
||||
// get the json data for this container field, ex: Points
|
||||
JProperty contJP = jsonbody.Children<JProperty>().Where(jp => string.Equals(jp.Name, containerField, StringComparison.OrdinalIgnoreCase)).SingleOrDefault();
|
||||
if ((contJP != null) && (contJP.Value is JArray array))
|
||||
if ((contJP is not null) && (contJP.Value is JArray array))
|
||||
{
|
||||
JArray contJPArray = array;
|
||||
|
||||
|
Reference in New Issue
Block a user