| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452 |
- using System;
- using System.Globalization;
- using System.ServiceModel.Activation;
- using System.Timers;
- using System.Web;
- using System.Web.Routing;
- using Curtain.Core;
- 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.Contracts;
- using Dongke.IBOSS.PRD.WCF.ExHGS3QRS;
- using Dongke.IBOSS.PRD.WCF.Services;
- 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)
- );
- DataManager.ConnectionStringReport = DataManager.ConnectionString;
- try
- {
- string DBIP = ini.ReadIniData("DBSettingReport", "DBIP");
- if (!string.IsNullOrWhiteSpace(DBIP))
- {
- DataManager.ConnectionStringReport = string.Format(DataManager.ConnectionStringFormat,
- DBIP,
- ini.ReadIniData("DBSettingReport", "DBPort"),
- ini.ReadIniData("DBSettingReport", "SID"),
- ini.ReadIniData("DBSettingReport", "DBUser"),
- Encryption.DecryptDES(ini.ReadIniData("DBSettingReport", "DBPassword"), Constant.S_ENCRYPTION_KEY)
- );
- }
- }
- catch
- {
- }
- DataAccess.DefaultDataBaseType = Curtain.DataAccess.DataBaseType.Oracle;
- DataAccess.DefaultConnectionString = DataManager.ConnectionString;
- // SAP接口自动调用
- //InitSAP_HEGII();
- }
- 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 bool Timer_doing = false;
- public static void InitSAP_HEGII()
- {
- try
- {
- INIUtility ini = INIUtility.Instance(INIUtility.IniFile.SAP_HEGII);
- // 下次开始时间
- string SAP_ING = ini.ReadIniData("SAP_HEGII", "SAP_ING");
- if (SAP_ING != "1")
- {
- OutputLog.TraceLog(LogPriority.Information,
- "Global",
- "Application_Start - InitSAP_HEGII",
- "Timer not Started",
- LocalPath.LogExePath + "SAP_HEGII\\Timer_");
- return;
- }
- //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)
- {
- if (Timer_doing)
- {
- return;
- }
- try
- {
- Timer_doing = true;
- lock (Timer_Loker)
- {
- // 当前时间
- DateTime dateTimeNow = DateTime.Now;
- INIUtility ini = INIUtility.Instance(INIUtility.IniFile.SAP_HEGII);
- // 下次开始时间
- string nextDate = ini.ReadIniData("SAP_HEGII", "NextDate");
- string strInterval = ini.ReadIniData("SAP_HEGII", "Interval");
- DateTime ndate;
- if (!string.IsNullOrWhiteSpace(nextDate) && !string.IsNullOrWhiteSpace(strInterval))
- {
- ndate = DateTime.ParseExact(nextDate, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture);
- DateTime.TryParseExact(nextDate, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out ndate);
- if (ndate != null && ndate <= dateTimeNow)
- {
- // 间隔时间(分钟)
- int interval = strInterval.ToInt32();
- DateTime nextDateINI = ndate.AddMinutes(interval);
- while (nextDateINI <= dateTimeNow)
- {
- nextDateINI = nextDateINI.AddMinutes(interval);
- }
- // 更新下次执行时间
- ini.WriteIniData("SAP_HEGII", "NextDate", nextDateINI.ToString("yyyy-MM-dd HH:mm"));
- string funCode = ini.ReadIniData("SAP_HEGII", "FunCode");
- OutputLog.TraceLog(LogPriority.Information,
- "Global2",
- "OnTimedEvent begin: " + funCode,
- "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
- + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + $" -date:" + ndate.ToString("yyyy-MM-dd HH:mm:ss")
- + $" -[{interval}]" + nextDateINI.ToString("yyyy-MM-dd HH:mm:ss"),
- LocalPath.LogExePath + "SAP_HEGII\\Timer_");
- Service.SAPHegiiDataService.SAPDataLogic.AutoWorkDataToSAP(ndate, funCode, ndate);
- OutputLog.TraceLog(LogPriority.Information,
- "Global2",
- "OnTimedEvent end",
- "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
- + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
- LocalPath.LogExePath + "SAP_HEGII\\Timer_");
- }
- }
- #region 50
- string nextDate50 = ini.ReadIniData("SAP_HEGII", "NextDate50");
- string strInterval50 = ini.ReadIniData("SAP_HEGII", "Interval50");
- if (!string.IsNullOrWhiteSpace(nextDate50) && !string.IsNullOrWhiteSpace(strInterval50) &&
- DateTime.TryParseExact(nextDate50, "yyyy-MM-dd HH:mm", null, DateTimeStyles.None, out ndate) &&
- ndate <= dateTimeNow)
- {
- // 间隔时间(分钟)
- int interval50 = strInterval50.ToInt32();
- DateTime nextDateINI50 = ndate.AddMinutes(interval50);
- while (nextDateINI50 <= dateTimeNow)
- {
- nextDateINI50 = nextDateINI50.AddMinutes(interval50);
- }
- // 更新下次执行时间
- ini.WriteIniData("SAP_HEGII", "NextDate50", nextDateINI50.ToString("yyyy-MM-dd HH:mm"));
- string funCode = "50";
- OutputLog.TraceLog(LogPriority.Information,
- "Global2",
- "OnTimedEvent begin: " + funCode,
- "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
- + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + $" -date:" + ndate.ToString("yyyy-MM-dd HH:mm:ss")
- + $" -[{interval50}]" + nextDateINI50.ToString("yyyy-MM-dd HH:mm:ss"),
- LocalPath.LogExePath + "SAP_HEGII\\Timer_");
- Service.SAPHegiiDataService.SAPDataLogic.AutoWorkDataToSAP(ndate, funCode, ndate);
- OutputLog.TraceLog(LogPriority.Information,
- "Global2",
- "OnTimedEvent end",
- "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
- + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
- LocalPath.LogExePath + "SAP_HEGII\\Timer_");
- }
- #endregion
- #region 6002
- /*
- string nextDate6002 = ini.ReadIniData("SAP_HEGII", "NextDate6002");
- if (!string.IsNullOrWhiteSpace(nextDate6002))
- {
- 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_");
- }
- }
- }
- */
- #endregion
- }
- }
- 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_");
- }
- finally
- {
- Timer_doing = false;
- }
- }
- #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_");
- }
- }
- }
- }
|