コード例 #1
0
        public JobStatus Process()
        {
            int           jobCount   = 0;
            dlxTaskResult taskResult = dlxTaskResult.SuccessResult();
            JobStatus     jobStatus  = JobStatus.DlxSuccessResult();
            Job           jobLog     = new Job();

            jobLog.JobType     = FtpConfigurationType.Announcement.ToString();
            jobLog.TriggeredBy = this.RunBy;
            int jobId = _service.JobLog(jobLog);

            jobStatus.JobId = jobId;
            string runingTask      = string.Empty;
            int    recordsImported = 0;

            foreach (var task in _tasks)
            {
                jobCount++;
                runingTask = task.Name;
                if (taskResult.IsSuccess)
                {
                    task.PreviousTaskResult = taskResult;
                    task.Execute(jobId);
                    taskResult = task.GetTaskResult();
                }
                else
                {
                    jobStatus.Success = false;
                    //jobLog.Status = false;
                    jobLog.Description = "Job fails due to" + " " + taskResult.ErrorMessage;
                    break;
                }

                if (taskResult.TaskData != null)
                {
                    if (!string.IsNullOrEmpty(taskResult.TaskData.FilePath) && string.IsNullOrEmpty(jobLog.FileName))
                    {
                        string filePath = taskResult.TaskData.FilePath;
                        jobLog.FileName = filePath.Substring(filePath.LastIndexOf("/") + 1);
                    }
                    if (taskResult.TaskData.NoOfRecordImported > 0)
                    {
                        recordsImported = taskResult.TaskData.NoOfRecordImported;
                    }
                }
            }

            jobLog.Status      = jobStatus.Success;
            jobLog.Description = jobStatus.Success ? "Job completed successfully" : string.Format("Job failed due to {0} task failed", runingTask);
            jobLog.Id          = jobId;
            _service.UpdateJobLog(jobLog);

            #region Previous Code
            //foreach (var task in _tasks)
            //{
            //    jobCount++;
            //    if (taskResult.IsSuccess)
            //    {
            //        task.PreviousTaskResult = taskResult;
            //        task.Execute(jobId);
            //        taskResult = task.GetTaskResult();
            //        //System.Threading.Thread.Sleep(2000);
            //        if (jobCount == _tasks.Count() && taskResult.IsSuccess)
            //        {
            //            jobLog.Status = true;
            //            jobLog.Description = "Job Successfully Completed";
            //            jobLog.Id = jobId;
            //            _service.UpdateJobLog(jobLog);
            //        }
            //        if (jobCount == _tasks.Count() && !taskResult.IsSuccess)
            //        {
            //            jobLog.Status = false;
            //            jobLog.Description = "Job fails due to" + " " + taskResult.ErrorMessage;
            //            jobLog.Id = jobId;
            //            _service.UpdateJobLog(jobLog);
            //        }
            //    }
            //    else
            //    {
            //        jobLog.Status = false;
            //        jobLog.Description = "Job fails due to" + " " + taskResult.ErrorMessage;
            //        jobLog.Id = jobId;
            //        _service.UpdateJobLog(jobLog);
            //        break;
            //    }
            //}
            #endregion

            jobStatus.FileName            = jobLog.FileName;
            jobStatus.NoOfRecordsImported = recordsImported;
            return(jobStatus);
        }