开发者

Spring.Net Programmatic vs XML Configuration

If I define the objects in XML and call var xmlApplicationContext = new XmlApplicationContext() the job is scheduled and fires. What I would like to accomplish is to do this through code as the properties will be dynamic, the method fragment below compiles and runs but the job is not scheduled. Is this possible?

// SpringJob.xml

<objects xmlns="http://www.springframework.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <object name="emailNotification" type="Spring.Scheduling.Quartz.JobDetailObject, Spring.Scheduling.Quartz">
            <property name="JobType" value="Project.Agent.Jobs.EmailNotification, Project.Agent" />
        </object>
        <object id="simpleTrigger" type="Spring.Scheduling.Quartz.SimpleTriggerObject, Spring.Scheduling.Quartz">
            <property name="jobDetail" ref="emailNotification" />
            <property name="startDelay" value="1s" />
            <property name="repeatInterval" value="1s" />
            <property name="repeatCount" value="0" />
        </object>
        <object type="Spring.Scheduling.Quartz.SchedulerFactoryObject, Spring.Scheduling.Quartz">
            <property name="triggers">
                <list>
                    <ref object="simpleTrigger" />
                </list>
            </property>
        </object>
</objects>

// Method

 var jobDetailObject = new JobDetailObject
                                              {
                                                  JobType = new EmailNotification().GetType()
                                              };

    var simpleTrigger = new SimpleTriggerObject
                            {
                                JobDetail = jobDetailObject,
                                StartDelay = new TimeSpan(0, 0, 0, 1),
                                RepeatInterval = new TimeSpan(0, 0, 0, 1),
                                RepeatCount = 0
          开发者_StackOverflow                  };

    var scheduleTrigger = new SchedulerFactoryObject();
    var triggers = new Trigger[1];
    triggers[0] = simpleTrigger;
    scheduleTrigger.Triggers = triggers;
    scheduleTrigger.Start();


Decided to abandon the Spring.Net framework implementation of Quartz.Net instead I am using Quartz.Net directly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜