Global.asax.cs 18 KB

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