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

@ -22,6 +22,12 @@ public class EmailNotification {
public EmailNotification(Models.AppSettings appSettings) =>
_AppSettings = appSettings;
public EmailNotification(Models.AppSettings appSettings, string EmailHeaderSubject) {
_AppSettings = appSettings;
_subject = EmailHeaderSubject;
_TemplatesPath = appSettings.EmailTemplatesPath;
}
/// <summary>
/// The Constructor Function
/// </summary>
@ -52,16 +58,15 @@ public class EmailNotification {
protected string ReadEmailFile(string FileName) {
string retVal = null;
try {
//setting the file name path
string path = _TemplatesPath + FileName;
#if !NET8
FileInfo TheFile = new FileInfo(System.Web.HttpContext.Current.Server.MapPath(path));
//check if the file exists in the location.
// check if the file exists in the location.
if (!TheFile.Exists)
throw new Exception("Could Not Find the file : " + FileName + " in the location " + _TemplatesPath); // throw an exception here.
//start reading the file. i have used Encoding 1256 to support arabic text also.
// start reading the file. i have used Encoding 1256 to support arabic text also.
StreamReader sr = new StreamReader(System.Web.HttpContext.Current.Server.MapPath(@path), System.Text.Encoding.GetEncoding(1256));
retVal = sr.ReadToEnd(); // getting the entire text from the file.
sr.Close();
@ -88,21 +93,19 @@ public class EmailNotification {
msg.IsBodyHtml = true;// email body will allow html elements
// setting the Sender Email ID
//msg.From = new MailAddress(SenderEmail, SenderName);
msg.From = new MailAddress("MesaFabApproval@infineon.com", "Mesa Fab Approval");
msg.Sender = new MailAddress("MesaFabApproval@infineon.com", "Mesa Fab Approval");
// adding the Recepient Email ID
msg.To.Add(Recep);
//msg.To.Add("Jonathan.Ouellette@infineon.com");
// add CC email ids if supplied.
if (!string.IsNullOrEmpty(cc))
msg.CC.Add(cc);
//setting email subject and body
// setting email subject and body
msg.Subject = email_title;
msg.Body = email_body;
//create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
// create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
SmtpClient SmtpMail = new("mailrelay-internal.infineon.com");
// sending the message.
@ -130,12 +133,12 @@ public class EmailNotification {
if (!string.IsNullOrEmpty(cc))
msg.CC.Add(cc);
//setting email subject and body
// setting email subject and body
msg.Subject = email_title;
msg.Body = email_body;
msg.Attachments.Add(new Attachment(attachmentPath));
//create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
// create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
SmtpClient SmtpMail = new();
#if(!DEBUG)
// sending the message.
@ -150,7 +153,6 @@ public class EmailNotification {
msg.IsBodyHtml = true;// email body will allow html elements
// setting the Sender Email ID
//msg.From = new MailAddress(SenderEmail, SenderName);
msg.From = new MailAddress("MesaFabApproval@infineon.com", "Mesa Fab Approval");
// adding the Recepient Email ID
foreach (string recepient in RecepientList) {
@ -161,11 +163,11 @@ public class EmailNotification {
if (!string.IsNullOrEmpty(cc))
msg.CC.Add(cc);
//setting email subject and body
// setting email subject and body
msg.Subject = email_title;
msg.Body = email_body;
//create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
// create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
SmtpClient SmtpMail = new();
// sending the message.
@ -196,12 +198,12 @@ public class EmailNotification {
if (!string.IsNullOrEmpty(cc))
msg.CC.Add(cc);
//setting email subject and body
// setting email subject and body
msg.Subject = email_title;
msg.Body = email_body;
msg.Attachments.Add(new Attachment(attachmentPath));
//create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
// create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
SmtpClient SmtpMail = new();
// sending the message.
@ -223,14 +225,14 @@ public class EmailNotification {
if (!string.IsNullOrEmpty(cc))
msg.CC.Add(cc);
//setting email subject and body
// setting email subject and body
msg.Subject = email_title;
msg.Body = email_body;
foreach (string attachment in attachments) {
msg.Attachments.Add(new Attachment(attachment));
}
//create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
// create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
SmtpClient SmtpMail = new();
#if(!DEBUG)
// sending the message.
@ -256,7 +258,7 @@ public class EmailNotification {
if (!string.IsNullOrEmpty(cc))
msg.CC.Add(cc);
//setting email subject and body
// setting email subject and body
msg.Subject = email_title;
msg.Body = email_body;
@ -264,7 +266,7 @@ public class EmailNotification {
msg.Attachments.Add(new Attachment(attachment));
}
//create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
// create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
SmtpClient SmtpMail = new();
// sending the message.
@ -285,16 +287,16 @@ public class EmailNotification {
public string SendNotificationEmail(string EmailTemplateFile, string SenderEmail, string SenderName, string RecepientEmail, string CC, string Subject, params string[] Args) {
string retVal = null;
//reading the file
// reading the file
string FileContents = ReadEmailFile(EmailTemplateFile);
string emailBody = FileContents;
//setting formatting the string
// setting formatting the string
retVal = string.Format(emailBody, Args);
try {
//check if we are in debug mode or not. to send email
// check if we are in debug mode or not. to send email
if (GlobalVars.DBConnection.ToUpper() == "TEST" || GlobalVars.DBConnection.ToUpper() == "QUALITY") {
SendEmail(SenderEmail, SenderName, GetTestRecipientsList(), CC, (!string.IsNullOrEmpty(Subject) ? Subject + " for: " + RecepientEmail : _subject), retVal);
} else {
@ -316,16 +318,16 @@ public class EmailNotification {
public string SendNotificationEmailWithAttachment(string EmailTemplateFile, string SenderEmail, string SenderName, string RecepientEmail, string CC, string Subject, string attachmentPath, params string[] Args) {
string retVal = null;
//reading the file
// reading the file
string FileContents = ReadEmailFile(EmailTemplateFile);
string emailBody = FileContents;
//setting formatting the string
// setting formatting the string
retVal = string.Format(emailBody, Args);
try {
//check if we are in debug mode or not. to send email
// check if we are in debug mode or not. to send email
if (GlobalVars.DBConnection.ToUpper() == "TEST" || GlobalVars.DBConnection.ToUpper() == "QUALITY") {
SendEmailWithAttachment(SenderEmail, SenderName, GetTestRecipientsList(), CC, (!string.IsNullOrEmpty(Subject) ? " TESTING ONLY -IGNORE : " + Subject + RecepientEmail : _subject), retVal, attachmentPath);
} else {
@ -343,16 +345,16 @@ public class EmailNotification {
public string SendNotificationEmailWithAttachment(string EmailTemplateFile, string SenderEmail, string SenderName, List<string> RecepientEmail, string CC, string Subject, string attachmentPath, params string[] Args) {
string retVal = null;
//reading the file
// reading the file
string FileContents = ReadEmailFile(EmailTemplateFile);
string emailBody = FileContents;
//setting formatting the string
// setting formatting the string
retVal = string.Format(emailBody, Args);
try {
//check if we are in debug mode or not. to send email
// check if we are in debug mode or not. to send email
if (GlobalVars.DBConnection.ToUpper() == "TEST" || GlobalVars.DBConnection.ToUpper() == "QUALITY") {
foreach (string email in RecepientEmail) {
Subject += email + ";";
@ -375,16 +377,16 @@ public class EmailNotification {
public string SendNotificationEmailWithAttachments(string EmailTemplateFile, string SenderEmail, string SenderName, string RecepientEmail, string CC, string Subject, List<string> attachments, params string[] Args) {
string retVal = null;
//reading the file
// reading the file
string FileContents = ReadEmailFile(EmailTemplateFile);
string emailBody = FileContents;
//setting formatting the string
// setting formatting the string
retVal = string.Format(emailBody, Args);
try {
//check if we are in debug mode or not. to send email
// check if we are in debug mode or not. to send email
if (GlobalVars.DBConnection.ToUpper() == "TEST" || GlobalVars.DBConnection.ToUpper() == "QUALITY") {
SendEmailWithAttachments(SenderEmail, SenderName, GetTestRecipientsList(), CC, (!string.IsNullOrEmpty(Subject) ? " TESTING ONLY -IGNORE : " + Subject + RecepientEmail : _subject), retVal, attachments);
} else {
@ -402,16 +404,16 @@ public class EmailNotification {
public string SendNotificationEmailWithAttachments(string EmailTemplateFile, string SenderEmail, string SenderName, List<string> RecepientEmail, string CC, string Subject, List<string> attachments, params string[] Args) {
string retVal = null;
//reading the file
// reading the file
string FileContents = ReadEmailFile(EmailTemplateFile);
string emailBody = FileContents;
//setting formatting the string
// setting formatting the string
retVal = string.Format(emailBody, Args);
try {
//check if we are in debug mode or not. to send email
// check if we are in debug mode or not. to send email
if (GlobalVars.DBConnection.ToUpper() == "TEST" || GlobalVars.DBConnection.ToUpper() == "QUALITY") {
foreach (string email in RecepientEmail) {
Subject += email + ";";
@ -434,16 +436,16 @@ public class EmailNotification {
public string SendNotificationEmail(string EmailTemplateFile, string SenderEmail, string SenderName, List<string> RecepientEmail, string CC, string Subject, params string[] Args) {
string retVal = null;
//reading the file
// reading the file
string FileContents = ReadEmailFile(EmailTemplateFile);
string emailBody = FileContents;
//setting formatting the string
// setting formatting the string
retVal = string.Format(emailBody, Args);
try {
//check if we are in debug mode or not. to send email
// check if we are in debug mode or not. to send email
if (GlobalVars.DBConnection.ToUpper() == "TEST" || GlobalVars.DBConnection.ToUpper() == "QUALITY") {
foreach (string email in RecepientEmail) {
Subject += email + ";";
@ -480,9 +482,7 @@ public class EmailNotification {
msg.Subject = subject;
msg.Body = temp;
msg.Priority = importance;
//#if(!DEBUG)
client.Send(msg);
//#endif
} catch (Exception ex) {
throw;
}