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

@ -1,10 +1,10 @@
using Microsoft.Extensions.Configuration;
using System;
using System;
using System.Globalization;
using System.IO;
namespace OI.Metrology.Archive.Services;
using OI.Metrology.Archive.Models;
using OI.Metrology.Shared.DataModels;
using OI.Metrology.Shared.Repositories;
using OI.Metrology.Shared.Services;
@ -12,19 +12,17 @@ using System.Data.SqlClient;
public class AttachmentsService : IAttachmentsService
{
private IConfiguration Config { get; }
protected IMetrologyRepo _Repo;
private readonly IMetrologyRepo _Repo;
private readonly AppSettings _AppSettings;
public AttachmentsService(IConfiguration config, IMetrologyRepo repo)
public AttachmentsService(AppSettings appSettings, IMetrologyRepo repo)
{
Config = config;
_Repo = repo;
_AppSettings = appSettings;
}
protected Stream GetAttachmentStream(String tableName, Guid attachmentId, string filename)
protected Stream GetAttachmentStream(string tableName, Guid attachmentId, string filename)
{
string attachmentsRootPath = Config[Constants.AttachmentPathKey];
if (attachmentId.Equals(Guid.Empty))
throw new Exception("No attachments found");
@ -36,12 +34,12 @@ public class AttachmentsService : IAttachmentsService
string workWeek = "WW" + weekNum.ToString("00");
string dateDir = year + @"\" + workWeek;
string fullPath = Path.Combine(attachmentsRootPath, tableName + "_", dateDir, attachmentId.ToString(), filename);
string fullPath = Path.Combine(_AppSettings.AttachmentPath, tableName + "_", dateDir, attachmentId.ToString(), filename);
//Check to see if file exists in the "New" directory structure, if not change the path back to the old. and check there
// Check to see if file exists in the "New" directory structure, if not change the path back to the old. and check there
if (!File.Exists(fullPath))
{
fullPath = Path.Combine(attachmentsRootPath, tableName, attachmentId.ToString(), filename);
fullPath = Path.Combine(_AppSettings.AttachmentPath, tableName, attachmentId.ToString(), filename);
}
if (!File.Exists(fullPath))
@ -49,40 +47,20 @@ public class AttachmentsService : IAttachmentsService
return new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
}
//protected System.IO.Stream GetAttachmentStream(String tableName, Guid attachmentId, string filename)
//{
// //This part seems to be key
// var attachmentsRootPath = _config[Constants.AttachmentPathKey];
// //if (attachmentId.Equals(Guid.Empty))
// //throw new Exception("No attachments found");
// //string list = Directory.GetDirectories(attachmentsRootPath).Where(s => s.Contains(attachmentId.ToString())).SingleOrDefault();
// //var fullPath = list;
// var fullPath = System.IO.Path.Combine(attachmentsRootPath, tableName, attachmentId.ToString(), filename);
// if (!System.IO.File.Exists(fullPath))
// throw new Exception("File not found " + fullPath);
// return new System.IO.FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
//}
protected Stream GetAttachmentStreamArchive(String tableName, Guid attachmentId, string filename)
protected Stream GetAttachmentStreamArchive(string tableName, Guid attachmentId, string filename)
{
//This part seems to be key
string attachmentsRootPath = Config[Constants.AttachmentPathKey];
if (attachmentId.Equals(Guid.Empty))
throw new Exception("No attachments found");
string fullPath = Path.Combine(attachmentsRootPath, tableName, "2019\\09", attachmentId.ToString(), filename);
string fullPath = Path.Combine(_AppSettings.AttachmentPath, tableName, "2019\\09", attachmentId.ToString(), filename);
if (!File.Exists(fullPath))
throw new Exception("File not found");
return new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
}
public Stream GetAttachmentStreamByTitle(ToolType toolType, bool header, string title, string filename)
{
if (toolType == null)
@ -98,7 +76,6 @@ public class AttachmentsService : IAttachmentsService
using (SqlConnection connection = new(connectionString))
{
SqlCommand command = new(queryString, connection);
//command.Parameters.AddWithValue("@attachmentId", attachmentId);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
try
@ -112,7 +89,6 @@ public class AttachmentsService : IAttachmentsService
}
finally
{
// Always call Close when done reading.
reader.Close();
}
}
@ -121,14 +97,8 @@ public class AttachmentsService : IAttachmentsService
{
_ = "0" + SearchMonth;
}
_ = SearchDate.Year.ToString();
_ = Config[Constants.AttachmentPathKey];
string tableName;
//var attachmentsRootPath = "\\\\messv02ecc1.ec.local\\EC_Metrology_Si\\MetrologyAttachments\\TencorRunData\\2019\\09";
Guid attachmentId;
if (header)
{
@ -140,7 +110,6 @@ public class AttachmentsService : IAttachmentsService
tableName = toolType.DataTableName;
attachmentId = _Repo.GetDataAttachmentIDByTitle(toolType.ID, title);
}
return GetAttachmentStream(tableName, attachmentId, filename);
}
@ -148,66 +117,18 @@ public class AttachmentsService : IAttachmentsService
{
if (toolType == null)
throw new Exception("Invalid tool type");
/*string queryString = "SELECT * FROM " + toolType.DataTableName + " WHERE AttachmentId = @attachmentId";
if (header)
{
queryString = "SELECT * FROM " + toolType.HeaderTableName + " WHERE AttachmentId = '" + attachmentId + "'";
}
DateTime SearchDate = new DateTime();
string connectionString = @"Server=messv01ec.ec.local\PROD1,53959;Database=Metrology_Archive;Integrated Security=True";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(queryString, connection);
command.Parameters.AddWithValue("@attachmentId", attachmentId);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
try
{
while (reader.Read())
{
Console.WriteLine(string.Format("{0}", reader["InsertDate"]));// etc
//string test = string.Format("{0}", reader["InsertDate"]);
SearchDate = Convert.ToDateTime(string.Format("{0}", reader["Date"]));
}
}
finally
{
// Always call Close when done reading.
reader.Close();
}
}
string SearchMonth = SearchDate.Month.ToString();
if (SearchDate.Month < 10)
{
SearchMonth = "0" + SearchMonth;
}
string SearchYear = SearchDate.Year.ToString();*/
//string DateSearchTermin = +""+
_ = Config[Constants.AttachmentPathKey];
string tableName;
if (header)
tableName = toolType.HeaderTableName;
else
tableName = toolType.DataTableName;
//System.IO.Stream test = GetAttachmentStream(tableName, attachmentId, filename, SearchYear);
return GetAttachmentStream(tableName, attachmentId, filename);
//return test;
}
public Stream GetAttachmentStreamByAttachmentIdArchive(ToolType toolType, bool header, Guid attachmentId, string filename)
{
if (toolType == null)
throw new Exception("Invalid tool type");
_ = Config[Constants.AttachmentPathKey];
string tableName;
if (header)
tableName = toolType.HeaderTableName;
else
@ -216,7 +137,7 @@ string SearchYear = SearchDate.Year.ToString();*/
return GetAttachmentStreamArchive(tableName, attachmentId, filename);
}
public void SaveAttachment(ToolType toolType, long headerId, string dataUniqueId, string filename, Microsoft.AspNetCore.Http.IFormFile uploadedFile)
private void SaveAttachment(ToolType toolType, long headerId, string dataUniqueId, string filename, Microsoft.AspNetCore.Http.IFormFile uploadedFile)
{
if (toolType == null)
throw new Exception("Invalid tool type");
@ -235,24 +156,16 @@ string SearchYear = SearchDate.Year.ToString();*/
attachmentId = _Repo.GetDataAttachmentID(toolType.ID, headerId, dataUniqueId);
tableName = toolType.DataTableName;
}
if (Equals(attachmentId, Guid.Empty))
throw new Exception("Invalid attachment ID");
string attachmentsRootPath = Config[Constants.AttachmentPathKey];
string directoryPath = Path.Combine(attachmentsRootPath, tableName, attachmentId.ToString());
string directoryPath = Path.Combine(_AppSettings.AttachmentPath, tableName, attachmentId.ToString());
if (!Directory.Exists(directoryPath))
_ = Directory.CreateDirectory(directoryPath);
string fullPath = Path.Combine(directoryPath, filename);
using (FileStream s = new(fullPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
{
uploadedFile.CopyTo(s);
}
trans.Complete();
}