187 lines
6.8 KiB
C#
187 lines
6.8 KiB
C#
namespace FineUIPro.Web
|
|
{
|
|
using BLL;
|
|
using Model;
|
|
using System;
|
|
using System.Configuration;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
public class Global : System.Web.HttpApplication
|
|
{
|
|
/// <summary>
|
|
/// 自动启用插件标志文件路径
|
|
/// </summary>
|
|
//private static string applicationActiveFlagFilePhysicalPath = String.Empty;
|
|
|
|
protected void Application_Start(object sender, EventArgs e)
|
|
{
|
|
Application["OnlineUserCount"] = 0;
|
|
try
|
|
{
|
|
Funs.RootPath = Server.MapPath("~/");
|
|
|
|
// 日志文件所在目录
|
|
ErrLogInfo.DefaultErrLogFullPath = Server.MapPath("~/ErrLog.txt");
|
|
Funs.ConnString = ConfigurationManager.AppSettings["ConnectionString"];
|
|
Funs.SystemName = ConfigurationManager.AppSettings["SystemName"];
|
|
Funs.SGGLUrl = ConfigurationManager.AppSettings["SGGLUrl"];
|
|
Funs.RealNameApiUrl = ConfigurationManager.AppSettings["RealNameApiUrl"];
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrLogInfo.WriteLog(string.Empty, ex);
|
|
//AppDomain.Unload(AppDomain.CurrentDomain);
|
|
}
|
|
//通用定时器
|
|
try
|
|
{
|
|
ErrLogInfo.WriteLog("通用定时器开启!");
|
|
QuartzServices.Init();
|
|
ErrLogInfo.WriteLog("通用定时器结束!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrLogInfo.WriteLog("通用定时器!", ex);
|
|
}
|
|
// 开启线程
|
|
System.Threading.Thread LoadServiceData = new System.Threading.Thread(new System.Threading.ThreadStart(EduTrainAddScore));
|
|
LoadServiceData.Start();
|
|
}
|
|
|
|
private void EduTrainAddScore()
|
|
{
|
|
//定义一个定时器,并开启和配置相关属性
|
|
System.Timers.Timer Wtimer = new System.Timers.Timer();
|
|
//执行任务的周期 ,60分钟
|
|
Wtimer.Interval = 1000 * 60 * 60; //120000;
|
|
Wtimer.Enabled = true;
|
|
Wtimer.Start();
|
|
Wtimer.Elapsed += new System.Timers.ElapsedEventHandler(Wtimer_Elapsed);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 培训考试加分
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
void Wtimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
|
{
|
|
//考试大于等于及格分、已开考、且没有加过分的记录,加分
|
|
//与交卷接口共用同一套记分逻辑,避免两份实现各自维护
|
|
//直接查基表,避免视图里 7 个 LEFT JOIN 的全表扫描
|
|
int passScore = BLL.SysConstSetService.getPassScore();
|
|
var testRecordIds = (from x in Funs.DB.Training_TestRecord
|
|
where x.TestScores >= passScore && x.TestStartTime != null
|
|
&& !Funs.DB.ScoreFlowLog.Any(log => log.DataSourceId == x.TestRecordId)
|
|
orderby x.TestStartTime
|
|
select x.TestRecordId).ToList();
|
|
foreach (var testRecordId in testRecordIds)
|
|
{
|
|
BLL.ScoreFlowLogService.HseScoring(testRecordId);
|
|
}
|
|
}
|
|
|
|
protected void Session_Start(object sender, EventArgs e)
|
|
{
|
|
Session.Timeout = 60;
|
|
// 这种统计在线人数的做法会有一定的误差
|
|
Application.Lock();
|
|
Application["OnlineUserCount"] = (int)Application["OnlineUserCount"] + 1;
|
|
Application.UnLock();
|
|
}
|
|
|
|
protected void Application_BeginRequest(object sender, EventArgs e)
|
|
{
|
|
}
|
|
|
|
protected void Application_AuthenticateRequest(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
protected void Application_Error(object sender, EventArgs e)
|
|
{
|
|
StringBuilder errLog = null;
|
|
Exception ex = null;
|
|
using (Model.CNPCDB db = new Model.CNPCDB(Funs.ConnString))
|
|
{
|
|
Sys_ErrLogInfo newErr = new Sys_ErrLogInfo
|
|
{
|
|
ErrLogId = SQLHelper.GetNewID()
|
|
};
|
|
try
|
|
{
|
|
// 获取错误类
|
|
ex = Server.GetLastError().InnerException;
|
|
if (ex == null)
|
|
{
|
|
ex = Server.GetLastError().GetBaseException();
|
|
}
|
|
errLog = new StringBuilder();
|
|
errLog.Append(String.Format(CultureInfo.InvariantCulture, "出错文件:{0}\r\n", Request.Url.AbsoluteUri));
|
|
newErr.ErrUrl = Request.Url.AbsoluteUri;
|
|
|
|
if (Request.UserHostAddress != null)
|
|
{
|
|
errLog.Append(String.Format(CultureInfo.InvariantCulture, "IP地址:{0}\r\n", Request.UserHostAddress));
|
|
newErr.ErrIP = Request.UserHostAddress;
|
|
}
|
|
|
|
if (Session != null && Session["CurrUser"] != null)
|
|
{
|
|
errLog.Append(String.Format(CultureInfo.InvariantCulture, "操作人员:{0}\r\n", ((Model.Sys_User)Session["CurrUser"]).UserName));
|
|
newErr.UserName = ((Model.Sys_User)Session["CurrUser"]).UserId;
|
|
}
|
|
else
|
|
{
|
|
PageBase.PageRefresh(Request.ApplicationPath + "/LogOff.aspx");
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
try
|
|
{
|
|
PageBase.PageRefresh(Request.ApplicationPath + "/LogOff.aspx");
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if (errLog != null)
|
|
{
|
|
db.Sys_ErrLogInfo.InsertOnSubmit(newErr);
|
|
db.SubmitChanges();
|
|
}
|
|
|
|
ErrLogInfo.WriteLog(newErr.ErrLogId, ex, errLog == null ? null : errLog.ToString());
|
|
Server.ClearError();
|
|
|
|
//PageBase.PageRefresh(Request.ApplicationPath + "/LogOff.aspx");
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 缓存结束
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Session_End(object sender, EventArgs e)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// 活动结束
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Application_End(object sender, EventArgs e)
|
|
{
|
|
}
|
|
}
|
|
}
|