/// <summary> /// Run all process in list /// </summary> /// <param name="list"></param> /// <param name="callback"></param> /// <param name="BatchDate"></param> public static void RunBatchAll(List <BatchProcessRunAll_Result> list, BatchWriteLogDel callback, DateTime BatchDate) { ISchedulerFactory schedFact = new StdSchedulerFactory(); IScheduler sched = schedFact.GetScheduler(); sched.Start(); try { JobDetail jobDetail = new JobDetail("SECOM_AJIS_BatchAll", null, typeof(ProcessJobList)); jobDetail.JobDataMap["BatchList"] = list; jobDetail.JobDataMap["UserId"] = list[0].BatchUser; jobDetail.JobDataMap["BatchDate"] = BatchDate; jobDetail.JobDataMap["WriteLog"] = callback; //Modify by Phoomsak L. 2012-11-15 Change time span from 1 to 12 //Modify by Phoomsak L. 2012-12-19 Change repeat count from 1 to 0 Trigger trigger2 = TriggerUtils.MakeImmediateTrigger(0, new TimeSpan(12, 0, 0)); trigger2.Name = "ExecuteBatchImmediate"; sched.ScheduleJob(jobDetail, trigger2); } catch (Exception) { sched.Shutdown(); throw; } }
/// <summary> /// Process - execute all batch process /// </summary> public void RunProcessAll() { ILogHandler handLog = ServiceContainer.GetService <ILogHandler>() as ILogHandler; handLog.WriteWindowLog(EventType.C_EVENT_TYPE_INFORMATION, LogMessage.C_LOG_NIGHT_BATCH_START, EventID.C_EVENT_ID_BATCH_START); List <GetBatchProcessRunAll_Result> list = new List <GetBatchProcessRunAll_Result>(); List <BatchProcessRunAll_Result> jobList = new List <BatchProcessRunAll_Result>(); list = base.GetBatchProcessRunAll(); DateTime?batchDate = DateTime.Now; foreach (GetBatchProcessRunAll_Result p in list) { BatchProcessRunAll_Result r = CommonUtil.CloneObject <GetBatchProcessRunAll_Result, BatchProcessRunAll_Result>(p); r.BatchUser = CommonUtil.dsTransData.dtUserData.EmpNo; r.BatchDate = batchDate; jobList.Add(r); // Narupon 10-Sep-2012 base.UpdateBatchResult( p.BatchCode , BatchStatus.C_BATCH_STATUS_BE_PROCESSED , null , 0 , 0 , 0 , CommonUtil.dsTransData.dtUserData.EmpNo); } BatchWriteLogDel callback = new BatchWriteLogDel(this.BatchUpdateResult); BatchProcessUtil.RunBatchAll(jobList, callback, DateTime.Now); }
public void Execute(JobExecutionContext context) { JobDataMap dataMap = context.JobDetail.JobDataMap; List <BatchProcessRunAll_Result> list = (List <BatchProcessRunAll_Result>)dataMap.Get("BatchList"); string UserId = dataMap.GetString("UserId"); DateTime BatchDate = dataMap.GetDateTime("BatchDate"); BatchWriteLogDel writeLog = (BatchWriteLogDel)dataMap.Get("WriteLog"); try { //=== start 'run batch all' === doBatchProcessResult allResult_start = new doBatchProcessResult(); allResult_start.BatchName = "Run All Batch"; allResult_start.BatchUser = UserId; allResult_start.BatchStatus = BatchStatus.C_BATCH_STATUS_PROCESSING; allResult_start.BatchCode = "AL"; allResult_start.BatchJobName = ""; allResult_start.BatchDate = DateTime.Now; writeLog(allResult_start); foreach (BatchProcessRunAll_Result s in list) { doBatchProcessResult result = CommonUtil.CloneObject <BatchProcessRunAll_Result, doBatchProcessResult>(s); try { string[] batchJobName = s.BatchJobName.Split(','); string assemblyName = batchJobName[0]; string typeName = assemblyName + '.' + batchJobName[1]; result.BatchStatus = BatchStatus.C_BATCH_STATUS_PROCESSING; writeLog(result); Assembly assembly = Assembly.Load(assemblyName + ", Version=0.0.0.0, PublicKeyToken=null,Culture=neutral"); Type type = assembly.GetType(typeName); IBatchProcess process = (IBatchProcess)Activator.CreateInstance(type); result = process.WorkProcess(UserId, BatchDate); // == add by Narupon == result.BatchCode = s.BatchCode; result.BatchName = s.BatchName; result.BatchJobName = s.BatchJobName; result.BatchDate = DateTime.Now; if (result.Result) { result.BatchStatus = BatchStatus.C_BATCH_STATUS_SUCCEEDED; } else { result.BatchStatus = BatchStatus.C_BATCH_STATUS_FAILED; } // == (end) add by Narupon == result.BatchUser = UserId; writeLog(result); } catch (Exception ex) { result.ErrorMessage += string.Format("Error: {0} {1}\n", ex.Message, ex.InnerException != null ? ex.InnerException.Message : ""); result.BatchStatus = BatchStatus.C_BATCH_STATUS_FAILED; writeLog(result); } } //=== finish 'run batch all' === doBatchProcessResult allResult_finish = new doBatchProcessResult(); allResult_finish.BatchName = "Run All Batch"; allResult_finish.BatchUser = UserId; allResult_finish.BatchStatus = BatchStatus.C_BATCH_STATUS_SUCCEEDED; allResult_finish.BatchCode = "AL"; allResult_finish.BatchJobName = ""; allResult_finish.BatchDate = DateTime.Now; writeLog(allResult_finish); } catch (Exception ex) { doBatchProcessResult errorResult = new doBatchProcessResult(); errorResult.BatchCode = null; errorResult.ErrorMessage = ex.Message; errorResult.BatchUser = UserId; errorResult.BatchStatus = BatchStatus.C_BATCH_STATUS_FAILED; writeLog(errorResult); throw ex; } finally { context.Scheduler.Shutdown(); } }