Global.asax.cs 14 KB

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