Global.asax.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. using System;
  2. using System.Globalization;
  3. using System.ServiceModel.Activation;
  4. using System.Timers;
  5. using System.Web;
  6. using System.Web.Routing;
  7. using Curtain.Core;
  8. using Curtain.DataAccess;
  9. using Curtain.Log;
  10. using Dongke.IBOSS.PRD.Basics.BaseResources;
  11. using Dongke.IBOSS.PRD.Basics.DataAccess;
  12. using Dongke.IBOSS.PRD.Basics.Library;
  13. using Dongke.IBOSS.PRD.WCF.Contracts;
  14. using Dongke.IBOSS.PRD.WCF.ExHGS3QRS;
  15. using Dongke.IBOSS.PRD.WCF.Services;
  16. namespace Dongke.IBOSS.PRD.WCF.WebHosting
  17. {
  18. public class Global : HttpApplication
  19. {
  20. protected void Application_Start(object sender, EventArgs e)
  21. {
  22. Logger.DefaultLogDirectory = "Log";
  23. InitService();
  24. // 更改连接串
  25. INIUtility ini = INIUtility.Instance(INIUtility.IniFile.Config);
  26. DataManager.ConnectionString = string.Format(DataManager.ConnectionStringFormat,
  27. ini.ReadIniData("DBSetting", "DBIP"),
  28. ini.ReadIniData("DBSetting", "DBPort"),
  29. ini.ReadIniData("DBSetting", "SID"),
  30. ini.ReadIniData("DBSetting", "DBUser"),
  31. Encryption.DecryptDES(ini.ReadIniData("DBSetting", "DBPassword"), Constant.S_ENCRYPTION_KEY)
  32. );
  33. DataManager.ConnectionStringReport = DataManager.ConnectionString;
  34. try
  35. {
  36. string DBIP = ini.ReadIniData("DBSettingReport", "DBIP");
  37. if (!string.IsNullOrWhiteSpace(DBIP))
  38. {
  39. DataManager.ConnectionStringReport = string.Format(DataManager.ConnectionStringFormat,
  40. DBIP,
  41. ini.ReadIniData("DBSettingReport", "DBPort"),
  42. ini.ReadIniData("DBSettingReport", "SID"),
  43. ini.ReadIniData("DBSettingReport", "DBUser"),
  44. Encryption.DecryptDES(ini.ReadIniData("DBSettingReport", "DBPassword"), Constant.S_ENCRYPTION_KEY)
  45. );
  46. }
  47. }
  48. catch
  49. {
  50. }
  51. DataAccess.DefaultDataBaseType = Curtain.DataAccess.DataBaseType.Oracle;
  52. DataAccess.DefaultConnectionString = DataManager.ConnectionString;
  53. // SAP接口自动调用
  54. //InitSAP_HEGII();
  55. }
  56. private void InitService()
  57. {
  58. // 此处处理需要进行映射的服务类
  59. /* ServiceRoute实体
  60. * 第一个参数为客户端调用终结点地址的名称
  61. * 第二个参数固定写法
  62. * 第三个参数为终结点调用对应的服务类
  63. */
  64. RouteTable.Routes.Add
  65. (
  66. new ServiceRoute
  67. (
  68. "DKService/PDAModuleService", new WebServiceHostFactory(), typeof(PDAModuleService)
  69. )
  70. );
  71. RouteTable.Routes.Add
  72. (
  73. new ServiceRoute
  74. (
  75. "DKService/DKIBOSSPRDService", new WebServiceHostFactory(), typeof(DKIBOSSPRDService)
  76. )
  77. );
  78. RouteTable.Routes.Add
  79. (
  80. new ServiceRoute
  81. (
  82. "DKService/CommonModuleService", new WebServiceHostFactory(), typeof(CommonModuleService)
  83. )
  84. );
  85. RouteTable.Routes.Add
  86. (
  87. new ServiceRoute
  88. (
  89. "DKService/SystemModuleService", new WebServiceHostFactory(), typeof(SystemModuleService)
  90. )
  91. );
  92. RouteTable.Routes.Add
  93. (
  94. new ServiceRoute
  95. (
  96. "DKService/HRModuleService", new WebServiceHostFactory(), typeof(HRModuleService)
  97. )
  98. );
  99. RouteTable.Routes.Add
  100. (
  101. new ServiceRoute
  102. (
  103. "DKService/PCModuleService", new WebServiceHostFactory(), typeof(PCModuleService)
  104. )
  105. );
  106. RouteTable.Routes.Add
  107. (
  108. new ServiceRoute
  109. (
  110. "DKService/PMModuleService", new WebServiceHostFactory(), typeof(PMModuleService)
  111. )
  112. );
  113. RouteTable.Routes.Add
  114. (
  115. new ServiceRoute
  116. (
  117. "DKService/TATModuleService", new WebServiceHostFactory(), typeof(TATModuleService)
  118. )
  119. );
  120. RouteTable.Routes.Add
  121. (
  122. new ServiceRoute
  123. (
  124. "DKService/ReportModuleService", new WebServiceHostFactory(), typeof(ReportModuleService)
  125. )
  126. );
  127. RouteTable.Routes.Add
  128. (
  129. new ServiceRoute
  130. (
  131. "DKService/WCFTestService", new WebServiceHostFactory(), typeof(WCFTestService)
  132. )
  133. );
  134. RouteTable.Routes.Add
  135. (
  136. new ServiceRoute
  137. (
  138. "DKService/CMNModuleService", new WebServiceHostFactory(), typeof(CMNModuleService)
  139. )
  140. );
  141. RouteTable.Routes.Add
  142. (
  143. new ServiceRoute
  144. (
  145. "DKService/PMModuleServiceNew", new WebServiceHostFactory(), typeof(PMModuleServiceNew)
  146. )
  147. );
  148. RouteTable.Routes.Add
  149. (
  150. new ServiceRoute
  151. (
  152. "DKService/PCModuleServiceNew", new WebServiceHostFactory(), typeof(PCModuleServiceNew)
  153. )
  154. );
  155. RouteTable.Routes.Add
  156. (
  157. new ServiceRoute
  158. (
  159. "DKService/PAMModuleService", new WebServiceHostFactory(), typeof(PAMModuleService)
  160. )
  161. );
  162. RouteTable.Routes.Add
  163. (
  164. new ServiceRoute
  165. (
  166. "DKService/PublicModuleService", new WebServiceHostFactory(), typeof(PublicModuleService)
  167. )
  168. );
  169. RouteTable.Routes.Add
  170. (
  171. new ServiceRoute
  172. (
  173. "DKService/SmartDeviceService", new WebServiceHostFactory(), typeof(SmartDeviceService)
  174. )
  175. );
  176. RouteTable.Routes.Add
  177. (
  178. new ServiceRoute
  179. (
  180. "DKService/ExHGS3QR", new WebServiceHostFactory(), typeof(ExHGS3QR)
  181. )
  182. );
  183. RouteTable.Routes.Add
  184. (
  185. new ServiceRoute
  186. (
  187. "DKService/SAPDataService", new WebServiceHostFactory(), typeof(SAPDataService)
  188. )
  189. );
  190. RouteTable.Routes.Add
  191. (
  192. new ServiceRoute
  193. (
  194. "DKService/PPModuleService", new WebServiceHostFactory(), typeof(PPModuleService)
  195. )
  196. );
  197. }
  198. #region SAP_HEGII
  199. private class TimerLocker
  200. {
  201. public string LockerName = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff");
  202. }
  203. private static Timer SAP_HEGII_Timer = null;
  204. private static TimerLocker Timer_Loker = null;
  205. private static bool Timer_doing = false;
  206. public static void InitSAP_HEGII()
  207. {
  208. try
  209. {
  210. INIUtility ini = INIUtility.Instance(INIUtility.IniFile.SAP_HEGII);
  211. // 下次开始时间
  212. string SAP_ING = ini.ReadIniData("SAP_HEGII", "SAP_ING");
  213. if (SAP_ING != "1")
  214. {
  215. OutputLog.TraceLog(LogPriority.Information,
  216. "Global",
  217. "Application_Start - InitSAP_HEGII",
  218. "Timer not Started",
  219. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  220. return;
  221. }
  222. //if (string.IsNullOrWhiteSpace(interval))
  223. //{
  224. // return;
  225. //}
  226. double intt = 60000;
  227. //if (!double.TryParse(interval, out intt) || intt < 30000)
  228. //{
  229. // intt = 60000;
  230. //}
  231. Timer_Loker = new TimerLocker();
  232. SAP_HEGII_Timer = new Timer();
  233. SAP_HEGII_Timer.Interval = intt;
  234. SAP_HEGII_Timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
  235. SAP_HEGII_Timer.AutoReset = true;
  236. SAP_HEGII_Timer.Enabled = true;
  237. OutputLog.TraceLog(LogPriority.Information,
  238. "Global",
  239. "Application_Start - InitSAP_HEGII",
  240. "Timer Started : " + Timer_Loker.LockerName + " - " + intt,
  241. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  242. }
  243. catch (Exception ex)
  244. {
  245. OutputLog.TraceLog(LogPriority.Error,
  246. "Global",
  247. "InitSAP_HEGII",
  248. ex.ToString(),
  249. LocalPath.LogExePath + "SAP_HEGII\\Error_");
  250. }
  251. }
  252. private static void OnTimedEvent(object source, ElapsedEventArgs e)
  253. {
  254. if (Timer_doing)
  255. {
  256. return;
  257. }
  258. try
  259. {
  260. Timer_doing = true;
  261. lock (Timer_Loker)
  262. {
  263. // 当前时间
  264. DateTime dateTimeNow = DateTime.Now;
  265. INIUtility ini = INIUtility.Instance(INIUtility.IniFile.SAP_HEGII);
  266. // 下次开始时间
  267. string nextDate = ini.ReadIniData("SAP_HEGII", "NextDate");
  268. string strInterval = ini.ReadIniData("SAP_HEGII", "Interval");
  269. DateTime ndate;
  270. if (!string.IsNullOrWhiteSpace(nextDate) && !string.IsNullOrWhiteSpace(strInterval))
  271. {
  272. ndate = DateTime.ParseExact(nextDate, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture);
  273. DateTime.TryParseExact(nextDate, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out ndate);
  274. if (ndate != null && ndate <= dateTimeNow)
  275. {
  276. // 间隔时间(分钟)
  277. int interval = strInterval.ToInt32();
  278. DateTime nextDateINI = ndate.AddMinutes(interval);
  279. while (nextDateINI <= dateTimeNow)
  280. {
  281. nextDateINI = nextDateINI.AddMinutes(interval);
  282. }
  283. // 更新下次执行时间
  284. ini.WriteIniData("SAP_HEGII", "NextDate", nextDateINI.ToString("yyyy-MM-dd HH:mm"));
  285. string funCode = ini.ReadIniData("SAP_HEGII", "FunCode");
  286. OutputLog.TraceLog(LogPriority.Information,
  287. "Global2",
  288. "OnTimedEvent begin: " + funCode,
  289. "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  290. + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + $" -date:" + ndate.ToString("yyyy-MM-dd HH:mm:ss")
  291. + $" -[{interval}]" + nextDateINI.ToString("yyyy-MM-dd HH:mm:ss"),
  292. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  293. Service.SAPHegiiDataService.SAPDataLogic.AutoWorkDataToSAP(ndate, funCode, ndate);
  294. OutputLog.TraceLog(LogPriority.Information,
  295. "Global2",
  296. "OnTimedEvent end",
  297. "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  298. + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
  299. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  300. }
  301. }
  302. #region 50
  303. string nextDate50 = ini.ReadIniData("SAP_HEGII", "NextDate50");
  304. string strInterval50 = ini.ReadIniData("SAP_HEGII", "Interval50");
  305. if (!string.IsNullOrWhiteSpace(nextDate50) && !string.IsNullOrWhiteSpace(strInterval50) &&
  306. DateTime.TryParseExact(nextDate50, "yyyy-MM-dd HH:mm", null, DateTimeStyles.None, out ndate) &&
  307. ndate <= dateTimeNow)
  308. {
  309. // 间隔时间(分钟)
  310. int interval50 = strInterval50.ToInt32();
  311. DateTime nextDateINI50 = ndate.AddMinutes(interval50);
  312. while (nextDateINI50 <= dateTimeNow)
  313. {
  314. nextDateINI50 = nextDateINI50.AddMinutes(interval50);
  315. }
  316. // 更新下次执行时间
  317. ini.WriteIniData("SAP_HEGII", "NextDate50", nextDateINI50.ToString("yyyy-MM-dd HH:mm"));
  318. string funCode = "50";
  319. OutputLog.TraceLog(LogPriority.Information,
  320. "Global2",
  321. "OnTimedEvent begin: " + funCode,
  322. "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  323. + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + $" -date:" + ndate.ToString("yyyy-MM-dd HH:mm:ss")
  324. + $" -[{interval50}]" + nextDateINI50.ToString("yyyy-MM-dd HH:mm:ss"),
  325. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  326. Service.SAPHegiiDataService.SAPDataLogic.AutoWorkDataToSAP(ndate, funCode, ndate);
  327. OutputLog.TraceLog(LogPriority.Information,
  328. "Global2",
  329. "OnTimedEvent end",
  330. "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  331. + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
  332. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  333. }
  334. #endregion
  335. #region 6002
  336. /*
  337. string nextDate6002 = ini.ReadIniData("SAP_HEGII", "NextDate6002");
  338. if (!string.IsNullOrWhiteSpace(nextDate6002))
  339. {
  340. if (DateTime.TryParseExact(nextDate6002, "yyyy-MM-dd HH:mm", null, DateTimeStyles.None, out ndate))
  341. {
  342. //DateTime date = e.SignalTime; //DateTime.Now;
  343. DateTime date = DateTime.Now;
  344. if (ndate <= date)
  345. {
  346. //ini.WriteIniData("SAP_HEGII", "NextDate6002", date.AddHours(1).ToString("yyyy-MM-dd HH:")+ ndate.ToString("mm"));
  347. ini.WriteIniData("SAP_HEGII", "NextDate6002", date.AddMinutes(20).ToString("yyyy-MM-dd HH:mm"));
  348. string funCode = "6002"; // ini.ReadIniData("SAP_HEGII", "FunCode");
  349. OutputLog.TraceLog(LogPriority.Information,
  350. "Global",
  351. "OnTimedEvent begin: " + funCode,
  352. "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  353. + " - " + date.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
  354. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  355. Service.SAPHegiiDataService.SAPDataLogic.AutoWorkDataToSAP(date, funCode);
  356. OutputLog.TraceLog(LogPriority.Information,
  357. "Global",
  358. "OnTimedEvent end",
  359. "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  360. + " - " + date.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
  361. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  362. }
  363. }
  364. }
  365. */
  366. #endregion
  367. }
  368. }
  369. catch (Exception ex)
  370. {
  371. OutputLog.TraceLog(LogPriority.Error,
  372. "Global",
  373. "OnTimedEvent - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss"),
  374. ex.ToString(),
  375. LocalPath.LogExePath + "SAP_HEGII\\Error_");
  376. }
  377. finally
  378. {
  379. Timer_doing = false;
  380. }
  381. }
  382. #endregion
  383. protected void Session_Start(object sender, EventArgs e)
  384. {
  385. }
  386. protected void Application_BeginRequest(object sender, EventArgs e)
  387. {
  388. }
  389. protected void Application_AuthenticateRequest(object sender, EventArgs e)
  390. {
  391. }
  392. protected void Application_Error(object sender, EventArgs e)
  393. {
  394. //try
  395. //{
  396. // Logger.Error(
  397. //}
  398. //catch
  399. //{
  400. //}
  401. }
  402. protected void Session_End(object sender, EventArgs e)
  403. {
  404. }
  405. protected void Application_End(object sender, EventArgs e)
  406. {
  407. SAP_HEGII_Timer?.Dispose();
  408. SAP_HEGII_Timer = null;
  409. string lockerName = Timer_Loker?.LockerName;
  410. Timer_Loker = null;
  411. if (!string.IsNullOrEmpty(lockerName))
  412. {
  413. OutputLog.TraceLog(LogPriority.Information,
  414. "Global",
  415. "Application_End",
  416. "Timer End : " + lockerName,
  417. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  418. }
  419. }
  420. }
  421. }