/// <summary>
        /// Schedule job with trigger to underlying service collection. This API maybe change!
        /// </summary>
        public static IServiceCollectionQuartzConfigurator ScheduleJob <T>(
            this IServiceCollectionQuartzConfigurator configurator,
            Action <IServiceCollectionTriggerConfigurator> trigger,
            Action <IServiceCollectionJobConfigurator>?job = null) where T : IJob
        {
            if (trigger is null)
            {
                throw new ArgumentNullException(nameof(trigger));
            }

            var jobConfigurator = new ServiceCollectionJobConfigurator(configurator.Services);
            var jobDetail       = ConfigureAndBuildJobDetail <T>(jobConfigurator, job);

            configurator.Services.AddTransient(x => jobDetail);
            configurator.Services.AddTransient(jobDetail.JobType);

            var triggerConfigurator = new ServiceCollectionTriggerConfigurator(configurator.Services);

            triggerConfigurator.ForJob(jobDetail);

            trigger.Invoke(triggerConfigurator);
            var t = triggerConfigurator.Build();

            if (t.JobKey is null || !t.JobKey.Equals(jobDetail.Key))
            {
                throw new InvalidOperationException("Trigger doesn't refer to job being scheduled");
            }

            configurator.Services.AddTransient(x => t);

            return(configurator);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds LibLog configuration to use Microsoft's logging abstraction instead of trying to find one.
        /// </summary>
        public static IServiceCollectionQuartzConfigurator AddTrigger(
            this IServiceCollectionQuartzConfigurator configurator,
            Action <IServiceCollectionTriggerConfigurator>?configure = null)
        {
            var c = new ServiceCollectionTriggerConfigurator(configurator.Services);

            configure?.Invoke(c);
            var trigger = c.Build();

            configurator.Services.AddTransient(x => trigger);

            return(configurator);
        }
        /// <summary>
        /// Add trigger to underlying service collection. This API maybe change!
        /// </summary>
        public static IServiceCollectionQuartzConfigurator AddTrigger(
            this IServiceCollectionQuartzConfigurator configurator,
            Action <IServiceCollectionTriggerConfigurator>?configure = null)
        {
            var c = new ServiceCollectionTriggerConfigurator(configurator.Services);

            configure?.Invoke(c);
            var trigger = c.Build();

            if (trigger.JobKey is null)
            {
                throw new InvalidOperationException("Trigger hasn't been associated with a job");
            }

            configurator.Services.AddTransient(x => trigger);

            return(configurator);
        }