Global.asax.cs 14 KB

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