Moved System.IO references from DMO classes to Static Helpers

Removed nugetSource from pipeline
Removed more comments
Created Static Classes for most DMO / Controller Classes
Push ConfigurationManager.AppSettings to controller
Align Tests with other Projects
This commit is contained in:
2024-12-11 09:29:01 -07:00
parent b1c6903c1c
commit b99b721458
86 changed files with 2961 additions and 4432 deletions

View File

@ -1,17 +1,8 @@
using Fab2ApprovalSystem.DMO;
using Fab2ApprovalSystem.Misc;
using Fab2ApprovalSystem.Models;
using Fab2ApprovalSystem.ViewModels;
using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using System;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
@ -19,6 +10,14 @@ using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using Fab2ApprovalSystem.DMO;
using Fab2ApprovalSystem.Misc;
using Fab2ApprovalSystem.Models;
using Fab2ApprovalSystem.ViewModels;
using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
namespace Fab2ApprovalSystem.Controllers;
[Authorize]
@ -26,29 +25,21 @@ namespace Fab2ApprovalSystem.Controllers;
[SessionExpireFilter]
public class MRBController : Controller {
MRB_DMO mrbDMO;
MRB_DMO mrbDMO = new MRB_DMO(GlobalVars.AppSettings);
WorkflowDMO wfDMO = new WorkflowDMO();
CredentialsStorage credentialsStorage = new CredentialsStorage();
private readonly AppSettings _AppSettings;
private readonly AppSettings _AppSettings = GlobalVars.AppSettings;
public MRBController(AppSettings appSettings) {
_AppSettings = appSettings;
mrbDMO = new MRB_DMO(appSettings);
}
//
// GET: /MRB/
public ActionResult Index() {
return View();
}
//
// GET: /MRB/Details/5
public ActionResult Details(int id) {
return View();
}
//
// GET: /MRB/Create
public ActionResult Create() {
MRB mrb = new MRB();
@ -60,15 +51,6 @@ public class MRBController : Controller {
try {
PopulateCloseToQDB();
mrbDMO.SubmitDocument(mrb.MRBNumber, (int)Session[GlobalVars.SESSION_USERID]);
//if (appoverCount > 0)
// NotifyApprovers(mrb.MRBNumber, (byte)GlobalVars.WorkFLowStepNumber.Step1);
//if (Request.IsAjaxRequest())
//{
// return Content("Redirect");
//}
//else
// return Content("Invalid");
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "Issue=" + mrb.MRBNumber.ToString() + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
Functions.WriteEvent(_AppSettings, @User.Identity.Name + "\r\n SubmitDocument - MRB\r\n" + e.Message.ToString(), System.Diagnostics.EventLogEntryType.Error);
@ -79,7 +61,6 @@ public class MRBController : Controller {
return RedirectToAction("Edit", new { IssueID = mrb.MRBNumber });
}
//
// POST: /MRB/Create
[HttpPost]
public ActionResult Create(FormCollection collection) {
@ -92,7 +73,6 @@ public class MRBController : Controller {
}
}
//
// GET: /MRB/Edit/5
public ActionResult Edit(int issueID) {
string jwt = Session["JWT"].ToString();
@ -106,7 +86,6 @@ public class MRBController : Controller {
return Redirect(mrbUrl);
}
//
// POST: /MRB/Edit/5
[HttpPost]
public void Edit(MRB mrb) {
@ -132,13 +111,11 @@ public class MRBController : Controller {
return Redirect(mrbUrl);
}
//
// GET: /MRB/Delete/5
public ActionResult Delete(int id) {
return View();
}
//
// POST: /MRB/Delete/5
[HttpPost]
public ActionResult Delete(int id, FormCollection collection) {
@ -152,7 +129,6 @@ public class MRBController : Controller {
}
public JsonResult SearchLots(string searchText, string searchBy) {
//IEnumerable<Lot> lotlist = MiscDMO.SearchLots(searchText, searchBy);
List<String> lotlist = MiscDMO.SearchLots(searchText, searchBy).Select(x => x.LotNumber).ToList<String>();
return Json(lotlist, JsonRequestBehavior.AllowGet);
}
@ -169,46 +145,8 @@ public class MRBController : Controller {
/// <summary>
/// Updates the lot tables
/// </summary>
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateMRBLot([DataSourceRequest] DataSourceRequest request, Lot lot) {
//try
//{
// // RJK
// //routine to cascade the "dispo type" to all the child lots in SPN
// MRB mrbInfo = mrbDMO.GetToolIssueStartEndDateData(lot.MRBNumber);
// if (!mrbInfo.ToolCSV.ToUpper().Equals("NA"))
// {
// bool existingLotUpdated;
// Lot l = new Lot();
// l.LotNumber = lot.LotNumber;
// if (lot.DispoType.ToString().Trim().Length == 1)
// {
// l.DispoType = lot.DispoType;
// }
// l.MRBNumber = lot.MRBNumber;
// // check if the lot was sent to SPN
// bool lotSentToSPN = mrbDMO.IsLotSentToSPN(l.LotNumber, l.MRBNumber);
// //only get the child lots if it has been sent to SPN to set the MRB Flag
// if (lotSentToSPN)
// {
// if (!mrbDMO.GetChildLotsFromSPNForDispoTypeUpdate(l.MRBNumber, l.LotNumber, mrbInfo.ToolCSV, mrbInfo.IssueStartDate, mrbInfo.IssueEndDate, lot.DispoType))
// {
// //warnings.AppendFormat("Lot number {0} is not affected by these tools and issue start/end time.\n", l.LotNumber);
// }
// }
// }
//}
//catch(Exception e)
//{
// // ignore the error
// string s = e.InnerException.ToString();
//}
if (lot != null && ModelState.IsValid) {
mrbDMO.UpdateMRBLot(lot);
}
@ -219,7 +157,6 @@ public class MRBController : Controller {
/// <summary>
/// Deletes record from the lot table
/// </summary>
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult DeleteMRBLot([DataSourceRequest] DataSourceRequest request, Lot lot) {
try {
@ -271,17 +208,7 @@ public class MRBController : Controller {
l.LotNumber = lotNumber;
l.MRBNumber = mrbNumber;
mrbDMO.InsertLot(l, true, out existingRowUpdated);
//if (!existingRowUpdated)
//{
// if (!mrbDMO.InsertLotSplitsAffectedByIncident(mrbNumber, l.LotNumber))
// {
// warnings.AppendFormat("Lot number {0} is not affected by these tools and issue start/end time.\n", l.LotNumber);
// }
//}
}
//warnings.Append("No tool info, split lots will NOT be automatically searched and uploaded \n please make sure to include all the child lots in the MRB");
}
return Content(warnings.ToString());
@ -317,9 +244,9 @@ public class MRBController : Controller {
mrbDMO.DeleteMRBAttachment(attachmentID);
if (!String.IsNullOrWhiteSpace(fileName)) {
var physicalPath = Path.Combine(_AppSettings.AttachmentFolder + "MRB", fileName);
var physicalPath = System.IO.Path.Combine(_AppSettings.AttachmentFolder + "MRB", fileName);
FileInfo f = new FileInfo(physicalPath);
System.IO.FileInfo f = new System.IO.FileInfo(physicalPath);
if (f.Exists)
f.Delete();
@ -340,12 +267,9 @@ public class MRBController : Controller {
if (files != null) {
int userId = (int)Session[GlobalVars.SESSION_USERID];
foreach (var file in files) {
mrbDMO.AttachSave(mrbNumber, userId, file.FileName, file.InputStream);
MRBHelper.AttachSave(_AppSettings, mrbDMO, mrbNumber, userId, file.FileName, file.InputStream);
}
}
//var model = mrbDMO.GetMRBAttachments(mrbNumber);
return Json(new { errors = errorList });
}
@ -357,10 +281,8 @@ public class MRBController : Controller {
try {
string userIdentityName = @User.Identity.Name;
var dispos = mrbDMO.GetDispositions(mrbNumber);
string lotTempPipeLine = ConfigurationManager.AppSettings["LotTempPipeLine"].ToString();
foreach (var file in Lotfile) {
physicalPath = mrbDMO.ExcelLotOpen(mrbNumber, warnings, dispos, userIdentityName, lotTempPipeLine, file.FileName, file.InputStream);
physicalPath = MRBHelper.ExcelLotOpen(mrbDMO, mrbNumber, warnings, dispos, userIdentityName, _AppSettings.LotTempPipeLine, file.FileName, file.InputStream);
}
return Content(warnings.ToString());
@ -375,7 +297,7 @@ public class MRBController : Controller {
Functions.WriteEvent(_AppSettings, @User.Identity.Name + "\r\n MRB Excel\r\n" + detailedException, System.Diagnostics.EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { IssueID = mrbNumber, UserID = @User.Identity.Name, DocumentType = "Lot Disposition", OperationType = "Error", Comments = exceptionString });
FileInfo f = new FileInfo(physicalPath);
System.IO.FileInfo f = new System.IO.FileInfo(physicalPath);
if (f.Exists)
f.Delete();
@ -385,16 +307,15 @@ public class MRBController : Controller {
}
public ActionResult ImportAddQDBFlag(IEnumerable<HttpPostedFileBase> AddQDBFlag, string operation) {
//string path = Server.MapPath("/FTPBatch/" + ConfigurationManager.AppSettings["FTPSPNBatchFileName"]);
var physicalPath = "";
try {
string message;
string c = Server.MapPath("/FTPBatch/");
string userIdentityName = @User.Identity.Name;
string b = Server.MapPath("/FTPBatch/" + ConfigurationManager.AppSettings["FTPSPNBatchFileName"]);
string a = Server.MapPath("/FTPBatch/" + ConfigurationManager.AppSettings["FTPSPNBatchFileName_Test"]);
string b = Server.MapPath("/FTPBatch/" + _AppSettings.FTPSPNBatchFileName);
string a = Server.MapPath("/FTPBatch/" + _AppSettings.FTPSPNBatchFileName_Test);
foreach (var file in AddQDBFlag) {
message = mrbDMO.ImportAddQDBFlag(operation, out physicalPath, userIdentityName, a, b, c, file.FileName, file.InputStream);
message = MRBHelper.ImportAddQDBFlag(_AppSettings, mrbDMO, operation, out physicalPath, userIdentityName, a, b, c, file.FileName, file.InputStream);
if (string.IsNullOrEmpty(message))
continue;
return Content(message);
@ -402,7 +323,7 @@ public class MRBController : Controller {
return Content("");
} catch {
FileInfo f = new FileInfo(physicalPath);
System.IO.FileInfo f = new System.IO.FileInfo(physicalPath);
if (f.Exists)
f.Delete();
@ -416,10 +337,10 @@ public class MRBController : Controller {
string message;
string c = Server.MapPath("/FTPBatch/");
string userIdentityName = @User.Identity.Name;
string b = Server.MapPath("/FTPBatch/" + ConfigurationManager.AppSettings["FTPSPNBatchFileName"]);
string a = Server.MapPath("/FTPBatch/" + ConfigurationManager.AppSettings["FTPSPNBatchFileName_Test"]);
string b = Server.MapPath("/FTPBatch/" + _AppSettings.FTPSPNBatchFileName);
string a = Server.MapPath("/FTPBatch/" + _AppSettings.FTPSPNBatchFileName_Test);
foreach (var file in RemoveQDBFlag) {
message = mrbDMO.ImportRemoveQDBFlag(operation, out physicalPath, userIdentityName, a, b, c, file.FileName, file.InputStream);
message = MRBHelper.ImportRemoveQDBFlag(_AppSettings, mrbDMO, operation, out physicalPath, userIdentityName, a, b, c, file.FileName, file.InputStream);
if (string.IsNullOrEmpty(message))
continue;
return Content(message);
@ -427,7 +348,7 @@ public class MRBController : Controller {
return Content("");
} catch {
FileInfo f = new FileInfo(physicalPath);
System.IO.FileInfo f = new System.IO.FileInfo(physicalPath);
if (f.Exists)
f.Delete();
@ -503,38 +424,13 @@ public class MRBController : Controller {
List<CloseToQDBOptionViewModel> options = new List<CloseToQDBOptionViewModel>();
options.Add(new CloseToQDBOptionViewModel { CloseToQDBOptionID = 0, CloseToQDBOption = "No" });
options.Add(new CloseToQDBOptionViewModel { CloseToQDBOptionID = 1, CloseToQDBOption = "Yes" });
//options.Add(new CloseToQDBOptionViewModel{CloseToQDBOption= "No"});
//options.Add(new CloseToQDBOptionViewModel {CloseToQDBOption = "Yes" });
ViewData["CloseToQDBOptions"] = options;
}
public void NotifyApprovers(int mrbNumber, byte currentStep) {
string emailSentList = "";
List<string> emailIst = MiscDMO.GetApproverEmailListByDocument(mrbNumber, currentStep, (int)GlobalVars.DocumentType.MRB).Distinct().ToList();
string emailTemplate = "MRBAssigned.txt";
string userEmail = string.Empty;
string subject = "MRB Assignment";
string senderName = "MRB";
foreach (string email in emailIst) {
subject = "MRB Assignment";
EmailNotification en = new EmailNotification(_AppSettings, subject, ConfigurationManager.AppSettings["EmailTemplatesPath"]);
string[] emailparams = new string[3];
emailparams[0] = mrbNumber.ToString();
emailparams[1] = mrbNumber.ToString();
emailparams[2] = GlobalVars.hostURL;
userEmail = email;
//#if(DEBUG)
// userEmail = "rkotian1@irf.com";
//#endif
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
emailSentList += email + ",";
}
string emailSentList = MRBHelper.NotifyApprovers(_AppSettings, mrbNumber, emailIst);
try {
EventLogDMO.Add(new WinEventLog() { IssueID = mrbNumber, UserID = @User.Identity.Name, DocumentType = "MRB", OperationType = "Email", Comments = "Approvers for Step " + currentStep.ToString() + ":" + emailSentList });
} catch { }
@ -575,15 +471,6 @@ public class MRBController : Controller {
int waferCount = 0;
int dieCount = 0;
mrbDMO.GetLotWaferDieCount(mrbNumber, out lotCount, out waferCount, out dieCount);
//dynamic data = new ExpandoObject();
//data.LotCount = lotCount;
//data.WaferCount = waferCount;
//data.DieCount = dieCount;
//string json = Newtonsoft.Json.JsonConvert.SerializeObject(data);
//return Json(json, JsonRequestBehavior.AllowGet);
return Json(lotCount.ToString() + "~" + waferCount.ToString() + "~" + dieCount, JsonRequestBehavior.AllowGet);
}
@ -601,7 +488,7 @@ public class MRBController : Controller {
var mrbLotInfo = mrbDMO.GetLotsToFindNewChildLots(mrbNumber);
foreach (Lot lot in mrbLotInfo) {
//routine to cascade the "dispo type" to all the child lots in SPN (Lot that are not present in FAb App Sys,)
// routine to cascade the "dispo type" to all the child lots in SPN (Lot that are not present in FAb App Sys,)
mrbDMO.ChildLotsUpdateInSPNWithNewDispoType(lot, mrbInfo);
}
@ -614,11 +501,10 @@ public class MRBController : Controller {
try {
string c = Server.MapPath("/FTPBatch/");
string userIdentityName = @User.Identity.Name;
string b = Server.MapPath("/FTPBatch/" + ConfigurationManager.AppSettings["FTPSPNBatchFileName"]);
string a = Server.MapPath("/FTPBatch/" + ConfigurationManager.AppSettings["FTPSPNBatchFileName_Test"]);
string b = Server.MapPath("/FTPBatch/" + _AppSettings.FTPSPNBatchFileName);
string a = Server.MapPath("/FTPBatch/" + _AppSettings.FTPSPNBatchFileName_Test);
IEnumerable<string> data = mrbDMO.GetMRBHoldLots(mrbNumber);
foreach (string tempData in data) {
//output = new StringBuilder();
if (tempData != null)
output.Append(tempData.Trim() + Environment.NewLine);
@ -630,9 +516,7 @@ public class MRBController : Controller {
string newsourceFileName = mrbNumber.ToString() + "_S" + dt.Day.ToString("00") + dt.Month.ToString("00") + dt.Year.ToString("00") + dt.Hour.ToString("00") + dt.Minute.ToString("00") + dt.Second.ToString("00") + ".mrb";
string newDestFileName = "S" + dt.Hour.ToString("00") + dt.Minute.ToString("00") + dt.Second.ToString("00");
//string outputFile = @"C:\Websites\SPNLotHoldFlag\" + newsourceFileName;
string ftpLogDirectory = ConfigurationManager.AppSettings["SPNMRBHoldFlagFTPLogDirectory"].ToString();
string outputFile = ConfigurationManager.AppSettings["SPNMRBHoldFlagDirectory"].ToString() + newsourceFileName;
string outputFile = _AppSettings.SPNMRBHoldFlagDirectory + newsourceFileName;
System.IO.File.WriteAllText(outputFile, output.ToString());
@ -640,26 +524,17 @@ public class MRBController : Controller {
Thread.Sleep(1000);
#endif
try {
//#if (!DEBUG)
//FTPWrapper spfSPN = new FTPWrapper(outputFile, newDestFileName);
//spfSPN.FTPToSPN();
if (mrbDMO.BatchFTP(outputFile, newDestFileName, ftpLogDirectory, userIdentityName, a, b, c)) {
//TODO
if (MRBHelper.BatchFTP(_AppSettings, outputFile, newDestFileName, _AppSettings.SPNMRBHoldFlagFTPLogDirectory, userIdentityName, a, b, c)) {
// TODO
mrbDMO.LogHoldFlagSentToSPNHistory(mrbNumber);
}
//#endif
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "MRB =" + mrbNumber.ToString() + " FTPToSPN(): SendMRBHoldFlagToSPN(mrbNumber) - FTP Upload Error " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
EventLogDMO.Add(new WinEventLog() { IssueID = -1, UserID = @User.Identity.Name, DocumentType = "MRB", OperationType = "Error", Comments = exceptionString });
return Json(new { Error = true, Message = e.Message }, JsonRequestBehavior.AllowGet);
//return false;
}
}
//return true;
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "MRB =" + mrbNumber.ToString() + " SendMRBHoldFlagToSPN(mrbNumber) " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
Functions.WriteEvent(_AppSettings, @User.Identity.Name + "\r\n Approve\r\n" + e.Message.ToString(), System.Diagnostics.EventLogEntryType.Error);
@ -678,18 +553,14 @@ public class MRBController : Controller {
}
public bool BatchFTP_Old(string sourceFile, string destFile) {
FileInfo sourcefile = new FileInfo(sourceFile);
//FileInfo sourcefile = new FileInfo(@"C:\Websites\ECNViewerAckResultToSPN\S15122017102017.ecn");
System.IO.FileInfo sourcefile = new System.IO.FileInfo(sourceFile);
try {
//Functions.WriteEvent("HR Emp", "SPNData - Start Send(): FTPing " + sourceFile + " to SPN server.", System.Diagnostics.EventLogEntryType.Information);
ProcessStartInfo psiFab1 = new ProcessStartInfo();
//psiFab1.FileName = ConfigurationManager.AppSettings["FTPSPNBatchFileName"];
if (GlobalVars.DBConnection.ToUpper() == "TEST" || GlobalVars.DBConnection.ToUpper() == "QUALITY") {
psiFab1.FileName = Server.MapPath("/FTPBatch/" + ConfigurationManager.AppSettings["FTPSPNBatchFileName_Test"]);
psiFab1.FileName = Server.MapPath("/FTPBatch/" + _AppSettings.FTPSPNBatchFileName_Test);
} else {
psiFab1.FileName = Server.MapPath("/FTPBatch/" + ConfigurationManager.AppSettings["FTPSPNBatchFileName"]);
psiFab1.FileName = Server.MapPath("/FTPBatch/" + _AppSettings.FTPSPNBatchFileName);
}
psiFab1.Arguments = sourcefile.FullName + " " + destFile;
@ -697,8 +568,6 @@ public class MRBController : Controller {
Process procFab1 = new Process();
procFab1.StartInfo = psiFab1;
procFab1.Start();
//Functions.WriteEvent("HR Emp", "SPNData - Finish FTPing to SPN server.", System.Diagnostics.EventLogEntryType.Information);
return true;
} catch (Exception e) {
Functions.WriteEvent(_AppSettings, @User.Identity.Name + "\r\n Approve\r\n" + e.Message.ToString(), System.Diagnostics.EventLogEntryType.Error);
@ -707,8 +576,6 @@ public class MRBController : Controller {
}
public FileResult DownloadFile(string attachmentID) {
//fileName = "ECNForm_71132.pdf";
var attachment = mrbDMO.GetMRBAttachment(Convert.ToInt32(attachmentID));
if (attachment == null)
@ -718,7 +585,7 @@ public class MRBController : Controller {
if (String.IsNullOrEmpty(fileName))
fileName = attachment.FileName;
var sDocument = Path.Combine(_AppSettings.AttachmentFolder + "MRB", fileName);
var sDocument = System.IO.Path.Combine(_AppSettings.AttachmentFolder + "MRB", fileName);
var FDir_AppData = _AppSettings.AttachmentFolder;
if (!sDocument.StartsWith(FDir_AppData)) {
// Ensure that we are serving file only inside the Fab2ApprovalAttachments folder
@ -728,7 +595,6 @@ public class MRBController : Controller {
if (!System.IO.File.Exists(sDocument)) {
return null;
//throw new Exception("File not found");
}
return File(sDocument, System.Net.Mime.MediaTypeNames.Application.Octet, attachment.FileName);