コード例 #1
0
        public SystemJobParametersStepViewModel(IRepositoryFactory<IAppConfigRepository> repositoryFactory, IAppConfigEntityFactory entityFactory, IViewModelsFactory<IAddParameterViewModel> vmFactory, SystemJob item)
            : base(repositoryFactory, entityFactory, vmFactory, item)
		{
		}
コード例 #2
0
        private void AddJob(IScheduler scheduler, SystemJob jobItem, Func<Type, IJobActivity> getJob)
        {
            var jobKey = new JobKey(jobItem.SystemJobId, jobItem.JobClassType);
            var type = Type.GetType(jobItem.JobClassType, true);

            // Define the Job to be scheduled
            var quartzJobDetail = JobBuilder.Create(typeof(QuartzJob))
                .WithIdentity(jobKey)
                .RequestRecovery()
                .Build();

            Func<IJobActivity> jobActivityConstructor = () => getJob(type);

            Func<DateTime, Action<string>> getAudit = startDateTime =>
                message => _schedulerDbTools.CreateSystemJobLogEntry(
                jobItem.SystemJobId, startDateTime, DateTime.Now, message,
                Thread.CurrentThread.Name, null, jobItem.AllowMultipleInstances);

            var section = ConfigurationManager.GetSection("traceContextConfiguration") ?? new TraceContextConfigurationSection();
            ITraceContextConfigurator config = (TraceContextConfigurationSection)section;
            var contextName = new ContextName(type.FullName, "");
            var configuration = config.GetDefault(contextName.Service, contextName.Method);
            var traceSource = new TraceSource("VirtoCommerce.ScheduleService.Trace");
            var traceContext = new TraceContext(configuration, contextName, Guid.NewGuid(), traceSource);

            quartzJobDetail.JobDataMap.Add("realization", jobActivityConstructor);
            quartzJobDetail.JobDataMap.Add("getAudit", getAudit);
            quartzJobDetail.JobDataMap.Add("context", traceContext);
            quartzJobDetail.JobDataMap.Add("parameters", jobItem.JobParameters.ToDictionary(pk => pk.Name.ToLowerInvariant(), pv => pv.Value));

            // Associate a trigger with the Job
            var trigger = TriggerBuilder.Create()
                .WithIdentity(jobItem.SystemJobId, jobItem.JobClassType)
                .WithSimpleSchedule(x =>
                {
                    x.WithInterval(TimeSpan.FromSeconds(jobItem.Period));
                    x.RepeatForever();
                })
                .StartAt(DateTime.UtcNow)
                .WithPriority(jobItem.Priority)
                .Build();

            // Validate that the job doesn't already exists
            if (scheduler.CheckExists(jobKey))
            {
                scheduler.DeleteJob(jobKey);
            }
            scheduler.ScheduleJob(quartzJobDetail, trigger);
        }
コード例 #3
0
		public CreateSystemJobViewModel(IViewModelsFactory<ISystemJobOverviewStepViewModel> overviewVmFactory, IViewModelsFactory<ISystemJobParametersStepViewModel> parametersVmFactory, SystemJob item)
		{
			RegisterStep(overviewVmFactory.GetViewModelInstance(new KeyValuePair<string, object>("item", item)));
			RegisterStep(parametersVmFactory.GetViewModelInstance(new KeyValuePair<string, object>("item", item)));
		}