public static JobDataModel ToDataModel(JobDTO jobDTO, JobApplicationDTO jobApplicationDTO, JobApplicationStateDTO jobApplicationStateDTO)
        {
            JobDataModel model = new JobDataModel();

            model.JobID       = jobDTO.JobID;
            model.BusinessID  = jobDTO.BusinessID;
            model.Title       = jobDTO.Title;
            model.Description = jobDTO.Description;
            model.JobTypeID   = jobDTO.JobTypeID;
            model.IsActive    = jobDTO.IsActive;
            model.IsDeleted   = jobDTO.IsDeleted;
            model.StartDate   = jobDTO.StartDate;
            model.EndDate     = jobDTO.EndDate;
            model.insuser     = jobDTO.insuser;
            model.insdt       = jobDTO.insdt;
            model.upduser     = jobDTO.upduser;
            model.upddt       = jobDTO.upddt;

            model.JobApplicationID = jobApplicationDTO.JobApplicationID;
            model.ApplicantUserID  = jobApplicationDTO.ApplicantUserID;
            model.ApplicationDate  = jobApplicationDTO.ApplicationDate;

            model.JobApplicationStateID  = jobApplicationStateDTO.JobApplicationStateID;
            model.JobApplicationStatusID = jobApplicationStateDTO.JobApplicationStatusID;

            return(model);
        }
        public static JobDataModel ToDataModel(JobDTO jobDTO, JobApplicationDTO jobApplicationDTO, JobApplicationStateDTO jobApplicationStateDTO)
        {
            JobDataModel model = new JobDataModel();

            model.JobID = jobDTO.JobID;
            model.BusinessID = jobDTO.BusinessID;
            model.Title = jobDTO.Title;
            model.Description = jobDTO.Description;
            model.JobTypeID = jobDTO.JobTypeID;
            model.IsActive = jobDTO.IsActive;
            model.IsDeleted = jobDTO.IsDeleted;
            model.StartDate = jobDTO.StartDate;
            model.EndDate = jobDTO.EndDate;
            model.insuser = jobDTO.insuser;
            model.insdt = jobDTO.insdt;
            model.upduser = jobDTO.upduser;
            model.upddt = jobDTO.upddt;

            model.JobApplicationID = jobApplicationDTO.JobApplicationID;
            model.ApplicantUserID = jobApplicationDTO.ApplicantUserID;
            model.ApplicationDate = jobApplicationDTO.ApplicationDate;

            model.JobApplicationStateID = jobApplicationStateDTO.JobApplicationStateID;
            model.JobApplicationStatusID = jobApplicationStateDTO.JobApplicationStatusID;

            return model;
        }
        public bool UpdateHttpJob(JobParamHttpModel job)
        {
            try
            {
                JobKey       jobKey  = CreateJobKey(job.JobName, job.JobGroupName);
                var          jobData = _scheduler.GetJobDetail(jobKey).GetAwaiter().GetResult();
                JobDataModel model   = new JobDataModel();
                model.CallbackUrl    = jobData.JobDataMap[JobConfig.CallbackUrl].ToString();
                model.CallbackParams = JobUtils.GetDictFromString(jobData.JobDataMap[JobConfig.CallbackParams].ToString());

                bool isSameParams = IsSameParam(job, model);
                if (isSameParams)
                {
                    return(ModifyJobCron(job));
                }
                else
                {
                    bool bl = DeleteJob(job);
                    if (bl)
                    {
                        return(AddHttpJob(job));
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            return(false);
        }
Beispiel #4
0
 public bool UpdateHttpJob(JobParamHttpModel job)
 {
     try
     {
         JobKey       jobKey       = CreateJobKey(job.JobName, job.JobGroupName);
         JobDataModel jobData      = Xml.XmlJobManage.GetJobDataByKey(jobKey);
         bool         isSameParams = IsSameParam(job, jobData);
         if (isSameParams)
         {
             return(ModifyJobCron(job));
         }
         else
         {
             bool bl = DeleteJob(job);
             if (bl)
             {
                 return(AddHttpJob(job));
             }
         }
     }
     catch (Exception ex)
     {
         logger.Error(ex);
     }
     return(false);
 }
Beispiel #5
0
 public Task ScheduleJobAsync(string jobId, JobDataModel jobData)
 {
     return(requestFactory.PostRequest(RoutePrefix)
            .AddUrlSegment(jobId)
            .AddBody(jobData)
            .PostAsync());
 }
Beispiel #6
0
        public List <KeyValueModel> GetJobParaList(string jobName, string jobGroupName)
        {
            List <KeyValueModel> list = new List <KeyValueModel>();

            try
            {
                JobKey jobKey = CreateJobKey(jobName, jobGroupName);

                JobDataModel jobData = Xml.XmlJobManage.GetJobDataByKey(jobKey);
                if (jobData == null || jobData.CallbackParams == null)
                {
                    return(list);
                }

                foreach (var item in jobData.CallbackParams)
                {
                    KeyValueModel model = new KeyValueModel();
                    model.key   = item.Key;
                    model.value = item.Value;
                    list.Add(model);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }

            return(list);
        }
Beispiel #7
0
        public JobRegistrar(ISchedulerClient schedulerClient, IJob job)
        {
            this.schedulerClient = schedulerClient;

            this.job = job;
            jobData  = job.GetJobDataModel();
        }
        public void UpsertJobV2_AddNewUniqueJobWithNewJobType()
        {
            //Arrange
            var messageList = new List <string>();
            var newJob      = new JobDataModel
            {
                Id     = null,
                Name   = "New Unique Job #2",
                Type   = "Roofing",
                Date   = DateTime.Parse("2018-04-02"),
                Amount = 1250.00M
            };

            //Act
            var newId = SqlData.UpsertJobV2(newJob, out messageList);

            _outputHelper.WriteLine("[INFO] {0}", messageList.FirstOrDefault());
            _outputHelper.WriteLine("[INFO] New job created with Id = {0}", newId?.ToString() ?? "null");

            //Assert
            Assert.NotNull(newId);
            Assert.Single(messageList);
            var message = messageList.Count > 0 ? messageList.First() : string.Empty;

            Assert.Equal("A new Job Type [Roofing] was created.", message);
        }
Beispiel #9
0
        public void UpsertJob_AddNewJobWithDuplicateName() // must run UpsertJob_AddNewUniqueJob() before this test
        {
            //Arrange
            var newJob = new JobDataModel
            {
                Id     = null,
                Name   = "New Unique Job #1",
                Type   = "Plumbing",
                Date   = DateTime.Parse("2018-04-02"),
                Amount = 725.00M
            };

            //Act & Assert
            int?newId        = null;
            var sqlException = Assert.Throws <SqlException>(() =>
            {
                newId = SqlData.UpsertJob(newJob);
            });

            _outputHelper.WriteLine("What your log will see...");
            var message = _outputHelper.LogExceptionAccordingly(sqlException)
                          ?? "Generic error message.";

            _outputHelper.WriteLine("What your user will see...");
            _outputHelper.WriteLine(message);

            //Assert
            Assert.Null(newId);
            Assert.Equal(14, sqlException.Class);
            Assert.Equal(1, sqlException.State);
            Assert.Equal("Generic error message.", message);
            Assert.Contains("Cannot insert duplicate key row", sqlException.Message);
        }
Beispiel #10
0
        public static int?UpsertJobV3(JobDataModel job, out List <string> outMessageList)
        {
            outMessageList = new List <string>();
            var messageList = new List <string>(); // need local holding list for InfoMessage event handler

            using (var conn = new SqlConnection(_connectionString))
            {
                conn.Open();

                conn.InfoMessage += (sender, args) =>
                {
                    messageList.Add(args.Message);
                };

                using (var cmd = new SqlCommand("dbo.UpsertJobV3", conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    var idOutPram = SqlParameterHelper.CreateInputOutputIntParameter("job_id", job.Id);
                    cmd.Parameters.Add(idOutPram);
                    cmd.Parameters.AddWithValue("job_name", job.Name);
                    cmd.Parameters.AddWithValue("job_type_name", job.Type);
                    cmd.Parameters.AddWithValue("job_date", job.Date);
                    cmd.Parameters.AddWithValue("job_amount", job.Amount);

                    cmd.ExecuteNonQuery();

                    outMessageList.AddRange(messageList);

                    return(idOutPram.Value as int?);
                }
            }
        }
Beispiel #11
0
        public async Task ScheduleJob([FromUri] string id, JobDataModel jobData)
        {
            if (jobData == null)
            {
                throw new ArgumentNullException(nameof(jobData));
            }

            await schedulerService.ScheduleJobAsync(id, jobData);
        }
Beispiel #12
0
        public async Task ScheduleJob(string jobGroup, string id, [FromBody] JobDataModel jobData)
        {
            if (jobData == null)
            {
                throw new ArgumentNullException(nameof(jobData));
            }

            await schedulerService.ScheduleJobAsync(jobGroup, id, jobData);
        }
Beispiel #13
0
        public JobDataModel GetJob(JobDTO oJobDTO)
        {
            JobDataModel oJobDataModel = null;

            if (oJobDTO != null)
            {
                oJobDataModel = JobDataModelAssembler.ToDataModel(oJobsBL.Get(oJobDTO.JobID), null, null);
            }
            return(oJobDataModel);
        }
Beispiel #14
0
 private Task RegisterJobAsync()
 {
     return(schedulerClient.ScheduleJobAsync(JobId, new JobDataModel
     {
         SdkVersion = SchedulerClientConfig.Version,
         Settings = JobDataModel.SerializeSettings(GetJobSettings()),
         ScheduleType = scheduleType,
         ScheduleSettings = JobDataModel.SerializeSettings(GetScheduleSettings())
     }));
 }
Beispiel #15
0
 JobDataModel IJob.GetJobDataModel()
 {
     return(new JobDataModel
     {
         SdkVersion = SchedulerClientConfig.Version,
         Settings = JobDataModel.SerializeSettings(GetJobSettings()),
         ScheduleType = scheduleType,
         ScheduleSettings = JobDataModel.SerializeSettings(GetScheduleSettings())
     });
 }
        public static ITrigger Create(JobKey key, JobDataModel data)
        {
            switch (data.ScheduleType)
            {
            case ScheduleType.Recurrent: return(CreateRecurrentTrigger(key, JobDataModel.DeserializeSettings <RecurrentScheduleSettingsModel>(data.ScheduleSettings)));

            case ScheduleType.Cron: return(CreateCronTrigger(key, JobDataModel.DeserializeSettings <CronScheduleSettingsModel>(data.ScheduleSettings)));

            default: throw new NotSupportedException();
            }
        }
        public static IJobDetail Create(JobKey key, JobDataModel data)
        {
            var jobDetail = JobBuilder.Create <WebRequestJob>()
                            .WithIdentity(key)
                            .StoreDurably()
                            .Build();

            jobDetail.SetJobData(data);

            return(jobDetail);
        }
Beispiel #18
0
        /// <summary>
        /// Registers reporter job if it doesn't exist. If it already exist, do nothing
        /// </summary>
        /// <param name="job">The job.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public JobDataModel RegisterDeporterJob(JobDataModel job)
        {
            var query  = Query.And(Query.EQ("JobName", job.JobName));
            var update = Update <JobDataModel>
                         .SetOnInsert(c => c.JobName, job.JobName)
                         .SetOnInsert(c => c.CreateDateTime, job.CreateDateTime)
                         .SetOnInsert(c => c.LastRunDateTime, job.LastRunDateTime);

            WriteConcernResult wr = _jobCollection.Update(query, update, UpdateFlags.Upsert);

            return(_jobCollection.FindOne(query));
        }
 public static JobApplicationDTO TojobApplicationDTO(JobDataModel datamodel)
 {
     JobApplicationDTO dto = new JobApplicationDTO();
     if (datamodel != null)
     {
         dto.JobApplicationID = datamodel.JobApplicationID;
         dto.ApplicantUserID = datamodel.ApplicantUserID;
         dto.ApplicationDate = datamodel.ApplicationDate;
         dto.JobID = datamodel.JobID;
     }
     return dto;
 }
 public static JobApplicationStateDTO ToJobApplicationStateDTO(JobDataModel datamodel)
 {
     JobApplicationStateDTO dto = new JobApplicationStateDTO();
     if (datamodel != null)
     {
         dto.JobApplicationStatusID = datamodel.JobApplicationStatusID;
         dto.JobApplicationStateID = datamodel.JobApplicationStateID;
         dto.insdt = datamodel.JobApplicationinsdt;
         dto.insuser = datamodel.JobApplicationinsuser;
         dto.JobApplicationID = datamodel.JobApplicationID;
     }
     return dto;
 }
        public static JobApplicationDTO TojobApplicationDTO(JobDataModel datamodel)
        {
            JobApplicationDTO dto = new JobApplicationDTO();

            if (datamodel != null)
            {
                dto.JobApplicationID = datamodel.JobApplicationID;
                dto.ApplicantUserID  = datamodel.ApplicantUserID;
                dto.ApplicationDate  = datamodel.ApplicationDate;
                dto.JobID            = datamodel.JobID;
            }
            return(dto);
        }
Beispiel #22
0
        public bool RunAtOnce(string jobName, string jobGroupName)
        {
            try
            {
                JobKey jobKey = CreateJobKey(jobName, jobGroupName);

                JobDataModel jobData = Xml.XmlJobManage.GetJobDataByKey(jobKey);
                if (jobData == null)
                {
                    return(false);
                }

                JobKey jobKeyOnce = CreateJobKey(jobName, JobConfig.JobGroupNameOnce);

                var type = typeof(HttpJob);

                if (jobData.JobType == JobType.Assembly)
                {
                    string   path     = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, jobData.AssemblyDllName);
                    Assembly assembly = Assembly.LoadFile(path);
                    type = assembly.GetType(jobData.TypeFullName);
                }

                var bl = _scheduler.CheckExists(jobKeyOnce).GetAwaiter().GetResult();
                if (bl)
                {
                    _scheduler.DeleteJob(jobKeyOnce);
                }
                IJobDetail jobDetail = JobBuilder.Create(type)
                                       .WithIdentity(jobKeyOnce)
                                       .UsingJobData(JobConfig.CallbackUrl, jobData.CallbackUrl)
                                       .UsingJobData(JobConfig.CallbackParams, JobUtils.GetDictToString(jobData.CallbackParams))
                                       .Build();

                DateTimeOffset startTime = DateBuilder.NextGivenSecondDate(null, 2);
                ITrigger       trigger   = TriggerBuilder.Create()
                                           .WithIdentity(JobConfig.GetTriggerNameOnce(jobName), JobConfig.TriggerGroupNameOnce)
                                           .StartAt(startTime)
                                           .Build();

                _scheduler.ScheduleJob(jobDetail, trigger).GetAwaiter().GetResult();
                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }

            return(false);
        }
        public static JobApplicationStateDTO ToJobApplicationStateDTO(JobDataModel datamodel)
        {
            JobApplicationStateDTO dto = new JobApplicationStateDTO();

            if (datamodel != null)
            {
                dto.JobApplicationStatusID = datamodel.JobApplicationStatusID;
                dto.JobApplicationStateID  = datamodel.JobApplicationStateID;
                dto.insdt            = datamodel.JobApplicationinsdt;
                dto.insuser          = datamodel.JobApplicationinsuser;
                dto.JobApplicationID = datamodel.JobApplicationID;
            }
            return(dto);
        }
Beispiel #24
0
        public JobDataModel GetJob(int id)
        {
            JobDataModel model = new JobDataModel();

            if (id > 0)
            {
                JobDTO oJobDTO = oJobsBL.Get(id);

                if (oJobDTO != null)
                {
                    model = GetJob(oJobDTO);
                }
            }

            return(model);
        }
Beispiel #25
0
        public JobDataModel UpdateJob(JobDataModel oJobDataModel)
        {
            if (oJobDataModel != null)
            {
                JobDTO oJobDTO = new JobDTO();

                oJobDTO = JobDataModelAssembler.ToJobDTO(oJobDataModel);

                if (oJobDTO != null)
                {
                    oJobDTO = oJobsBL.Update(oJobDTO);
                }
            }

            return(oJobDataModel);
        }
        /// <summary>
        /// 参数是否相同
        /// </summary>
        /// <returns></returns>
        protected bool IsSameParam(JobParamHttpModel job, JobDataModel data)
        {
            string map = JobUtils.GetDictToString(data.CallbackParams);

            string newParam = JobUtils.GetDictToString(job.CallbackParams);

            if (data.CallbackUrl != job.CallbackUrl)
            {
                return(false);
            }

            if (map.ToString() != newParam)
            {
                return(false);
            }

            return(true);
        }
        public async Task ScheduleJobAsync(string jobId, JobDataModel jobData)
        {
            if (!SchedulerClientConfig.Version.Equals(jobData.SdkVersion))
            {
                throw new ApiValidationException("Invalid SDK version");
            }

            invalidatedEvent.WaitOne();

            var jobKey = JobKey.Create(jobId);

            using (await jobLockProvider.AcquireAsync(jobKey))
            {
                if (await scheduler.CheckJobExistsAsync(jobKey))
                {
                    var existingJobDetail = await scheduler.GetJobDetailAsync(jobKey);

                    if (jobData.GetDataHashCode().Equals(existingJobDetail.GetDataHashCode()))
                    {
                        Log.Debug("{jobId} job is up to date", jobId);
                        return;
                    }

                    Log.Debug("{jobId} job will be updated", jobId);

                    await scheduler.DeleteJobAsync(jobKey);

                    Log.Information("{jobId} job was deleted", jobKey.Name);
                }

                var newJobDetail = JobDetailFactory.Create(jobKey, jobData);
                await scheduler.CreateJobAsync(newJobDetail);

                Log.Information("{jobId} job was created", jobId);

                var newTrigger      = TriggerFactory.Create(jobKey, jobData);
                var firstFireMoment = await scheduler.CreateTriggerAsync(newTrigger);

                Log.Information($"{{jobId}} job was scheduled (next execution: {firstFireMoment})", jobId);
            }
        }
Beispiel #28
0
        /// <summary>
        /// Registers the job with agent information
        /// </summary>
        /// <param name="job">The job.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">Error saving job:  + job.JobName +  - + job.AgentId.ToString()</exception>
        public JobDataModel RegisterJobCumAgent(JobDataModel job)
        {
            var query  = Query.And(Query.EQ("JobName", job.JobName), Query.EQ("AgentId", job.AgentId));
            var update = Update <JobDataModel>
                         .Set(c => c.AgentId, job.AgentId)
                         .Set(c => c.JobName, job.JobName)
                         .Set(c => c.CreateDateTime, DateTime.UtcNow)
                         .Set(c => c.LastRunDateTime, DateTime.UtcNow)
                         .Set(c => c.Limit, job.Limit);

            WriteConcernResult wr = _jobCollection.Update(query, update, UpdateFlags.Upsert);

            if (wr.DocumentsAffected >= 1)
            {
                return(_jobCollection.FindOne(query));
            }
            else
            {
                throw new Exception("Error saving job: " + job.JobName + " - " + job.AgentId.ToString());
            }
        }
 public static JobDTO ToJobDTO(JobDataModel datamodel)
 {
     JobDTO dto = new JobDTO();
     if (datamodel != null)
     {
         dto.JobID = datamodel.JobID;
         dto.BusinessID = datamodel.BusinessID;
         dto.Title = datamodel.Title;
         dto.Description = datamodel.Description;
         dto.JobTypeID = datamodel.JobTypeID;
         dto.IsActive = datamodel.IsActive;
         dto.IsDeleted = datamodel.IsDeleted;
         dto.StartDate = datamodel.StartDate;
         dto.EndDate = datamodel.EndDate;
         dto.insuser = datamodel.insuser;
         dto.insdt = datamodel.insdt;
         dto.upduser = datamodel.upduser;
         dto.upddt = datamodel.upddt;
     }
     return dto;
 }
        public static JobDTO ToJobDTO(JobDataModel datamodel)
        {
            JobDTO dto = new JobDTO();

            if (datamodel != null)
            {
                dto.JobID       = datamodel.JobID;
                dto.BusinessID  = datamodel.BusinessID;
                dto.Title       = datamodel.Title;
                dto.Description = datamodel.Description;
                dto.JobTypeID   = datamodel.JobTypeID;
                dto.IsActive    = datamodel.IsActive;
                dto.IsDeleted   = datamodel.IsDeleted;
                dto.StartDate   = datamodel.StartDate;
                dto.EndDate     = datamodel.EndDate;
                dto.insuser     = datamodel.insuser;
                dto.insdt       = datamodel.insdt;
                dto.upduser     = datamodel.upduser;
                dto.upddt       = datamodel.upddt;
            }
            return(dto);
        }
Beispiel #31
0
        public void UpsertJobV3_AddNewJobWithDuplicateName()
        {
            //Arrange
            var messageList = new List <string>();
            var newJob      = new JobDataModel
            {
                Id     = null,
                Name   = "New Unique Job #1",
                Type   = "Plumbing",
                Date   = DateTime.Parse("2018-04-02"),
                Amount = 725.00M
            };

            //Act & Assert
            int?         newId        = null;
            string       message      = null;
            SqlException sqlException = null;

            try
            {
                newId = SqlData.UpsertJobV3(newJob, out messageList);
            }
            catch (Exception e)
            {
                message = _outputHelper.LogExceptionAccordingly(e)
                          ?? "Generic error message.";

                sqlException = e as SqlException;
            }

            //Assert
            Assert.Null(newId);
            Assert.NotNull(sqlException);
            Assert.Equal(12, sqlException.Class);
            Assert.Equal(255, sqlException.State);
            Assert.Empty(messageList);
            Assert.Equal("A Job with name [New Unique Job #1] already exists.", message);
        }
Beispiel #32
0
        public static int?UpsertJob(JobDataModel job)
        {
            using (var conn = new SqlConnection(_connectionString))
            {
                conn.Open();

                using (var cmd = new SqlCommand("dbo.UpsertJob", conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    var idOutPram = SqlParameterHelper.CreateInputOutputIntParameter("job_id", job.Id);
                    cmd.Parameters.Add(idOutPram);
                    cmd.Parameters.AddWithValue("job_name", job.Name);
                    cmd.Parameters.AddWithValue("job_type_name", job.Type);
                    cmd.Parameters.AddWithValue("job_date", job.Date);
                    cmd.Parameters.AddWithValue("job_amount", job.Amount);

                    cmd.ExecuteNonQuery();

                    return(idOutPram.Value as int?);
                }
            }
        }
Beispiel #33
0
        public void UpsertJob_AddNewUniqueJob()
        {
            // reset database for test
            SqlData.DeleteJob("New Unique Job #1");

            //Arrange
            var newJob = new JobDataModel
            {
                Id     = null,
                Name   = "New Unique Job #1",
                Type   = "Electrical",
                Date   = DateTime.Parse("2018-04-01"),
                Amount = 125.00M
            };

            //Act
            var newId = SqlData.UpsertJob(newJob);

            _outputHelper.WriteLine("[INFO] New job created with Id = {0}",
                                    newId?.ToString() ?? "null");

            //Assert
            Assert.NotNull(newId);
        }
 public static TJobSettings GetSettings <TJobSettings>(this IJobDetail job)
     where TJobSettings : class
 {
     return(JobDataModel.DeserializeSettings <TJobSettings>(job.TryToReadDataMapString(DataMapKeys.Settings)));
 }