using System; using System.Globalization; using System.ServiceModel.Activation; using System.Timers; using System.Web; using System.Web.Routing; using Curtain.DataAccess; using Curtain.Log; using Dongke.IBOSS.PRD.Basics.BaseResources; using Dongke.IBOSS.PRD.Basics.DataAccess; using Dongke.IBOSS.PRD.Basics.Library; using Dongke.IBOSS.PRD.WCF.Services; using Dongke.IBOSS.PRD.WCF.ExHGS3QRS; namespace Dongke.IBOSS.PRD.WCF.WebHosting { public class Global : HttpApplication { protected void Application_Start(object sender, EventArgs e) { Logger.DefaultLogDirectory = "Log"; InitService(); // 更改连接串 INIUtility ini = INIUtility.Instance(INIUtility.IniFile.Config); DataManager.ConnectionString = string.Format(DataManager.ConnectionStringFormat, ini.ReadIniData("DBSetting", "DBIP"), ini.ReadIniData("DBSetting", "DBPort"), ini.ReadIniData("DBSetting", "SID"), ini.ReadIniData("DBSetting", "DBUser"), Encryption.DecryptDES(ini.ReadIniData("DBSetting", "DBPassword"), Constant.S_ENCRYPTION_KEY) ); DataAccess.DefaultDataBaseType = Curtain.DataAccess.DataBaseType.Oracle; DataAccess.DefaultConnectionString = DataManager.ConnectionString; // SAP接口自动调用 InitSAP_HEGII(ini.ReadIniData("SAP_HEGII", "Interval")); } private void InitService() { // 此处处理需要进行映射的服务类 /* ServiceRoute实体 * 第一个参数为客户端调用终结点地址的名称 * 第二个参数固定写法 * 第三个参数为终结点调用对应的服务类 */ RouteTable.Routes.Add ( new ServiceRoute ( "DKService/PDAModuleService", new WebServiceHostFactory(), typeof(PDAModuleService) ) ); RouteTable.Routes.Add ( new ServiceRoute ( "DKService/DKIBOSSPRDService", new WebServiceHostFactory(), typeof(DKIBOSSPRDService) ) ); RouteTable.Routes.Add ( new ServiceRoute ( "DKService/CommonModuleService", new WebServiceHostFactory(), typeof(CommonModuleService) ) ); RouteTable.Routes.Add ( new ServiceRoute ( "DKService/SystemModuleService", new WebServiceHostFactory(), typeof(SystemModuleService) ) ); RouteTable.Routes.Add ( new ServiceRoute ( "DKService/HRModuleService", new WebServiceHostFactory(), typeof(HRModuleService) ) ); RouteTable.Routes.Add ( new ServiceRoute ( "DKService/PCModuleService", new WebServiceHostFactory(), typeof(PCModuleService) ) ); RouteTable.Routes.Add ( new ServiceRoute ( "DKService/PMModuleService", new WebServiceHostFactory(), typeof(PMModuleService) ) ); RouteTable.Routes.Add ( new ServiceRoute ( "DKService/TATModuleService", new WebServiceHostFactory(), typeof(TATModuleService) ) ); RouteTable.Routes.Add ( new ServiceRoute ( "DKService/ReportModuleService", new WebServiceHostFactory(), typeof(ReportModuleService) ) ); RouteTable.Routes.Add ( new ServiceRoute ( "DKService/WCFTestService", new WebServiceHostFactory(), typeof(WCFTestService) ) ); RouteTable.Routes.Add ( new ServiceRoute ( "DKService/CMNModuleService", new WebServiceHostFactory(), typeof(CMNModuleService) ) ); RouteTable.Routes.Add ( new ServiceRoute ( "DKService/PMModuleServiceNew", new WebServiceHostFactory(), typeof(PMModuleServiceNew) ) ); RouteTable.Routes.Add ( new ServiceRoute ( "DKService/PCModuleServiceNew", new WebServiceHostFactory(), typeof(PCModuleServiceNew) ) ); RouteTable.Routes.Add ( new ServiceRoute ( "DKService/PAMModuleService", new WebServiceHostFactory(), typeof(PAMModuleService) ) ); RouteTable.Routes.Add ( new ServiceRoute ( "DKService/PublicModuleService", new WebServiceHostFactory(), typeof(PublicModuleService) ) ); RouteTable.Routes.Add ( new ServiceRoute ( "DKService/SmartDeviceService", new WebServiceHostFactory(), typeof(SmartDeviceService) ) ); RouteTable.Routes.Add ( new ServiceRoute ( "DKService/ExHGS3QR", new WebServiceHostFactory(), typeof(ExHGS3QR) ) ); RouteTable.Routes.Add ( new ServiceRoute ( "DKService/SAPDataService", new WebServiceHostFactory(), typeof(SAPDataService) ) ); RouteTable.Routes.Add ( new ServiceRoute ( "DKService/PPModuleService", new WebServiceHostFactory(), typeof(PPModuleService) ) ); } #region SAP_HEGII private class TimerLocker { public string LockerName = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff"); } private static Timer SAP_HEGII_Timer = null; private static TimerLocker Timer_Loker = null; private static void InitSAP_HEGII(string interval) { try { if (string.IsNullOrWhiteSpace(interval)) { return; } double intt = 60000; if (!double.TryParse(interval, out intt) || intt < 30000) { intt = 60000; } Timer_Loker = new TimerLocker(); SAP_HEGII_Timer = new Timer(); SAP_HEGII_Timer.Interval = intt; SAP_HEGII_Timer.Elapsed += new ElapsedEventHandler(OnTimedEvent); SAP_HEGII_Timer.AutoReset = true; SAP_HEGII_Timer.Enabled = true; OutputLog.TraceLog(LogPriority.Information, "Global", "Application_Start - InitSAP_HEGII", "Timer Started : " + Timer_Loker.LockerName + " - " + intt, LocalPath.LogExePath + "SAP_HEGII\\Timer_"); } catch (Exception ex) { OutputLog.TraceLog(LogPriority.Error, "Global", "InitSAP_HEGII", ex.ToString(), LocalPath.LogExePath + "SAP_HEGII\\Error_"); } } private static void OnTimedEvent(object source, ElapsedEventArgs e) { try { lock (Timer_Loker) { INIUtility ini = INIUtility.Instance(INIUtility.IniFile.Config); string nextDate = ini.ReadIniData("SAP_HEGII", "NextDate"); string nextDate6002 = ini.ReadIniData("SAP_HEGII", "NextDate6002"); if (!string.IsNullOrWhiteSpace(nextDate)) { string byTime = ini.ReadIniData("SAP_HEGII", "ByTime"); if (string.IsNullOrWhiteSpace(byTime)) { byTime = "00:00"; } //OutputLog.TraceLog(LogPriority.Information, // "Global", // "OnTimedEvent ", // "OnTimedEvent begin : " + nextDate + " - " + byTime, // LocalPath.LogExePath + "SAP_HEGII\\Timer_"); DateTime ndate; if (DateTime.TryParseExact(nextDate + " " + byTime, "yyyy-MM-dd HH:mm", null, DateTimeStyles.None, out ndate)) { //DateTime date = e.SignalTime; //DateTime.Now; DateTime date = DateTime.Now; if (ndate <= date) { ini.WriteIniData("SAP_HEGII", "NextDate", date.AddDays(1).ToString("yyyy-MM-dd")); string funCode = ini.ReadIniData("SAP_HEGII", "FunCode"); OutputLog.TraceLog(LogPriority.Information, "Global", "OnTimedEvent begin: " + funCode, "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss") + " - " + date.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"), LocalPath.LogExePath + "SAP_HEGII\\Timer_"); Service.SAPHegiiDataService.SAPDataLogic.AutoWorkDataToSAP(date, funCode); OutputLog.TraceLog(LogPriority.Information, "Global", "OnTimedEvent end", "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss") + " - " + date.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"), LocalPath.LogExePath + "SAP_HEGII\\Timer_"); } } } if (!string.IsNullOrWhiteSpace(nextDate6002)) { DateTime ndate; if (DateTime.TryParseExact(nextDate6002, "yyyy-MM-dd HH:mm", null, DateTimeStyles.None, out ndate)) { //DateTime date = e.SignalTime; //DateTime.Now; DateTime date = DateTime.Now; if (ndate <= date) { //ini.WriteIniData("SAP_HEGII", "NextDate6002", date.AddHours(1).ToString("yyyy-MM-dd HH:")+ ndate.ToString("mm")); ini.WriteIniData("SAP_HEGII", "NextDate6002", date.AddMinutes(20).ToString("yyyy-MM-dd HH:mm")); string funCode = "6002"; // ini.ReadIniData("SAP_HEGII", "FunCode"); OutputLog.TraceLog(LogPriority.Information, "Global", "OnTimedEvent begin: " + funCode, "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss") + " - " + date.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"), LocalPath.LogExePath + "SAP_HEGII\\Timer_"); Service.SAPHegiiDataService.SAPDataLogic.AutoWorkDataToSAP(date, funCode); OutputLog.TraceLog(LogPriority.Information, "Global", "OnTimedEvent end", "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss") + " - " + date.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"), LocalPath.LogExePath + "SAP_HEGII\\Timer_"); } } } } } catch (Exception ex) { OutputLog.TraceLog(LogPriority.Error, "Global", "OnTimedEvent - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss"), ex.ToString(), LocalPath.LogExePath + "SAP_HEGII\\Error_"); } } #endregion protected void Session_Start(object sender, EventArgs e) { } protected void Application_BeginRequest(object sender, EventArgs e) { } protected void Application_AuthenticateRequest(object sender, EventArgs e) { } protected void Application_Error(object sender, EventArgs e) { //try //{ // Logger.Error( //} //catch //{ //} } protected void Session_End(object sender, EventArgs e) { } protected void Application_End(object sender, EventArgs e) { SAP_HEGII_Timer?.Dispose(); SAP_HEGII_Timer = null; string lockerName = Timer_Loker?.LockerName; Timer_Loker = null; if (!string.IsNullOrEmpty(lockerName)) { OutputLog.TraceLog(LogPriority.Information, "Global", "Application_End", "Timer End : " + lockerName, LocalPath.LogExePath + "SAP_HEGII\\Timer_"); } } } }