public static void Apply(NWGameObject player) { var playerID = _.GetGlobalID(player); var jobType = _.GetClassByPosition(ClassPosition.First, player); var jobDefinition = JobRegistry.Get(jobType); var job = JobRepo.Get(playerID, jobType); var abilityList = jobDefinition.GetAbilityListByLevel(job.Level); var allFeats = new List <Feat>(DefaultFeats); allFeats.AddRange(abilityList); // Remove any feats the player shouldn't have. var featCount = NWNXCreature.GetFeatCount(player); for (int x = featCount; x >= 0; x--) { var feat = NWNXCreature.GetFeatByIndex(player, x - 1); if (!allFeats.Contains(feat)) { NWNXCreature.RemoveFeat(player, feat); } } // Add any feats the player needs. foreach (var feat in allFeats) { if (_.GetHasFeat(feat, player)) { continue; } NWNXCreature.AddFeatByLevel(player, feat, 1); } }
/// <summary> /// @see IJobOperator#Stop . /// </summary> /// <param name="executionId"></param> /// <returns></returns> /// <exception cref="NoSuchJobException"> </exception> /// <exception cref="JobExecutionNotRunningException"> </exception> public bool Stop(long executionId) { JobExecution jobExecution = FindExecutionById(executionId); // Indicate the execution should be stopped by setting it's status to // 'STOPPING'. It is assumed that // the step implementation will check this status at chunk boundaries. BatchStatus status = jobExecution.Status; if (!(status == BatchStatus.Started || status == BatchStatus.Starting)) { throw new JobExecutionNotRunningException( string.Format("JobExecution must be running so that it can be stopped: {0}", jobExecution)); } jobExecution.Status = BatchStatus.Stopping; JobRepository.Update(jobExecution); try { IJob job = JobRegistry.GetJob(jobExecution.JobInstance.JobName); var locator = job as IStepLocator; if (locator != null) { //can only process as StepLocator is the only way to get the step object //get the current stepExecution foreach (StepExecution stepExecution in jobExecution.StepExecutions) { if (stepExecution.BatchStatus.IsRunning()) { try { //have the step execution that's running -> need to 'stop' it IStep step = locator.GetStep(stepExecution.StepName); var taskletStep = step as TaskletStep; if (taskletStep != null) { ITasklet tasklet = taskletStep.Tasklet; var stoppableTasklet = tasklet as IStoppableTasklet; if (stoppableTasklet != null) { StepSynchronizationManager.Register(stepExecution); stoppableTasklet.Stop(); StepSynchronizationManager.Release(); } } } catch (NoSuchStepException e) { _logger.Warn("Step not found {0}", e.Message); } } } } } catch (NoSuchJobException e) { _logger.Warn("Cannot find Job object {0}", e.Message); } return(true); }
/// <summary> /// @see IJobOperator#Start . /// </summary> /// <param name="jobName"></param> /// <param name="parameters"></param> /// <returns></returns> /// <exception cref="NoSuchJobException"> </exception> /// <exception cref="JobInstanceAlreadyExistsException"> </exception> /// <exception cref="JobParametersInvalidException"> </exception> public long?Start(string jobName, string parameters) { _logger.Info("Checking status of job with name= {0}", jobName); JobParameters jobParameters = _jobParametersConverter.GetJobParameters(PropertiesConverter.StringToProperties(parameters)); if (JobRepository.IsJobInstanceExists(jobName, jobParameters)) { throw new JobInstanceAlreadyExistsException(string.Format("Cannot start a job instance that already exists with name={0} and parameters={1}", jobName, parameters)); } IJob job = JobRegistry.GetJob(jobName); _logger.Info("Attempting to launch job with name={0} and parameters={1}", jobName, parameters); try { return(JobLauncher.Run(job, jobParameters).Id); } catch (JobExecutionAlreadyRunningException e) { throw new UnexpectedJobExecutionException(string.Format(IllegalStateMsg, "job execution already running", jobName, parameters), e); } catch (JobRestartException e) { throw new UnexpectedJobExecutionException(string.Format(IllegalStateMsg, "job not restartable", jobName, parameters), e); } catch (JobInstanceAlreadyCompleteException e) { throw new UnexpectedJobExecutionException(string.Format(IllegalStateMsg, "job already complete", jobName, parameters), e); } }
public override void Initialize() { var jobs = JobRegistry.GetAll(); foreach (var job in jobs) { AddResponseToPage("MainPage", job.CallSign, true, job.Class); } }
/// <summary> /// @see IJobOperator#GetJobInstances . /// </summary> /// <param name="jobName"></param> /// <param name="start"></param> /// <param name="count"></param> /// <returns></returns> /// <exception cref="NoSuchJobExecutionException"> </exception> public IList <long?> GetJobInstances(string jobName, int start, int count) { IList <JobInstance> jobInstances = JobExplorer.GetJobInstances(jobName, start, count); IList <long?> list = jobInstances.Select(jobInstance => jobInstance.Id).ToList(); if (!list.Any() && !JobRegistry.GetJobNames().Contains(jobName)) { throw new NoSuchJobException(string.Format("No such job (either in registry or in historical data): {0}", jobName)); } return(list); }
public IActionResult Reminder(int courseId, int day) { var userId = Convert.ToInt32(userManager.GetUserId(User)); var user = unitOfWork.GetRepository <User>().Get(s => s.Id == userId).FirstOrDefault(); var course = unitOfWork.GetRepository <Course>().Get(s => s.Id == courseId).FirstOrDefault(); var jobRegistry = new JobRegistry(user.Email, course.Name, course + "is going start", course.StartDate.AddDays(-day), this.emailOptions); JobManager.Initialize(new JobRegistry(user.Email, course.Name, course + "is going start", course.StartDate.AddDays(-day), this.emailOptions)); return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, "OK")); }
/// <summary> /// @see IJobOperator#StartNextInstance . /// </summary> /// <param name="jobName"></param> /// <returns></returns> /// <exception cref="NoSuchJobException"> </exception> /// <exception cref="JobParametersNotFoundException"> </exception> /// <exception cref="UnexpectedJobExecutionException"> </exception> /// <exception cref="JobParametersInvalidException"> </exception> public long?StartNextInstance(string jobName) { _logger.Info("Locating parameters for next instance of job with name={0}", jobName); IJob job = JobRegistry.GetJob(jobName); IList <JobInstance> lastInstances = JobExplorer.GetJobInstances(jobName, 0, 1); IJobParametersIncrementer incrementer = job.JobParametersIncrementer; if (incrementer == null) { throw new JobParametersNotFoundException( string.Format("No job parameters incrementer found for job={0}", jobName)); } JobParameters parameters; if (!lastInstances.Any()) { parameters = incrementer.GetNext(new JobParameters()); if (parameters == null) { throw new JobParametersNotFoundException( string.Format("No bootstrap parameters found for job={0}", jobName)); } } else { IList <JobExecution> lastExecutions = JobExplorer.GetJobExecutions(lastInstances.First()); parameters = incrementer.GetNext(lastExecutions.First().JobParameters); } _logger.Info("Attempting to launch job with name={0} and parameters={1}", jobName, parameters); try { return(JobLauncher.Run(job, parameters).Id); } catch (JobExecutionAlreadyRunningException e) { throw new UnexpectedJobExecutionException(string.Format(IllegalStateMsg, "job already running", jobName, parameters), e); } catch (JobRestartException e) { throw new UnexpectedJobExecutionException(string.Format(IllegalStateMsg, "job not restartable", jobName, parameters), e); } catch (JobInstanceAlreadyCompleteException e) { throw new UnexpectedJobExecutionException(string.Format(IllegalStateMsg, "job instance already complete", jobName, parameters), e); } }
/// <summary> /// @see IJobOperator#GetRunningExecutions . /// </summary> /// <param name="jobName"></param> /// <returns></returns> /// <exception cref="NoSuchJobException"> </exception> public ICollection <long?> GetRunningExecutions(string jobName) { // SLE: OrderedSet is not a ISet: must return a Collection (Interface changed for that purpose) ICollection <long?> set = new OrderedSet <long?>(); foreach (JobExecution jobExecution in JobExplorer.FindRunningJobExecutions(jobName)) { set.Add(jobExecution.Id); } if (!set.Any() && !JobRegistry.GetJobNames().Contains(jobName)) { throw new NoSuchJobException(string.Format("No such job (either in registry or in historical data): {0}", jobName)); } return(set); }
protected static void Recalculate(NWGameObject player) { var playerID = GetGlobalID(player); var playerEntity = PlayerRepo.Get(playerID); var @class = GetClassByPosition(ClassPosition.First, player); var level = GetLevelByPosition(ClassPosition.First, player); var jobDefinition = JobRegistry.Get(@class); // Retrieve the rating chart for the stat, then retrieve the value for that stat at this player's level. var hp = RatingRegistry.Get(jobDefinition.HPRating).Get(RatingStat.HP, level); var mp = RatingRegistry.Get(jobDefinition.MPRating).Get(RatingStat.MP, level); var ac = RatingRegistry.Get(jobDefinition.ACRating).Get(RatingStat.AC, level); var bab = RatingRegistry.Get(jobDefinition.BABRating).Get(RatingStat.BAB, level); var str = RatingRegistry.Get(jobDefinition.STRRating).Get(RatingStat.STR, level); var dex = RatingRegistry.Get(jobDefinition.DEXRating).Get(RatingStat.DEX, level); var con = RatingRegistry.Get(jobDefinition.CONRating).Get(RatingStat.CON, level); var wis = RatingRegistry.Get(jobDefinition.WISRating).Get(RatingStat.WIS, level); var @int = RatingRegistry.Get(jobDefinition.INTRating).Get(RatingStat.INT, level); var cha = RatingRegistry.Get(jobDefinition.CHARating).Get(RatingStat.CHA, level); // Now apply the changes to the player. ApplyHP(player, hp); playerEntity.MaxHP = hp; playerEntity.MaxMP = mp; playerEntity.HP = hp; playerEntity.MP = mp; NWNXCreature.SetBaseAC(player, ac); NWNXCreature.SetBaseAttackBonus(player, bab); NWNXCreature.SetRawAbilityScore(player, Ability.Strength, str); NWNXCreature.SetRawAbilityScore(player, Ability.Dexterity, dex); NWNXCreature.SetRawAbilityScore(player, Ability.Constitution, con); NWNXCreature.SetRawAbilityScore(player, Ability.Wisdom, wis); NWNXCreature.SetRawAbilityScore(player, Ability.Intelligence, @int); NWNXCreature.SetRawAbilityScore(player, Ability.Charisma, cha); PlayerRepo.Set(playerEntity); DelayCommand(1.0f, () => NWNXPlayer.UpdateCharacterSheet(player)); }
/// <summary> /// @see IJobOperator#Restart . /// </summary> /// <param name="executionId"></param> /// <returns></returns> /// <exception cref="JobInstanceAlreadyCompleteException"> </exception> /// <exception cref="NoSuchJobExecutionException"> </exception> /// <exception cref="NoSuchJobException"> </exception> /// <exception cref="JobRestartException"> </exception> /// <exception cref="JobParametersInvalidException"> </exception> public long?Restart(long executionId) { _logger.Info("Checking status of job execution with id= {0}", executionId); JobExecution jobExecution = FindExecutionById(executionId); string jobName = jobExecution.JobInstance.JobName; IJob job = JobRegistry.GetJob(jobName); JobParameters parameters = jobExecution.JobParameters; _logger.Info("Attempting to resume job with name={0} and parameters={1}", jobName, parameters); try { return(JobLauncher.Run(job, parameters).Id); } catch (JobExecutionAlreadyRunningException e) { throw new UnexpectedJobExecutionException(string.Format(IllegalStateMsg, "job execution already running", jobName, parameters), e); } }
public static void Main() { AbilityRegistry.Register(); JobRegistry.Register(); RatingRegistry.Register(); }
/// <summary> /// @see IJobOperator#GetJobNames . /// </summary> /// <returns></returns> public ISet <string> GetJobNames() { return(new SortedSet <string>(JobRegistry.GetJobNames())); }