Tasks 184281, 184799, 184800, 184801 and 184802

Align .editorconfig files

Move Controller logic to DMO classes

GlobalVars.AppSettings = Models.AppSettings.GetFromConfigurationManager();

Question EditorConfig
Project level editorconfig
Format White Spaces
AppSetting when EnvironmentVariable not set
Corrective Actions Tests
Schedule Actions Tests
DMO Tests
Controller Tests

Get ready to use VSCode IDE
This commit is contained in:
2024-12-04 11:58:13 -07:00
parent 538b1f817e
commit b1c6903c1c
150 changed files with 29146 additions and 33456 deletions

View File

@ -1,261 +1,199 @@
#pragma warning disable CS8019
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.Web;
#if !NET8
using System.Web.Security;
#endif
using System.IO;
using System.Net.Mail;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
namespace Fab2ApprovalSystem.Misc {
public static class Functions {
/// <summary>
/// Writes to the Application Event Log and sends an email notification if appropriate
/// </summary>
/// <param name="logtext"></param>
/// <param name="eventType"></param>
public static void WriteEvent(string logtext, System.Diagnostics.EventLogEntryType eventType) {
//#if(!DEBUG)
EmailNotification en = new EmailNotification();
EventLog ev = new EventLog("Application");
ev.Source = "Fab Approval System";
#pragma warning restore CS8019
try {
//Write to the Event Log
ev.WriteEntry(logtext, eventType);
using Fab2ApprovalSystem.Models;
////Send an email notification if appropriate
////Don't attempt to send an email if the error is pertaining to an email problem
if (!logtext.Contains("SendEmailNotification()")) {
//Only send email notifications for Error and Warning level events
if (eventType == System.Diagnostics.EventLogEntryType.Error)
en.SendNotificationEmailToAdmin(ev.Source + " - Error Notification", logtext, MailPriority.High);
//else if (eventType == System.Diagnostics.EventLogEntryType.Warning)
// SendEmailNotification(ErrorRecipient(), ev.Source + " Warning Event Logged", logtext, NORMAL_PRI);
}
} catch {
//throw;
} finally {
ev = null;
namespace Fab2ApprovalSystem.Misc;
public static class Functions {
/// <summary>
/// Writes to the Application Event Log and sends an email notification if appropriate
/// </summary>
public static void WriteEvent(AppSettings? appSettings, string logtext, EventLogEntryType eventType) {
//#if(!DEBUG)
#if !NET8
EmailNotification? en = appSettings is null ? null : new EmailNotification(appSettings);
#endif
EventLog ev = new("Application");
ev.Source = "Fab Approval System";
try {
//Write to the Event Log
ev.WriteEntry(logtext, eventType);
////Send an email notification if appropriate
////Don't attempt to send an email if the error is pertaining to an email problem
if (!logtext.Contains("SendEmailNotification()")) {
//Only send email notifications for Error and Warning level events
#if !NET8
if (appSettings is not null && eventType == System.Diagnostics.EventLogEntryType.Error)
en.SendNotificationEmailToAdmin(ev.Source + " - Error Notification", logtext, MailPriority.High);
#endif
//else if (eventType == System.Diagnostics.EventLogEntryType.Warning)
// SendEmailNotification(ErrorRecipient(), ev.Source + " Warning Event Logged", logtext, NORMAL_PRI);
}
}
/// <summary>
/// Returns the FTP Server Name
/// </summary>
/// <returns></returns>
public static string FTPServer() {
ConfigurationManager.RefreshSection("appSettings");
return ConfigurationManager.AppSettings["FTP Server"];
}
/// <summary>
/// Returns the FTP User Name
/// </summary>
/// <returns></returns>
public static string FTPUser() {
ConfigurationManager.RefreshSection("appSettings");
return ConfigurationManager.AppSettings["FTP User"];
}
/// <summary>
/// Returns the FTP Password
/// </summary>
/// <returns></returns>
public static string FTPPassword() {
ConfigurationManager.RefreshSection("appSettings");
return ConfigurationManager.AppSettings["FTP Password"];
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public static string GetAttachmentFolder() {
ConfigurationManager.RefreshSection("appSettings");
return ConfigurationManager.AppSettings["AttachmentFolder"];
}
/// <summary>
///
/// </summary>
/// <param name="oldECNNumber"></param>
/// <param name="newECNNumber"></param>
public static void CopyAttachments(int oldECNNumber, int newECNNumber) {
// The Name of the Upload component is "files"
string oldFolderPath = Functions.GetAttachmentFolder() + "ECN\\" + oldECNNumber.ToString();
string newFolderPath = Functions.GetAttachmentFolder() + "ECN\\" + newECNNumber.ToString();
DirectoryInfo newdi = new DirectoryInfo(newFolderPath);
if (!newdi.Exists)
newdi.Create();
FileInfo[] existingFiles = new DirectoryInfo(oldFolderPath).GetFiles();
foreach (FileInfo file in existingFiles) {
if (!file.Name.Contains("ECNApprovalLog_" + oldECNNumber.ToString()) && !file.Name.Contains("ECNForm_" + oldECNNumber.ToString()))
//var fileName = Path.GetFileName(file.FullName);
file.CopyTo(Path.Combine(newFolderPath, file.Name));
}
}
/// <summary>
///
/// </summary>
/// <param name="userID"></param>
/// <param name="pwd"></param>
/// <returns></returns>
public static bool NA_ADAuthenticate(string userID, string pwd) {
string naContainer = ConfigurationManager.AppSettings["NAContainer"];
string naDomain = ConfigurationManager.AppSettings["NADomain"];
try {
PrincipalContext contextUser = new PrincipalContext(ContextType.Domain,
naDomain,
naContainer,
ContextOptions.Negotiate, userID, pwd);
UserPrincipal up = UserPrincipal.FindByIdentity(contextUser, userID);
if (null == up)
return false;
else
return true;
} catch {
return false;
}
}
/// <summary>
///
/// </summary>
/// <param name="userID"></param>
/// <param name="pwd"></param>
/// <returns></returns>
public static bool IFX_ADAuthenticate(string userID, string pwd) {
string container = ConfigurationManager.AppSettings["IFXContainer"];
string domain = ConfigurationManager.AppSettings["IFXDomain"];
try {
PrincipalContext contextUser = new PrincipalContext(ContextType.Domain,
domain,
container,
ContextOptions.Negotiate, userID, pwd);
UserPrincipal up = UserPrincipal.FindByIdentity(contextUser, userID);
if (null == up)
return false;
else
return true;
} catch {
return false;
}
}
public static string FTPSPNBatch() {
ConfigurationManager.RefreshSection("appSettings");
return ConfigurationManager.AppSettings["FTPSPNBatchFileName"];
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public static string FTPSPNBatch_Test() {
ConfigurationManager.RefreshSection("appSettings");
return ConfigurationManager.AppSettings["FTPSPNBatchFileName_Test"];
}
/// <summary>
///
/// </summary>
/// <param name="casection"></param>
/// <returns></returns>
public static string CASectionMapper(GlobalVars.CASection casection) {
switch (casection) {
case GlobalVars.CASection.Main:
return "Main";
case GlobalVars.CASection.D1:
return "D1";
case GlobalVars.CASection.D2:
return "D2";
case GlobalVars.CASection.D3:
return "D3";
case GlobalVars.CASection.D4:
return "D4";
case GlobalVars.CASection.D5:
return "D5";
case GlobalVars.CASection.D6:
return "D6";
case GlobalVars.CASection.D7:
return "D7";
case GlobalVars.CASection.D8:
return "D8";
case GlobalVars.CASection.CF: // CA Findings
return "CF";
}
return "";
}
public static string DocumentTypeMapper(GlobalVars.DocumentType docType) {
switch (docType) {
case GlobalVars.DocumentType.Audit:
return "Audit";
case GlobalVars.DocumentType.ChangeControl:
return "ChangeControl";
case GlobalVars.DocumentType.CorrectiveAction:
return "CorrectiveAction";
case GlobalVars.DocumentType.ECN:
return "ECN";
case GlobalVars.DocumentType.EECN:
return "EECN";
case GlobalVars.DocumentType.LotDisposition:
return "LotDisposition";
case GlobalVars.DocumentType.MRB:
return "MRB";
case GlobalVars.DocumentType.TECNCancelledExpired:
return "TECNCancelledExpired";
}
return "";
}
/// <summary>
/// Converts the CA No to the C00000 format
/// </summary>
/// <param name="caNo"></param>
/// <returns></returns>
public static string ReturnCANoStringFormat(int caNo) {
string caNoString = "";
if (caNo == 0)
return "";
caNoString = "C" + caNo.ToString().PadLeft(5, '0');
return caNoString;
}
public static string ReturnAuditNoStringFormat(int auditNo) {
string auditNoString = "";
if (auditNo == 0)
return "";
auditNoString = "A" + auditNo.ToString().PadLeft(5, '0');
return auditNoString;
}
public static string ReturnPartsRequestNoStringFormat(int PRNumber) {
if (PRNumber == 0)
return "";
return String.Format("PR{0:000000}", PRNumber);
} catch {
//throw;
} finally {
ev = null;
}
}
}
public static void CopyAttachments(AppSettings appSettings, int oldECNNumber, int newECNNumber) {
// The Name of the Upload component is "files"
string oldFolderPath = appSettings.AttachmentFolder + "ECN\\" + oldECNNumber.ToString();
string newFolderPath = appSettings.AttachmentFolder + "ECN\\" + newECNNumber.ToString();
DirectoryInfo newdi = new(newFolderPath);
if (!newdi.Exists)
newdi.Create();
FileInfo[] existingFiles = new DirectoryInfo(oldFolderPath).GetFiles();
foreach (FileInfo file in existingFiles) {
if (!file.Name.Contains("ECNApprovalLog_" + oldECNNumber.ToString()) && !file.Name.Contains("ECNForm_" + oldECNNumber.ToString()))
//var fileName = Path.GetFileName(file.FullName);
file.CopyTo(Path.Combine(newFolderPath, file.Name));
}
}
public static bool NA_ADAuthenticate(AppSettings appSettings, string userID, string pwd) {
string naContainer = appSettings.NAContainer;
string naDomain = appSettings.NADomain;
try {
PrincipalContext contextUser = new(ContextType.Domain,
naDomain,
naContainer,
ContextOptions.Negotiate, userID, pwd);
UserPrincipal up = UserPrincipal.FindByIdentity(contextUser, userID);
if (null == up)
return false;
else
return true;
} catch {
return false;
}
}
public static bool IFX_ADAuthenticate(AppSettings appSettings, string userID, string pwd) {
string container = appSettings.IFXContainer;
string domain = appSettings.IFXDomain;
try {
PrincipalContext contextUser = new(ContextType.Domain,
domain,
container,
ContextOptions.Negotiate, userID, pwd);
UserPrincipal up = UserPrincipal.FindByIdentity(contextUser, userID);
if (null == up)
return false;
else
return true;
} catch {
return false;
}
}
public static string CASectionMapper(GlobalVars.CASection casection) {
switch (casection) {
case GlobalVars.CASection.Main:
return "Main";
case GlobalVars.CASection.D1:
return "D1";
case GlobalVars.CASection.D2:
return "D2";
case GlobalVars.CASection.D3:
return "D3";
case GlobalVars.CASection.D4:
return "D4";
case GlobalVars.CASection.D5:
return "D5";
case GlobalVars.CASection.D6:
return "D6";
case GlobalVars.CASection.D7:
return "D7";
case GlobalVars.CASection.D8:
return "D8";
case GlobalVars.CASection.CF: // CA Findings
return "CF";
}
return "";
}
public static string DocumentTypeMapper(GlobalVars.DocumentType docType) {
switch (docType) {
case GlobalVars.DocumentType.Audit:
return "Audit";
case GlobalVars.DocumentType.ChangeControl:
return "ChangeControl";
case GlobalVars.DocumentType.CorrectiveAction:
return "CorrectiveAction";
case GlobalVars.DocumentType.ECN:
return "ECN";
case GlobalVars.DocumentType.EECN:
return "EECN";
case GlobalVars.DocumentType.LotDisposition:
return "LotDisposition";
case GlobalVars.DocumentType.MRB:
return "MRB";
case GlobalVars.DocumentType.TECNCancelledExpired:
return "TECNCancelledExpired";
}
return "";
}
/// <summary>
/// Converts the CA No to the C00000 format
/// </summary>
public static string ReturnCANoStringFormat(int caNo) {
string caNoString = "";
if (caNo == 0)
return "";
caNoString = "C" + caNo.ToString().PadLeft(5, '0');
return caNoString;
}
public static string ReturnAuditNoStringFormat(int auditNo) {
string auditNoString = "";
if (auditNo == 0)
return "";
auditNoString = "A" + auditNo.ToString().PadLeft(5, '0');
return auditNoString;
}
public static string ReturnPartsRequestNoStringFormat(int PRNumber) {
if (PRNumber == 0)
return "";
return string.Format("PR{0:000000}", PRNumber);
}
}