Mike Phares 7650bf2869 Removed PdfViewController, HtmlViewRenderer and FakeView to be replaced with ViewEngineResult Render method
Added HttpException class for missing HttpException for net8

Wrapped HttpContext.Session, GetJsonResult, IsAjaxRequest and GetUserIdentityName in controllers for net8

Added AuthenticationService to test Fab2ApprovalMKLink code for net8

Compile conditionally flags to debug in dotnet core
2025-05-23 12:51:42 -07:00

290 lines
16 KiB
C#

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
namespace Fab2ApprovalSystem.Models;
public class AppSettings {
public AppSettings(string adminNotificationRecepient,
string apiBaseUrl,
string attachmentFolder,
string? attachmentUrl,
string caBlankFormsLocation,
string? company,
string dBConnection,
string dbConnectionString,
string emailTemplatesPath,
string ftpPassword,
string ftpSPNBatchFileName,
string ftpSPNBatchFileName_Test,
string ftpServer,
string ftpUser,
string holdFlagDirectory,
string hostURL,
string ifxContainer,
string ifxDomain,
bool isInfineonDomain,
string? jwtAudience,
string? jwtIssuer,
string? jwtKey,
string lotTempPipeLine,
string mesaTemplateFiles,
string nDriveURL,
string naContainer,
string naDomain,
string notificationSender,
string senderEmail,
string? smtpServer,
string spnMRBHoldFlagDirectory,
string spnMRBHoldFlagFTPLogDirectory,
string ssrSFolder,
string ssrSBindingsByConfiguration,
string ssrSBaseURL,
string ssrSDomain,
string ssrSUsername,
string ssrSPassword,
string testEmailRecipients,
string urls,
int userId,
bool userIsAdmin,
string wasmClientUrl,
string wsr_URL,
string? workingDirectoryName) {
AdminNotificationRecepient = adminNotificationRecepient;
ApiBaseUrl = apiBaseUrl;
AttachmentFolder = attachmentFolder;
AttachmentUrl = attachmentUrl;
CABlankFormsLocation = caBlankFormsLocation;
Company = company;
DBConnection = dBConnection;
DBConnectionString = dbConnectionString;
EmailTemplatesPath = emailTemplatesPath;
FTPPassword = ftpPassword;
FTPSPNBatchFileName = ftpSPNBatchFileName;
FTPSPNBatchFileName_Test = ftpSPNBatchFileName_Test;
FTPServer = ftpServer;
FTPUser = ftpUser;
HoldFlagDirectory = holdFlagDirectory;
HostURL = hostURL;
IFXContainer = ifxContainer;
IFXDomain = ifxDomain;
IsInfineonDomain = isInfineonDomain;
JwtAudience = jwtAudience;
JwtIssuer = jwtIssuer;
JwtKey = jwtKey;
LotTempPipeLine = lotTempPipeLine;
MesaTemplateFiles = mesaTemplateFiles;
NDriveURL = nDriveURL;
NAContainer = naContainer;
NADomain = naDomain;
NotificationSender = notificationSender;
SenderEmail = senderEmail;
SMTPServer = smtpServer;
SPNMRBHoldFlagDirectory = spnMRBHoldFlagDirectory;
SPNMRBHoldFlagFTPLogDirectory = spnMRBHoldFlagFTPLogDirectory;
TestEmailRecipients = testEmailRecipients;
SSRSFolder = ssrSFolder;
SSRSBindingsByConfiguration = ssrSBindingsByConfiguration;
SSRSBaseURL = ssrSBaseURL;
SSRSDomain = ssrSDomain;
SSRSUsername = ssrSUsername;
SSRSPassword = ssrSPassword;
URLs = urls;
UserId = userId;
UserIsAdmin = userIsAdmin;
WSR_URL = wsr_URL;
WasmClientUrl = wasmClientUrl;
WorkingDirectoryName = workingDirectoryName;
}
public string AdminNotificationRecepient { get; }
public string ApiBaseUrl { get; }
public string AttachmentFolder { get; }
public string? AttachmentUrl { get; }
public string CABlankFormsLocation { get; }
public string? Company { get; }
public string DBConnection { get; }
public string DBConnectionString { get; }
public string EmailTemplatesPath { get; }
public string FTPPassword { get; }
public string FTPSPNBatchFileName { get; }
public string FTPSPNBatchFileName_Test { get; }
public string FTPServer { get; }
public string FTPUser { get; }
public string HoldFlagDirectory { get; }
public string HostURL { get; }
public string IFXContainer { get; }
public string IFXDomain { get; }
public bool IsInfineonDomain { get; }
public string? JwtAudience { get; }
public string? JwtIssuer { get; }
public string? JwtKey { get; }
public string LotTempPipeLine { get; }
public string MesaTemplateFiles { get; }
public string NAContainer { get; }
public string NADomain { get; }
public string NDriveURL { get; }
public string NotificationSender { get; }
public string SenderEmail { get; }
public string? SMTPServer { get; }
public string SPNMRBHoldFlagDirectory { get; }
public string SPNMRBHoldFlagFTPLogDirectory { get; }
public string SSRSFolder { get; }
public string SSRSBindingsByConfiguration { get; }
public string SSRSBaseURL { get; }
public string SSRSDomain { get; }
public string SSRSUsername { get; }
public string SSRSPassword { get; }
public string TestEmailRecipients { get; }
public string URLs { get; }
public int UserId { get; }
public bool UserIsAdmin { get; }
public string WasmClientUrl { get; }
public string WSR_URL { get; }
public string? WorkingDirectoryName { get; }
#if NET8
public static AppSettings Get(Microsoft.Extensions.Configuration.IConfigurationRoot configurationRoot) {
AppSettings? result;
try {
#pragma warning disable IL3050, IL2026
result = Microsoft.Extensions.Configuration.ConfigurationBinder.Get<AppSettings>(configurationRoot) ?? throw new Exception();
#pragma warning restore IL3050, IL2026
} catch (Exception) {
List<string> paths = [];
foreach (Microsoft.Extensions.Configuration.IConfigurationProvider configurationProvider in configurationRoot.Providers) {
if (configurationProvider is not Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider jsonConfigurationProvider)
continue;
if (jsonConfigurationProvider.Source.FileProvider is not Microsoft.Extensions.FileProviders.PhysicalFileProvider physicalFileProvider)
continue;
paths.Add(physicalFileProvider.Root);
}
throw new NotSupportedException($"Not found!{Environment.NewLine}{string.Join(Environment.NewLine, paths.Distinct())}");
}
return result;
}
#endif
internal static AppSettings LoadConfigurationManager() {
AppSettings result;
try {
int userId = 0;
string adminNotificationRecepient = ConfigurationManager.AppSettings["Admin Notification Recepient"] ??
throw new ArgumentNullException("Admin Notification Recepient environment variable not found");
string attachmentFolder = ConfigurationManager.AppSettings["AttachmentFolder"] ??
throw new ArgumentNullException("AttachmentFolder environment variable not found");
string emailTemplatesPath = ConfigurationManager.AppSettings["EmailTemplatesPath"] ??
throw new ArgumentNullException("EmailTemplatesPath environment variable not found");
string ftpPassword = ConfigurationManager.AppSettings["FTP Password"] ??
throw new ArgumentNullException("FTP Password environment variable not found");
string ftpServer = ConfigurationManager.AppSettings["FTP Server"] ??
throw new ArgumentNullException("FTP Server environment variable not found");
string ftpSPNBatchFileName = ConfigurationManager.AppSettings["FTPSPNBatchFileName"] ??
throw new ArgumentNullException("FTPSPNBatchFileName environment variable not found");
string ftpSPNBatchFileName_Test = ConfigurationManager.AppSettings["FTPSPNBatchFileName_Test"] ??
throw new ArgumentNullException("FTPSPNBatchFileName_Test environment variable not found");
string ftpUser = ConfigurationManager.AppSettings["FTP User"] ??
throw new ArgumentNullException("FTP User environment variable not found");
string holdFlagDirectory = ConfigurationManager.AppSettings["HoldFlagDirectory"] ??
throw new ArgumentNullException("HoldFlagDirectory environment variable not found");
string ifxContainer = ConfigurationManager.AppSettings["IFXContainer"] ??
throw new ArgumentNullException("IFXContainer environment variable not found");
string ifxDomain = ConfigurationManager.AppSettings["IFXDomain"] ??
throw new ArgumentNullException("IFXDomain environment variable not found");
string lotTempPipeLine = ConfigurationManager.AppSettings["LotTempPipeLine"] ??
throw new ArgumentNullException("LotTempPipeLine environment variable not found");
string naContainer = ConfigurationManager.AppSettings["NAContainer"] ??
throw new ArgumentNullException("NAContainer environment variable not found");
string naDomain = ConfigurationManager.AppSettings["NADomain"] ??
throw new ArgumentNullException("NADomain environment variable not found");
string notificationSender = ConfigurationManager.AppSettings["Notification Sender"] ??
throw new ArgumentNullException("Notification Sender environment variable not found");
string spnMRBHoldFlagDirectory = ConfigurationManager.AppSettings["SPNMRBHoldFlagDirectory"] ??
throw new ArgumentNullException("SPNMRBHoldFlagDirectory environment variable not found");
string spnMRBHoldFlagFTPLogDirectory = ConfigurationManager.AppSettings["SPNMRBHoldFlagFTPLogDirectory"] ??
throw new ArgumentNullException("SPNMRBHoldFlagFTPLogDirectory environment variable not found");
string ssrSFolder = ConfigurationManager.AppSettings["SSRSFolder"] ??
throw new ArgumentNullException("SSRSFolder environment variable not found");
string ssrSBindingsByConfiguration = ConfigurationManager.AppSettings["SSRSBindingsByConfiguration"] ??
throw new ArgumentNullException("SSRSBindingsByConfiguration environment variable not found");
string ssrSBaseURL = ConfigurationManager.AppSettings["SSRSBaseURL"] ??
throw new ArgumentNullException("SSRSBaseURL environment variable not found");
string ssrSDomain = ConfigurationManager.AppSettings["SSRSDomain"] ??
throw new ArgumentNullException("SSRSDomain environment variable not found");
string ssrSUsername = ConfigurationManager.AppSettings["SSRSUsername"] ??
throw new ArgumentNullException("SSRSUsername environment variable not found");
string ssrSPassword = ConfigurationManager.AppSettings["SSRSPassword"] ??
throw new ArgumentNullException("SSRSPassword environment variable not found");
string testEmailRecipients = ConfigurationManager.AppSettings["Test Email Recipients"] ??
throw new ArgumentNullException("Test Email Recipients environment variable not found");
string apiBaseUrl = Environment.GetEnvironmentVariable("FabApprovalApiBaseUrl") ??
throw new ArgumentNullException("FabApprovalApiBaseUrl environment variable not found");
string? attachmentUrl = ConfigurationManager.AppSettings["AttachmentUrl"]?.ToString();
string? company = ConfigurationManager.AppSettings["Company"]?.ToString();
string? smtpServer = ConfigurationManager.AppSettings["SMTP Server"]?.ToString();
string? urls = ConfigurationManager.AppSettings["URLs"]?.ToString();
string? workingDirectoryName = ConfigurationManager.AppSettings["WorkingDirectoryName"]?.ToString();
string wasmClientUrl = Environment.GetEnvironmentVariable("FabApprovalWasmClientUrl") ??
"https://localhost:7255";
string? jwtAudience = ConfigurationManager.AppSettings["JwtAudience"]?.ToString();
string? jwtIssuer = ConfigurationManager.AppSettings["JwtIssuer"]?.ToString();
string? jwtKey = ConfigurationManager.AppSettings["JwtKey"]?.ToString();
result = new(adminNotificationRecepient: adminNotificationRecepient,
apiBaseUrl: apiBaseUrl,
attachmentFolder: attachmentFolder,
attachmentUrl: attachmentUrl,
caBlankFormsLocation: Misc.GlobalVars.CA_BlankFormsLocation,
company: company,
dBConnection: Misc.GlobalVars.DBConnection,
dbConnectionString: Misc.GlobalVars.DB_CONNECTION_STRING,
emailTemplatesPath: emailTemplatesPath,
ftpPassword: ftpPassword,
ftpServer: ftpServer,
ftpSPNBatchFileName: ftpSPNBatchFileName,
ftpSPNBatchFileName_Test: ftpSPNBatchFileName_Test,
ftpUser: ftpUser,
holdFlagDirectory: holdFlagDirectory,
hostURL: Misc.GlobalVars.hostURL,
ifxContainer: ifxContainer,
ifxDomain: ifxDomain,
isInfineonDomain: Misc.GlobalVars.IS_INFINEON_DOMAIN,
jwtAudience: jwtAudience,
jwtIssuer: jwtIssuer,
jwtKey: jwtKey,
lotTempPipeLine: lotTempPipeLine,
mesaTemplateFiles: Misc.GlobalVars.MesaTemplateFiles,
naContainer: naContainer,
naDomain: naDomain,
nDriveURL: Misc.GlobalVars.NDriveURL,
notificationSender: notificationSender,
senderEmail: Misc.GlobalVars.SENDER_EMAIL,
smtpServer: smtpServer,
spnMRBHoldFlagDirectory: spnMRBHoldFlagDirectory,
spnMRBHoldFlagFTPLogDirectory: spnMRBHoldFlagFTPLogDirectory,
testEmailRecipients: testEmailRecipients,
ssrSFolder: ssrSFolder,
ssrSBindingsByConfiguration: ssrSBindingsByConfiguration,
ssrSBaseURL: ssrSBaseURL,
ssrSDomain: ssrSDomain,
ssrSUsername: ssrSUsername,
ssrSPassword: ssrSPassword,
urls: urls,
userId: userId,
userIsAdmin: Misc.GlobalVars.USER_ISADMIN,
wasmClientUrl: wasmClientUrl,
wsr_URL: Misc.GlobalVars.WSR_URL,
workingDirectoryName: workingDirectoryName);
return result;
} catch (Exception ex) {
Misc.Functions.WriteEvent(null, "LoadConfigurationManager - \r\n" + ex.Message.ToString(), System.Diagnostics.EventLogEntryType.Error);
throw;
}
}
}