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:
@ -1,165 +1,128 @@
|
||||
using Fab2ApprovalSystem.Misc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Hosting;
|
||||
using System.Web.Http;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Optimization;
|
||||
using System.Web.Routing;
|
||||
using System.Web.Security;
|
||||
using System.Configuration;
|
||||
|
||||
using Fab2ApprovalSystem.DMO;
|
||||
using System.Web.Http;
|
||||
using Fab2ApprovalSystem.JobSchedules;
|
||||
using Fab2ApprovalSystem.Misc;
|
||||
using Fab2ApprovalSystem.Models;
|
||||
|
||||
namespace Fab2ApprovalSystem
|
||||
{
|
||||
public class MvcApplication : System.Web.HttpApplication
|
||||
{
|
||||
protected void Application_Start()
|
||||
{
|
||||
AreaRegistration.RegisterAllAreas();
|
||||
GlobalConfiguration.Configure(WebApiConfig.Register);
|
||||
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
|
||||
RouteConfig.RegisterRoutes(RouteTable.Routes);
|
||||
BundleConfig.RegisterBundles(BundleTable.Bundles);
|
||||
namespace Fab2ApprovalSystem;
|
||||
|
||||
string hostName = System.Net.Dns.GetHostEntry("").HostName;
|
||||
GlobalVars.IS_INFINEON_DOMAIN = hostName.ToLower().Contains("infineon");
|
||||
public class MvcApplication : System.Web.HttpApplication {
|
||||
|
||||
string DevWebSiteUrl = ConfigurationManager.AppSettings["DevWebSiteURL"].ToString();
|
||||
string ProdWebSiteUrlEC = ConfigurationManager.AppSettings["ProdWebSiteURLEC"].ToString();
|
||||
string ProdWebSiteUrlStealth = ConfigurationManager.AppSettings["ProdWebSiteURLStealth"].ToString();
|
||||
protected void Application_Start() {
|
||||
AreaRegistration.RegisterAllAreas();
|
||||
GlobalConfiguration.Configure(WebApiConfig.Register);
|
||||
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
|
||||
RouteConfig.RegisterRoutes(RouteTable.Routes);
|
||||
BundleConfig.RegisterBundles(BundleTable.Bundles);
|
||||
|
||||
GlobalVars.SENDER_EMAIL = "FabApprovalSystem@Infineon.com"; // put in the Config File
|
||||
if (ConfigurationManager.AppSettings["Notification Sender"] != null)
|
||||
GlobalVars.SENDER_EMAIL = ConfigurationManager.AppSettings["Notification Sender"].ToString();
|
||||
string hostName = System.Net.Dns.GetHostEntry("").HostName;
|
||||
GlobalVars.IS_INFINEON_DOMAIN = hostName.ToLower().Contains("infineon");
|
||||
|
||||
GlobalVars.NDriveURL = ConfigurationManager.AppSettings["NDrive"].ToString();
|
||||
GlobalVars.WSR_URL = ConfigurationManager.AppSettings["WSR_URL"].ToString();
|
||||
GlobalVars.CA_BlankFormsLocation = ConfigurationManager.AppSettings["CA_BlankFormsLocation"].ToString();
|
||||
string DevWebSiteUrl = ConfigurationManager.AppSettings["DevWebSiteURL"].ToString();
|
||||
string ProdWebSiteUrlEC = ConfigurationManager.AppSettings["ProdWebSiteURLEC"].ToString();
|
||||
string ProdWebSiteUrlStealth = ConfigurationManager.AppSettings["ProdWebSiteURLStealth"].ToString();
|
||||
|
||||
//GlobalVars.AttachmentUrl = connectionstring.ToUpper().Contains("TEST") ? @"http://" + DevAttachmentUrl + "/" : @"http://" + ProdAttachmentUrl + "/"; ;
|
||||
GlobalVars.SENDER_EMAIL = "FabApprovalSystem@Infineon.com"; // put in the Config File
|
||||
if (ConfigurationManager.AppSettings["Notification Sender"] != null)
|
||||
GlobalVars.SENDER_EMAIL = ConfigurationManager.AppSettings["Notification Sender"].ToString();
|
||||
|
||||
GlobalVars.NDriveURL = ConfigurationManager.AppSettings["NDrive"].ToString();
|
||||
GlobalVars.WSR_URL = ConfigurationManager.AppSettings["WSR_URL"].ToString();
|
||||
GlobalVars.CA_BlankFormsLocation = ConfigurationManager.AppSettings["CA_BlankFormsLocation"].ToString();
|
||||
|
||||
#if (!DEBUG)
|
||||
OOOTrainingReportJobSchedule.Start();
|
||||
OOOTrainingReportJobSchedule.Start();
|
||||
|
||||
if (GlobalVars.IS_INFINEON_DOMAIN) {
|
||||
GlobalVars.DB_CONNECTION_STRING = ConfigurationManager.ConnectionStrings["FabApprovalConnectionStealth"].ConnectionString.ToString();
|
||||
GlobalVars.hostURL = @"https://" + ProdWebSiteUrlStealth;
|
||||
} else {
|
||||
GlobalVars.DB_CONNECTION_STRING = ConfigurationManager.ConnectionStrings["FabApprovalConnectionEC"].ConnectionString.ToString();
|
||||
GlobalVars.hostURL = @"https://" + ProdWebSiteUrlEC;
|
||||
}
|
||||
if (GlobalVars.IS_INFINEON_DOMAIN) {
|
||||
GlobalVars.DB_CONNECTION_STRING = ConfigurationManager.ConnectionStrings["FabApprovalConnectionStealth"].ConnectionString.ToString();
|
||||
GlobalVars.hostURL = @"https://" + ProdWebSiteUrlStealth;
|
||||
} else {
|
||||
GlobalVars.DB_CONNECTION_STRING = ConfigurationManager.ConnectionStrings["FabApprovalConnectionEC"].ConnectionString.ToString();
|
||||
GlobalVars.hostURL = @"https://" + ProdWebSiteUrlEC;
|
||||
}
|
||||
#else
|
||||
GlobalVars.DB_CONNECTION_STRING = ConfigurationManager.ConnectionStrings["FabApprovalConnectionDev"].ConnectionString.ToString();
|
||||
GlobalVars.hostURL = @"https://" + DevWebSiteUrl;
|
||||
GlobalVars.DB_CONNECTION_STRING = ConfigurationManager.ConnectionStrings["FabApprovalConnectionDev"].ConnectionString.ToString();
|
||||
GlobalVars.hostURL = @"https://" + DevWebSiteUrl;
|
||||
#endif
|
||||
GlobalVars.DBConnection = GlobalVars.DB_CONNECTION_STRING.ToUpper().Contains("TEST") ? "TEST" : GlobalVars.DB_CONNECTION_STRING.ToUpper().Contains("QUALITY") ? "QUALITY" : "PROD";
|
||||
}
|
||||
|
||||
|
||||
//void Application_BeginRequest(Object source, EventArgs e)
|
||||
//{
|
||||
|
||||
// HttpApplication app = (HttpApplication)source;
|
||||
// HttpContext context = app.Context;
|
||||
// GlobalVars.hostURL = context.Request.Url.AbsoluteUri;
|
||||
// // Attempt to peform first request initialization
|
||||
|
||||
//}
|
||||
|
||||
protected void Application_EndRequest()
|
||||
{
|
||||
var context = new HttpContextWrapper(Context);
|
||||
|
||||
//Do a direct 401 unautorized
|
||||
if (Context.Response.StatusCode == 301 && context.Request.IsAjaxRequest())
|
||||
{
|
||||
Context.Response.Clear();
|
||||
Context.Response.StatusCode = 401;
|
||||
}
|
||||
|
||||
else if (FormsAuthentication.IsEnabled && context.Response.StatusCode == 302
|
||||
&& context.Request.IsAjaxRequest())
|
||||
{
|
||||
context.Response.Clear();
|
||||
context.Response.StatusCode = 401;
|
||||
}
|
||||
}
|
||||
|
||||
protected void Session_Start(object sender, EventArgs e)
|
||||
{
|
||||
Session[GlobalVars.ECN_VIEW_OPTION] = "Pending Approvals"; ;
|
||||
}
|
||||
|
||||
protected void Session_End(object sender, EventArgs e)
|
||||
{
|
||||
//FormsAuthentication.SignOut();
|
||||
try
|
||||
{
|
||||
Session[GlobalVars.SESSION_USERNAME] = "";
|
||||
Session[GlobalVars.SESSION_USERID] = "";
|
||||
Session[GlobalVars.IS_ADMIN] = "";
|
||||
|
||||
//LotTravelerDMO LotTravDMO = new LotTravelerDMO();
|
||||
//LotTravDMO.ReleaseLockOnDocument((int)Session[GlobalVars.SESSION_USERID], -1);
|
||||
}
|
||||
|
||||
catch(Exception ex)
|
||||
{
|
||||
Functions.WriteEvent(@User.Identity.Name + "\r\n Session Closed - \r\n" + ex.Message.ToString(), System.Diagnostics.EventLogEntryType.Error);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// This code is to allow hyperlinks from Office products to load the site without always forcing the user to log in
|
||||
// It makes the browser reload the page so that the session cookies are sent properly
|
||||
private static string MSUserAgentsRegex = @"[^\w](Word|Excel|PowerPoint|ms-office)([^\w]|\z)";
|
||||
protected void Application_OnPostAuthenticateRequest(object sender, EventArgs e)
|
||||
{
|
||||
if (System.Text.RegularExpressions.Regex.IsMatch(Request.UserAgent, MSUserAgentsRegex))
|
||||
{
|
||||
Response.Write("<html><head><meta http-equiv='refresh' content='0'/></head><body></body></html>");
|
||||
Response.End();
|
||||
}
|
||||
}
|
||||
|
||||
void Application_Error(object sender, EventArgs e)
|
||||
{
|
||||
var ex = Server.GetLastError();
|
||||
|
||||
var exString = "Caught unhandled exception:\r\n";
|
||||
exString += String.Format("User: {0}\r\n", @User.Identity.Name);
|
||||
Exception x = ex;
|
||||
while (x != null)
|
||||
{
|
||||
exString += x.ToString();
|
||||
exString += "=====\r\n";
|
||||
x = x.InnerException;
|
||||
}
|
||||
|
||||
//Misc.Functions.WriteEvent(exString, System.Diagnostics.EventLogEntryType.Error);
|
||||
|
||||
try
|
||||
{
|
||||
if (exString.Length > 500)
|
||||
exString = exString.Substring(0, 500);
|
||||
|
||||
EventLogDMO.Add(new Fab2ApprovalSystem.Models.WinEventLog()
|
||||
{
|
||||
UserID = @User.Identity.Name,
|
||||
OperationType = "Error",
|
||||
Comments = exString
|
||||
});
|
||||
}
|
||||
catch (Exception ex2)
|
||||
{
|
||||
Misc.Functions.WriteEvent("Failed to write error to event log in database: " + ex2.ToString(), System.Diagnostics.EventLogEntryType.Error);
|
||||
}
|
||||
}
|
||||
GlobalVars.DBConnection = GlobalVars.DB_CONNECTION_STRING.ToUpper().Contains("TEST") ? "TEST" : GlobalVars.DB_CONNECTION_STRING.ToUpper().Contains("QUALITY") ? "QUALITY" : "PROD";
|
||||
|
||||
GlobalVars.AppSettings = Models.AppSettings.LoadConfigurationManager();
|
||||
}
|
||||
}
|
||||
|
||||
protected void Application_EndRequest() {
|
||||
var context = new HttpContextWrapper(Context);
|
||||
|
||||
//Do a direct 401 unauthorized
|
||||
if (Context.Response.StatusCode == 301 && context.Request.IsAjaxRequest()) {
|
||||
Context.Response.Clear();
|
||||
Context.Response.StatusCode = 401;
|
||||
} else if (FormsAuthentication.IsEnabled && context.Response.StatusCode == 302
|
||||
&& context.Request.IsAjaxRequest()) {
|
||||
context.Response.Clear();
|
||||
context.Response.StatusCode = 401;
|
||||
}
|
||||
}
|
||||
|
||||
protected void Session_Start(object sender, EventArgs e) {
|
||||
Session[GlobalVars.ECN_VIEW_OPTION] = "Pending Approvals";
|
||||
}
|
||||
|
||||
protected void Session_End(object sender, EventArgs e) {
|
||||
//FormsAuthentication.SignOut();
|
||||
try {
|
||||
Session[GlobalVars.SESSION_USERNAME] = "";
|
||||
Session[GlobalVars.SESSION_USERID] = "";
|
||||
Session[GlobalVars.IS_ADMIN] = "";
|
||||
} catch (Exception ex) {
|
||||
Functions.WriteEvent(null, @User.Identity.Name + "\r\n Session Closed - \r\n" + ex.Message.ToString(), System.Diagnostics.EventLogEntryType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
// This code is to allow hyperlinks from Office products to load the site without always forcing the user to log in
|
||||
// It makes the browser reload the page so that the session cookies are sent properly
|
||||
private static string MSUserAgentsRegex = @"[^\w](Word|Excel|PowerPoint|ms-office)([^\w]|\z)";
|
||||
protected void Application_OnPostAuthenticateRequest(object sender, EventArgs e) {
|
||||
if (System.Text.RegularExpressions.Regex.IsMatch(Request.UserAgent, MSUserAgentsRegex)) {
|
||||
Response.Write("<html><head><meta http-equiv='refresh' content='0'/></head><body></body></html>");
|
||||
Response.End();
|
||||
}
|
||||
}
|
||||
|
||||
void Application_Error(object sender, EventArgs e) {
|
||||
var ex = Server.GetLastError();
|
||||
|
||||
var exString = "Caught unhandled exception:\r\n";
|
||||
exString += String.Format("User: {0}\r\n", @User.Identity.Name);
|
||||
Exception x = ex;
|
||||
while (x != null) {
|
||||
exString += x.ToString();
|
||||
exString += "=====\r\n";
|
||||
x = x.InnerException;
|
||||
}
|
||||
|
||||
try {
|
||||
if (exString.Length > 500)
|
||||
exString = exString.Substring(0, 500);
|
||||
|
||||
EventLogDMO.Add(new Fab2ApprovalSystem.Models.WinEventLog() {
|
||||
UserID = @User.Identity.Name,
|
||||
OperationType = "Error",
|
||||
Comments = exString
|
||||
});
|
||||
} catch (Exception ex2) {
|
||||
Misc.Functions.WriteEvent(null, "Failed to write error to event log in database: " + ex2.ToString(), System.Diagnostics.EventLogEntryType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user