EAPServiceWrapper.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. using System;
  2. using System.Reflection;
  3. using System.Configuration;
  4. using Autofac;
  5. using Bowin.Common.Log;
  6. using EMIS.CommonLogic.SystemServices;
  7. using EMIS.Entities;
  8. namespace EMIS.Services
  9. {
  10. #region 所有的服务工作接口 IServiceJob
  11. /// <summary>
  12. /// IServiceJob : 所有的服务工作接口
  13. /// </summary>
  14. public interface IServiceJob
  15. {
  16. string JobID { get; set; }
  17. string JobName { get; set; }
  18. Guid SchedulerID { get; set; }
  19. int MaxThreadSize { get; set; }
  20. bool IsDebug { get; set; }
  21. string CertFile { get; set; }
  22. void ExecuteJob();
  23. DateTime AllTimeBegin { get; set; }
  24. DateTime AllTimeEnd { get; set; }
  25. int AllUseSeconds { get; set; }
  26. string Desc { get; set; }
  27. }
  28. #endregion
  29. #region 所有Job的基类
  30. /// <summary>
  31. /// 所有Job的基类。
  32. /// </summary>
  33. public abstract class EAPServiceJob : IServiceJob
  34. {
  35. #region 实现IServiceJob接口
  36. private string _jobid = "";
  37. private string _jobname = "";
  38. private Guid _schedulerid = Guid.Empty;
  39. private int _MaxThreadSize = 1;
  40. private bool _isdubug = false;
  41. private string _certfile = "";
  42. DateTime _AllTimeBegin;
  43. DateTime _AllTimeEnd;
  44. int _AllUseSeconds;
  45. DateTime _OneScheduleTimeBegin;
  46. DateTime _OneScheduleTimeEnd;
  47. int _OneScheduleUseSeconds;
  48. bool _Successful;
  49. string _Desc;
  50. /// <summary>
  51. /// 任务ID
  52. /// </summary>
  53. public string JobID
  54. {
  55. get { return _jobid; }
  56. set { _jobid = value; }
  57. }
  58. /// <summary>
  59. /// 任务名称
  60. /// </summary>
  61. public string JobName
  62. {
  63. get { return _jobname; }
  64. set { _jobname = value; }
  65. }
  66. /// <summary>
  67. /// 执行ID
  68. /// </summary>
  69. public Guid SchedulerID
  70. {
  71. get { return _schedulerid; }
  72. set { _schedulerid = value; }
  73. }
  74. /// <summary>
  75. /// 子服务同时最大线程数
  76. /// </summary>
  77. public int MaxThreadSize
  78. {
  79. get { return _MaxThreadSize; }
  80. set { _MaxThreadSize = value; }
  81. }
  82. /// <summary>
  83. /// 是否调试状态
  84. /// </summary>
  85. public bool IsDebug
  86. {
  87. get { return _isdubug; }
  88. set { _isdubug = value; }
  89. }
  90. /// <summary>
  91. /// 证书文件
  92. /// </summary>
  93. public string CertFile
  94. {
  95. get { return this._certfile; }
  96. set { this._certfile = value; }
  97. }
  98. /// <summary>
  99. /// 总体执行开始时间
  100. /// </summary>
  101. public DateTime AllTimeBegin
  102. {
  103. get { return _AllTimeBegin; }
  104. set { _AllTimeBegin = value; }
  105. }
  106. /// <summary>
  107. /// 总体执行结束时间
  108. /// </summary>
  109. public DateTime AllTimeEnd
  110. {
  111. get { return _AllTimeEnd; }
  112. set { _AllTimeEnd = value; }
  113. }
  114. /// <summary>
  115. /// 总体服务执行耗时秒数
  116. /// </summary>
  117. public int AllUseSeconds
  118. {
  119. get { return _AllUseSeconds; }
  120. set { _AllUseSeconds = value; }
  121. }
  122. /// <summary>
  123. /// 单个服务执行开始时间
  124. /// </summary>
  125. public DateTime OneScheduleTimeBegin
  126. {
  127. get { return _OneScheduleTimeBegin; }
  128. set { _OneScheduleTimeBegin = value; }
  129. }
  130. /// <summary>
  131. /// 单个服务执行结束时间
  132. /// </summary>
  133. public DateTime OneScheduleTimeEnd
  134. {
  135. get { return _OneScheduleTimeEnd; }
  136. set { _OneScheduleTimeEnd = value; }
  137. }
  138. /// <summary>
  139. /// 单个服务执行耗时秒数
  140. /// </summary>
  141. public int OneScheduleUseSeconds
  142. {
  143. get { return _OneScheduleUseSeconds; }
  144. set { _OneScheduleUseSeconds = value; }
  145. }
  146. /// <summary>
  147. /// 是否执行成功
  148. /// </summary>
  149. public bool Successful
  150. {
  151. get { return _Successful; }
  152. set { _Successful = value; }
  153. }
  154. /// <summary>
  155. /// 执行结果备注信息
  156. /// </summary>
  157. public string Desc
  158. {
  159. get { return _Desc; }
  160. set { _Desc = value; }
  161. }
  162. #endregion
  163. #region 运行JOB
  164. public void RunJobOnce()
  165. {
  166. this.MyJob();
  167. }
  168. #endregion
  169. public virtual void ExecuteJob()
  170. {
  171. //起止配对;容易找起止。
  172. Guid tagID = Guid.NewGuid();
  173. try
  174. {
  175. this.Init();
  176. Desc = "服务【" + this._jobname + "】开始执行:{" + tagID.ToString() + "}";
  177. LogHelper.WriteLog(LogType.ServiceLog, Desc);
  178. //先置最后执行时间;防止多线程一次集中连续执行。
  179. using (var scop = Program.AutofacContainer.BeginLifetimeScope())
  180. {
  181. var ScheduleServices = scop.Resolve<IScheduleServices>();
  182. ScheduleServices.UpdateLastRun(SchedulerID);
  183. }
  184. this.MyJob();
  185. OneScheduleTimeEnd = System.DateTime.Now;
  186. TimeSpan ts = new TimeSpan();
  187. ts = OneScheduleTimeEnd - OneScheduleTimeBegin;
  188. OneScheduleUseSeconds = Convert.ToInt32(ts.TotalSeconds);
  189. Desc = "服务【" + this._jobname + "】结束执行;耗时:" + OneScheduleUseSeconds.ToString() + "秒。{" + tagID.ToString() + "}";
  190. LogHelper.WriteLog(LogType.ServiceLog, Desc);
  191. Successful = true;
  192. UpdateSchedulingLog(SchedulerID, JobID, OneScheduleTimeBegin, OneScheduleTimeEnd, OneScheduleUseSeconds,
  193. Successful, "执行成功");
  194. }
  195. catch (Exception err)
  196. {
  197. OneScheduleTimeEnd = System.DateTime.Now;
  198. Desc = "服务【" + this._jobname + "】执行异常:" + err.Message;
  199. TimeSpan ts = new TimeSpan();
  200. ts = OneScheduleTimeEnd - OneScheduleTimeBegin;
  201. OneScheduleUseSeconds = Convert.ToInt32(ts.TotalSeconds); //转换时间间隔为 秒
  202. LogHelper.WriteLog(LogType.ServiceLog, "服务【" + this._jobname + "】结束;耗时:" + OneScheduleUseSeconds.ToString() + "秒;{" + tagID.ToString() + "} \r\n 执行结果:\r\n " + Desc);
  203. Successful = true;
  204. UpdateSchedulingLog(SchedulerID, JobID, OneScheduleTimeBegin, OneScheduleTimeEnd, OneScheduleUseSeconds,
  205. Successful, "执行失败:" + err.Message);
  206. }
  207. finally
  208. {
  209. }
  210. }
  211. protected virtual bool Init()
  212. {
  213. Successful = true;
  214. AllTimeBegin = System.DateTime.Now;
  215. AllTimeEnd = System.DateTime.Now;
  216. AllUseSeconds = 0;
  217. OneScheduleTimeBegin = System.DateTime.Now;
  218. OneScheduleTimeEnd = System.DateTime.Now;
  219. OneScheduleUseSeconds = 0;
  220. Desc = "服务【" + this._jobname + "】开始执行:";
  221. return true;
  222. }
  223. protected abstract bool MyJob();
  224. #region 修改具体服务调度表中的执行信息,记录服务调度历史记录。
  225. /// <summary>
  226. /// 修改具体服务调度表中的执行信息,记录服务调度历史记录。
  227. /// </summary>
  228. public void UpdateSchedulingLog(Guid schedulerID, string jobID, DateTime scheduleTimeBegin, DateTime scheduleTimeEnd, int UseSeconds,
  229. bool successful, string desc)
  230. {
  231. try
  232. {
  233. using (var scop = Program.AutofacContainer.BeginLifetimeScope())
  234. {
  235. var ScheduleServices = scop.Resolve<IScheduleServices>();
  236. ScheduleServices.UpdateLastRunAndLoopNum(SchedulerID);
  237. Sys_ScheduleLog log = new Sys_ScheduleLog();
  238. log.scid = schedulerID;
  239. log.timeBegin = scheduleTimeBegin;
  240. log.timeEnd = scheduleTimeEnd;
  241. log.successful = successful;
  242. log.useSeconds = UseSeconds;
  243. log.Desc = desc;
  244. ScheduleServices.InsertLog(log);
  245. }
  246. }
  247. catch (Exception ce)
  248. {
  249. LogHelper.WriteLog(LogType.ServiceLog, "操作数据库异常:" + ce.Message);
  250. }
  251. }
  252. #endregion
  253. }
  254. #endregion
  255. #region ServiceWrapper的接口
  256. namespace MyEAPServiceWrapper
  257. {
  258. /// <summary>
  259. /// ServiceWrapper的接口。
  260. /// 开启多线程,并且控制每个子服务当前最多只有一个线程在执行;多个子服务可以同时执行;防止不同的子服务彼此相互堵塞。
  261. /// </summary>
  262. public interface IServiceWrapper
  263. {
  264. bool IsDebug { get; set; }
  265. bool Execute();
  266. }
  267. }
  268. #endregion
  269. #region EAPServiceWrapper
  270. namespace MyEAPServiceWrapper
  271. {
  272. /// <summary>
  273. /// ServiceWrapper的具体子服务执行。
  274. /// 开启多线程,并且控制每个子服务当前最多只有一个线程在执行;多个子服务可以同时执行;防止不同的子服务彼此相互堵塞。
  275. /// </summary>
  276. using System;
  277. using System.Collections.Generic;
  278. using System.Linq;
  279. using System.Data;
  280. public class ServiceWrapper : IServiceWrapper
  281. {
  282. #region 实现IServiceWrapper接口属性
  283. private bool _isdubug = false;
  284. DateTime _AllTimeBegin;
  285. DateTime _AllTimeEnd;
  286. int _AllUseSeconds;
  287. DateTime _OneScheduleTimeBegin;
  288. DateTime _OneScheduleTimeEnd;
  289. int _OneScheduleUseSeconds;
  290. bool _Successful;
  291. string _Desc;
  292. Guid SchedulerID = Guid.Empty;
  293. int MaxThreadSize = 1;
  294. string JobID = "";
  295. string JobName = "";
  296. string AssemName = "";
  297. string ClassName = "";
  298. /// <summary>
  299. /// 是否调试状态
  300. /// </summary>
  301. public bool IsDebug
  302. {
  303. get { return _isdubug; }
  304. set { _isdubug = value; }
  305. }
  306. /// <summary>
  307. /// 总体执行开始时间
  308. /// </summary>
  309. public DateTime AllTimeBegin
  310. {
  311. get { return _AllTimeBegin; }
  312. set { _AllTimeBegin = value; }
  313. }
  314. /// <summary>
  315. /// 总体执行结束时间
  316. /// </summary>
  317. public DateTime AllTimeEnd
  318. {
  319. get { return _AllTimeEnd; }
  320. set { _AllTimeEnd = value; }
  321. }
  322. /// <summary>
  323. /// 总体服务执行耗时秒数
  324. /// </summary>
  325. public int AllUseSeconds
  326. {
  327. get { return _AllUseSeconds; }
  328. set { _AllUseSeconds = value; }
  329. }
  330. /// <summary>
  331. /// 单个服务执行开始时间
  332. /// </summary>
  333. public DateTime OneScheduleTimeBegin
  334. {
  335. get { return _OneScheduleTimeBegin; }
  336. set { _OneScheduleTimeBegin = value; }
  337. }
  338. /// <summary>
  339. /// 单个服务执行结束时间
  340. /// </summary>
  341. public DateTime OneScheduleTimeEnd
  342. {
  343. get { return _OneScheduleTimeEnd; }
  344. set { _OneScheduleTimeEnd = value; }
  345. }
  346. /// <summary>
  347. /// 单个服务执行耗时秒数
  348. /// </summary>
  349. public int OneScheduleUseSeconds
  350. {
  351. get { return _OneScheduleUseSeconds; }
  352. set { _OneScheduleUseSeconds = value; }
  353. }
  354. /// <summary>
  355. /// 是否执行成功
  356. /// </summary>
  357. public bool Successful
  358. {
  359. get { return _Successful; }
  360. set { _Successful = value; }
  361. }
  362. /// <summary>
  363. /// 执行结果备注信息
  364. /// </summary>
  365. public string Desc
  366. {
  367. get { return _Desc; }
  368. set { _Desc = value; }
  369. }
  370. #endregion
  371. #region 子服务线程控制
  372. public class ThreadInfo
  373. {
  374. public int ManagedThreadId { get; set; }
  375. public string Name { get; set; }
  376. public bool IsAlive { get; set; }
  377. public DateTime StartTime { get; set; }
  378. }
  379. /// <summary>
  380. /// 存放当前正在执行的子服务线程信息
  381. /// </summary>
  382. static System.Collections.Generic.List<ThreadInfo> NowExecThreadsInfo = new System.Collections.Generic.List<ThreadInfo>();
  383. #endregion
  384. #region 整体控制执行服务
  385. /// <summary>
  386. /// 开启多线程,并且控制每个子服务当前最多只有一个线程在执行;多个子服务可以同时执行;防止不同的子服务彼此相互堵塞。
  387. /// </summary>
  388. /// <returns></returns>
  389. public bool Execute()
  390. {
  391. //AllTimeEnd = System.DateTime.Now;
  392. //Desc = "总体服务执行成功!";
  393. //TimeSpan ts = new TimeSpan();
  394. //ts = AllTimeEnd - AllTimeBegin;
  395. //AllUseSeconds = Convert.ToInt32(ts.TotalSeconds); //转换时间间隔为 秒
  396. //Log.WriteLog("总体服务结束;耗时:" + AllUseSeconds.ToString() + "秒; \r\n 执行结果:\r\n " + Desc);
  397. bool bResult = true;
  398. //string serverName = ConfigurationManager.AppSettings["ServerName"];
  399. var scheduleJobList = QureyScheduleJobs();
  400. foreach (var scheduleJob in scheduleJobList)
  401. {
  402. string sStartDate = scheduleJob.datebegin.ToString().Trim(); ;//20040707
  403. sStartDate = sStartDate.Substring(0, 4) + "-" + sStartDate.Substring(4, 2) + "-" + sStartDate.Substring(6, 2); //转换成2004-07-07
  404. DateTime tmpStartDate = System.Convert.ToDateTime(sStartDate);
  405. sStartDate = scheduleJob.dateend.ToString().Trim();
  406. sStartDate = sStartDate.Substring(0, 4) + "-" + sStartDate.Substring(4, 2) + "-" + sStartDate.Substring(6, 2); //转换成2004-07-07
  407. DateTime tmpEndDate = System.Convert.ToDateTime(sStartDate);
  408. int scinterval = scheduleJob.scinterval;
  409. /* D:天 H:小时 M:分钟 S:秒 */
  410. switch (scheduleJob.scmode.ToUpper())
  411. {
  412. case "D":
  413. scinterval = scheduleJob.scinterval * (60 * 60 * 24);
  414. //对于周期跨天的,要防止累计偏差而出现跳天现象(空出2分钟的柔韧空间值)。
  415. scinterval = scinterval - 120;
  416. break;
  417. case "H":
  418. scinterval = scheduleJob.scinterval * (60 * 60);
  419. break;
  420. case "M":
  421. scinterval = scheduleJob.scinterval * (60);
  422. break;
  423. //默认秒
  424. default:
  425. break;
  426. }
  427. this.SchedulerID = scheduleJob.scid;
  428. this.MaxThreadSize = 1;
  429. this.JobID = scheduleJob.Sys_ScheduleJob.jobid;
  430. this.JobName = scheduleJob.Sys_ScheduleJob.jobname;
  431. this.AssemName = scheduleJob.Sys_ScheduleJob.assemname;
  432. this.ClassName = scheduleJob.Sys_ScheduleJob.classname;
  433. //检查该项服务是否到了下次运行时间,如是则运行。
  434. if (this.CheckJobAllowRun(tmpStartDate, tmpEndDate, scinterval, scheduleJob.lastrun,
  435. scheduleJob.timefrom, scheduleJob.timeto))
  436. {
  437. //this.JobRun(tmpSchedulerID, tmpJobID,tmpServerName, tmpJobName, tmpAssemName, tmpClassName);
  438. System.Threading.Thread thread = new System.Threading.Thread(JobRun);
  439. thread.Start();
  440. //防止循环后再次获取数据库进行判断,而当前的验证还没有加入线程属性导致可能多1个子线程服务在运行;需要停顿一下。
  441. System.Threading.Thread.Sleep(3000);
  442. }
  443. }
  444. return bResult;
  445. }
  446. #endregion
  447. #region 检查是允许运行
  448. /// <summary>
  449. /// 检查任务是否允许运行
  450. /// </summary>
  451. /// <param name="StartDate"></param>
  452. /// <param name="EndDate"></param>
  453. /// <param name="SecondTiple"></param>
  454. /// <param name="LastUpdate"></param>
  455. /// <returns></returns>
  456. private bool CheckJobAllowRun(DateTime StartDate, DateTime EndDate, int SecondTiple, DateTime? LastUpdate, string StartTime, string EndTime)
  457. {
  458. DateTime nowday = new System.DateTime(System.DateTime.Now.Year, System.DateTime.Now.Month, System.DateTime.Now.Day);
  459. StartDate = new DateTime(StartDate.Year, StartDate.Month, StartDate.Day);
  460. EndDate = new DateTime(EndDate.Year, EndDate.Month, EndDate.Day);
  461. if ((nowday >= StartDate) && (nowday <= EndDate))
  462. {
  463. if (InRunTimeRange(StartTime, EndTime))
  464. {
  465. if ((ReturnSecondFromDate(System.DateTime.Now) - ReturnSecondFromDate(LastUpdate)) >= SecondTiple)
  466. return true;
  467. else
  468. return false;
  469. }
  470. else
  471. return false;
  472. }
  473. else
  474. {
  475. return false;
  476. }
  477. }
  478. /// <summary>
  479. /// 把日期转化为秒
  480. /// </summary>
  481. /// <param name="datetime1"></param>
  482. /// <returns></returns>
  483. private long ReturnSecondFromDate(DateTime? datetime1)
  484. {
  485. if (!datetime1.HasValue) return 0;
  486. return (long)((datetime1.Value.Year * 365 + datetime1.Value.DayOfYear) * 24 * 60 + datetime1.Value.Hour * 60 + datetime1.Value.Minute) * 60 + datetime1.Value.Second;
  487. }
  488. private bool InRunTimeRange(string StartTime, string EndTime)
  489. {
  490. int mHour = System.DateTime.Now.Hour;
  491. int mMinute = System.DateTime.Now.Minute;
  492. int mSecond = System.DateTime.Now.Second;
  493. string[] splStartTime = StartTime.Split(':');
  494. int mStartHour = Convert.ToInt32(splStartTime[0]);
  495. int mStartMinute = Convert.ToInt32(splStartTime[1]);
  496. int mStartSecond = Convert.ToInt32(splStartTime[2]);
  497. string[] splEndTime = EndTime.Split(':');
  498. int mEndHour = Convert.ToInt32(splEndTime[0]);
  499. int mEndMinute = Convert.ToInt32(splEndTime[1]);
  500. int mEndSecond = Convert.ToInt32(splEndTime[2]);
  501. int mCurrent = mHour * 60 * 60 + mMinute * 60 + mSecond;
  502. int mStart = mStartHour * 60 * 60 + mStartMinute * 60 + mStartSecond;
  503. int mEnd = mEndHour * 60 * 60 + mEndMinute * 60 + mEndSecond;
  504. if (mCurrent >= mStart && mCurrent <= mEnd)
  505. return true;
  506. return false;
  507. }
  508. #endregion
  509. #region 运行具体某个Job
  510. /// <summary>
  511. /// 运行服务工作,不返回错误以免将其他的工作也停止
  512. /// private void JobRun(string schedulerID, string jobID,string serverName, string jobName, string assemName, string className)
  513. /// </summary>
  514. /// <param name="SqlConn"></param>
  515. /// <param name="JobName"></param>
  516. /// <param name="ClassName"></param>
  517. private void JobRun()
  518. {
  519. Guid schedulerID = SchedulerID;
  520. int maxThreadSize = MaxThreadSize;
  521. string jobID = JobID;
  522. string jobName = JobName;
  523. string assemName = AssemName;
  524. string className = ClassName;
  525. bool thisTimeNeedDo = true;
  526. ThreadInfo threadInfo = new ThreadInfo();
  527. try
  528. {
  529. //判断检查该项服务对应的线程是否在运行。
  530. System.Threading.Thread currentSubServiceThread = System.Threading.Thread.CurrentThread;
  531. currentSubServiceThread.Name = className;
  532. //启动时间在6个钟内的线程才有效
  533. var currentSubServices = (from a in NowExecThreadsInfo
  534. where a.Name == className
  535. && a.StartTime > DateTime.Now.AddHours(-6)
  536. select new ThreadInfo
  537. {
  538. ManagedThreadId = a.ManagedThreadId,
  539. Name = a.Name,
  540. IsAlive = a.IsAlive,
  541. StartTime = a.StartTime
  542. }
  543. ).ToList();
  544. int currentSubServiceNum = currentSubServices.Count;
  545. LogHelper.WriteLog(LogType.ServiceLog, "当前【" + className + "】有个(" + currentSubServiceNum.ToString() + ")线程在执行。最大线程数:" + maxThreadSize.ToString() + ";时间:" + DateTime.Now.ToString());
  546. if (currentSubServiceNum >= maxThreadSize)
  547. {
  548. thisTimeNeedDo = false;
  549. LogHelper.WriteLog(LogType.ServiceLog, "当前【" + className + "】正已经有个(" + currentSubServiceNum.ToString() + ")线程在执行,本次跳过激发执行。" + DateTime.Now.ToString());
  550. }
  551. if (thisTimeNeedDo)
  552. {
  553. //加线程子服务信息
  554. threadInfo.ManagedThreadId = currentSubServiceThread.ManagedThreadId;
  555. threadInfo.Name = currentSubServiceThread.Name;
  556. threadInfo.IsAlive = currentSubServiceThread.IsAlive;
  557. threadInfo.StartTime = DateTime.Now;
  558. NowExecThreadsInfo.Add(threadInfo);
  559. string fullClassName = "";
  560. Assembly assem = Assembly.Load(assemName);
  561. if (className.IndexOf(".") > 0)
  562. {
  563. fullClassName = className;
  564. }
  565. else
  566. {
  567. fullClassName = assemName + "." + className;
  568. }
  569. //Log.WriteLog("TestHere01 " + fullClassName);
  570. Type classType = assem.GetType(fullClassName);
  571. IServiceJob fss = (IServiceJob)System.Activator.CreateInstance(classType);
  572. fss.SchedulerID = schedulerID;
  573. fss.JobID = jobID;
  574. fss.JobName = jobName;
  575. fss.IsDebug = this._isdubug;
  576. fss.CertFile = ConfigurationManager.AppSettings["CertFile"];
  577. fss.ExecuteJob(); //运行Job
  578. }
  579. }
  580. catch (Exception ce)
  581. {
  582. LogHelper.WriteLog(LogType.ServiceLog, "服务【" + jobName + "】执行异常:" + ce.Message);
  583. }
  584. finally
  585. {
  586. if (thisTimeNeedDo)
  587. {
  588. //处理完毕后清除线程子服务信息
  589. NowExecThreadsInfo.Remove(threadInfo);
  590. }
  591. }
  592. }
  593. #endregion
  594. #region 获取总体服务信息;然后处理那些需要执行的各个具体服务。
  595. /// <summary>
  596. /// 获取总体服务信息;然后处理那些需要执行的各个具体服务。
  597. /// </summary>
  598. public List<Sys_Scheduling> QureyScheduleJobs()
  599. {
  600. try
  601. {
  602. using (var scop = Program.AutofacContainer.BeginLifetimeScope())
  603. {
  604. var ScheduleServices = scop.Resolve<IScheduleServices>();
  605. return ScheduleServices.GetJobList();
  606. }
  607. }
  608. catch (Exception ce)
  609. {
  610. LogHelper.WriteLog(LogType.ServiceLog, "操作数据库异常:" + ce.Message);
  611. }
  612. finally
  613. {
  614. }
  615. return new List<Sys_Scheduling>();
  616. }
  617. #endregion
  618. }
  619. #endregion
  620. }
  621. }