Пример #1
0
        public JobExecutionHistory CreateJobExecutionHistory(JobData job)
        {
            BackgroundWorkerJobExecutionHistory history = new BackgroundWorkerJobExecutionHistory
            {
                AbsoluteTimeout = job.AbsoluteTimeout,
                CreatedDate     = job.CreatedDate,
                Instance        = job.Instance,
                JobUniqueId     = job.UniqueId,
                Data            = job.Data,
                EndDateTime     = job.LastEndTime,
                ErrorMessage    = job.LastErrorMessage,
                JobId           = job.Id,
                MetaData        = job.MetaData,
                QueueId         = job.QueueId,
                StartDateTime   = job.LastStartTime ?? DateTime.Now,
                StatusId        = (int)job.Status,
                Success         = job.Status == JobStatus.Done,
                Type            = job.JobType.AssemblyQualifiedName,
                Application     = job.Application,
                Group           = job.Group,
                Name            = job.Name,
                Description     = job.Description,
            };

            using (Linq2SqlJobStoreDalDataContext context = new Linq2SqlJobStoreDalDataContext(connectionString))
            {
                context.BackgroundWorkerJobExecutionHistories.InsertOnSubmit(history);
                try
                {
                    context.SubmitChanges(System.Data.Linq.ConflictMode.FailOnFirstConflict);
                    return(new JobExecutionHistory
                    {
                        AbsoluteTimeout = history.AbsoluteTimeout,
                        Application = history.Application,
                        CreatedDate = history.CreatedDate,
                        Data = history.Data,
                        Description = history.Description,
                        EndTime = history.EndDateTime,
                        ErrorMessage = history.ErrorMessage,
                        Group = history.Group,
                        Id = history.Id,
                        Instance = history.Instance,
                        JobId = history.JobId,
                        JobType = Type.GetType(history.Type),
                        JobUniqueId = history.JobUniqueId,
                        MetaData = history.MetaData,
                        Name = history.Name,
                        QueueId = history.QueueId,
                        StartTime = history.StartDateTime,
                        Status = (JobStatus)history.StatusId,
                        Success = history.Success ?? false,
                    });
                }
                catch (Exception ex)
                {
                    logger.Error(string.Format("Failed to submit changes to the database."), ex);
                }
            }
            return(null);
        }
 partial void DeleteBackgroundWorkerJobExecutionHistory(BackgroundWorkerJobExecutionHistory instance);
 partial void InsertBackgroundWorkerJobExecutionHistory(BackgroundWorkerJobExecutionHistory instance);