Global.asax.cs 14 KB

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