Global.asax.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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.DataAccess;
  8. using Curtain.Log;
  9. using Dongke.IBOSS.PRD.Basics.BaseResources;
  10. using Dongke.IBOSS.PRD.Basics.DataAccess;
  11. using Dongke.IBOSS.PRD.Basics.Library;
  12. using Dongke.IBOSS.PRD.WCF.Services;
  13. using Dongke.IBOSS.PRD.WCF.ExHGS3QRS;
  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(ini.ReadIniData("SAP_HEGII", "Interval"));
  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/ExHGS3QR", new WebServiceHostFactory(), typeof(ExHGS3QR)
  161. )
  162. );
  163. RouteTable.Routes.Add
  164. (
  165. new ServiceRoute
  166. (
  167. "DKService/SAPDataService", new WebServiceHostFactory(), typeof(SAPDataService)
  168. )
  169. );
  170. RouteTable.Routes.Add
  171. (
  172. new ServiceRoute
  173. (
  174. "DKService/PPModuleService", new WebServiceHostFactory(), typeof(PPModuleService)
  175. )
  176. );
  177. }
  178. #region SAP_HEGII
  179. private class TimerLocker
  180. {
  181. public string LockerName = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff");
  182. }
  183. private static Timer SAP_HEGII_Timer = null;
  184. private static TimerLocker Timer_Loker = null;
  185. private static void InitSAP_HEGII(string interval)
  186. {
  187. try
  188. {
  189. if (string.IsNullOrWhiteSpace(interval))
  190. {
  191. return;
  192. }
  193. double intt = 60000;
  194. if (!double.TryParse(interval, out intt) || intt < 30000)
  195. {
  196. intt = 60000;
  197. }
  198. Timer_Loker = new TimerLocker();
  199. SAP_HEGII_Timer = new Timer();
  200. SAP_HEGII_Timer.Interval = intt;
  201. SAP_HEGII_Timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
  202. SAP_HEGII_Timer.AutoReset = true;
  203. SAP_HEGII_Timer.Enabled = true;
  204. OutputLog.TraceLog(LogPriority.Information,
  205. "Global",
  206. "Application_Start - InitSAP_HEGII",
  207. "Timer Started : " + Timer_Loker.LockerName + " - " + intt,
  208. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  209. }
  210. catch (Exception ex)
  211. {
  212. OutputLog.TraceLog(LogPriority.Error,
  213. "Global",
  214. "InitSAP_HEGII",
  215. ex.ToString(),
  216. LocalPath.LogExePath + "SAP_HEGII\\Error_");
  217. }
  218. }
  219. private static void OnTimedEvent(object source, ElapsedEventArgs e)
  220. {
  221. try
  222. {
  223. lock (Timer_Loker)
  224. {
  225. INIUtility ini = INIUtility.Instance(INIUtility.IniFile.Config);
  226. string nextDate = ini.ReadIniData("SAP_HEGII", "NextDate");
  227. string nextDate6002 = ini.ReadIniData("SAP_HEGII", "NextDate6002");
  228. if (!string.IsNullOrWhiteSpace(nextDate))
  229. {
  230. string byTime = ini.ReadIniData("SAP_HEGII", "ByTime");
  231. if (string.IsNullOrWhiteSpace(byTime))
  232. {
  233. byTime = "00:00";
  234. }
  235. //OutputLog.TraceLog(LogPriority.Information,
  236. // "Global",
  237. // "OnTimedEvent ",
  238. // "OnTimedEvent begin : " + nextDate + " - " + byTime,
  239. // LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  240. DateTime ndate;
  241. if (DateTime.TryParseExact(nextDate + " " + byTime, "yyyy-MM-dd HH:mm", null, DateTimeStyles.None, out ndate))
  242. {
  243. //DateTime date = e.SignalTime; //DateTime.Now;
  244. DateTime date = DateTime.Now;
  245. if (ndate <= date)
  246. {
  247. ini.WriteIniData("SAP_HEGII", "NextDate", date.AddDays(1).ToString("yyyy-MM-dd"));
  248. string funCode = ini.ReadIniData("SAP_HEGII", "FunCode");
  249. OutputLog.TraceLog(LogPriority.Information,
  250. "Global",
  251. "OnTimedEvent begin: " + funCode,
  252. "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  253. + " - " + date.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
  254. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  255. Service.SAPHegiiDataService.SAPDataLogic.AutoWorkDataToSAP(date, funCode);
  256. OutputLog.TraceLog(LogPriority.Information,
  257. "Global",
  258. "OnTimedEvent end",
  259. "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  260. + " - " + date.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
  261. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  262. }
  263. }
  264. }
  265. if (!string.IsNullOrWhiteSpace(nextDate6002))
  266. {
  267. DateTime ndate;
  268. if (DateTime.TryParseExact(nextDate6002, "yyyy-MM-dd HH:mm", null, DateTimeStyles.None, out ndate))
  269. {
  270. //DateTime date = e.SignalTime; //DateTime.Now;
  271. DateTime date = DateTime.Now;
  272. if (ndate <= date)
  273. {
  274. //ini.WriteIniData("SAP_HEGII", "NextDate6002", date.AddHours(1).ToString("yyyy-MM-dd HH:")+ ndate.ToString("mm"));
  275. ini.WriteIniData("SAP_HEGII", "NextDate6002", date.AddMinutes(20).ToString("yyyy-MM-dd HH:mm"));
  276. string funCode = "6002"; // ini.ReadIniData("SAP_HEGII", "FunCode");
  277. OutputLog.TraceLog(LogPriority.Information,
  278. "Global",
  279. "OnTimedEvent begin: " + funCode,
  280. "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  281. + " - " + date.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
  282. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  283. Service.SAPHegiiDataService.SAPDataLogic.AutoWorkDataToSAP(date, funCode);
  284. OutputLog.TraceLog(LogPriority.Information,
  285. "Global",
  286. "OnTimedEvent end",
  287. "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  288. + " - " + date.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
  289. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  290. }
  291. }
  292. }
  293. }
  294. }
  295. catch (Exception ex)
  296. {
  297. OutputLog.TraceLog(LogPriority.Error,
  298. "Global",
  299. "OnTimedEvent - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss"),
  300. ex.ToString(),
  301. LocalPath.LogExePath + "SAP_HEGII\\Error_");
  302. }
  303. }
  304. #endregion
  305. protected void Session_Start(object sender, EventArgs e)
  306. {
  307. }
  308. protected void Application_BeginRequest(object sender, EventArgs e)
  309. {
  310. }
  311. protected void Application_AuthenticateRequest(object sender, EventArgs e)
  312. {
  313. }
  314. protected void Application_Error(object sender, EventArgs e)
  315. {
  316. //try
  317. //{
  318. // Logger.Error(
  319. //}
  320. //catch
  321. //{
  322. //}
  323. }
  324. protected void Session_End(object sender, EventArgs e)
  325. {
  326. }
  327. protected void Application_End(object sender, EventArgs e)
  328. {
  329. SAP_HEGII_Timer?.Dispose();
  330. SAP_HEGII_Timer = null;
  331. string lockerName = Timer_Loker?.LockerName;
  332. Timer_Loker = null;
  333. if (!string.IsNullOrEmpty(lockerName))
  334. {
  335. OutputLog.TraceLog(LogPriority.Information,
  336. "Global",
  337. "Application_End",
  338. "Timer End : " + lockerName,
  339. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  340. }
  341. }
  342. }
  343. }