在安排 Quartz.NET 作业详细信息后修改它们

发布于 2024-09-28 13:18:41 字数 2027 浏览 3 评论 0原文

我有一个 Quartz.NET 应用程序,我需要管理员能够修改作业详细信息 - 主要是每个作业数据图中的信息,还有触发器之类的内容 - 这是我正在使用的代码

   protected void ButtonSubmit_Click(object sender, EventArgs e)
    {
        JobDetail jobDetail = sched.GetJobDetail(hdnID.Value, hdnGroupID.Value);
        jobDetail.JobDataMap["idname"] = txtName.Text;
        jobDetail.JobDataMap["initialPath"] = TextBox1.Text;
        jobDetail.JobDataMap["targetPath"] = TextBox2.Text;
        jobDetail.JobDataMap["regex"] = TextBox3.Text;
        jobDetail.JobDataMap["overrideemails"] = txtEmails.Text;
        jobDetail.JobDataMap["flush"] = chkflush.Checked;
        jobDetail.JobDataMap["impUsername"] = txtImpUsername.Text;
        jobDetail.JobDataMap["impDomain"] = txtImpDomain.Text;
        jobDetail.JobDataMap["impPassword"] = txtImpPassword.Text;
        Trigger[] triggers = sched.GetTriggersOfJob(hdnID.Value, hdnGroupID.Value);

        if (ddlScheduleType.SelectedIndex == 0)
        {
            foreach (SimpleTrigger trigger in triggers.OfType<SimpleTrigger>())
            {
                if (ddlInterval.SelectedIndex == 0)
                {
                    trigger.RepeatInterval = TimeSpan.Parse("00:00:01");
                }
                else if (ddlInterval.SelectedIndex == 1)
                {
                    trigger.RepeatInterval = TimeSpan.Parse("00:01:00");
                }
                else if (ddlInterval.SelectedIndex == 2)
                {
                    trigger.RepeatInterval = TimeSpan.Parse("00:00:01");
                }
            }
        }

        else
        {
            foreach (CronTrigger trigger in triggers.OfType<CronTrigger>())
            {
                trigger.CronExpressionString = txtCron.Text;

            }
        }


    }

(我知道我在做什么)使用 foreach 循环是愚蠢的,但工作中只有一个触发器,这是我在这里收到的一段代码)。

问题是,页面回发正常,并且新值仍然保留在文本框中。但当我再次查看这份工作时,一切都没有变化。我做错了什么?这很令人困惑,因为根本没有错误。

请注意,隐藏字段也已正确设置。

谢谢

ButtonSubmit_Click 事件肯定可以正常工作,因为我已经调试了程序并且程序也经历了这一过程。

I have a Quartz.NET application where I need the administrators to be able to modify the job details - mostly information in each jobs datamap, but also things like the triggers - here is my code I'm using

   protected void ButtonSubmit_Click(object sender, EventArgs e)
    {
        JobDetail jobDetail = sched.GetJobDetail(hdnID.Value, hdnGroupID.Value);
        jobDetail.JobDataMap["idname"] = txtName.Text;
        jobDetail.JobDataMap["initialPath"] = TextBox1.Text;
        jobDetail.JobDataMap["targetPath"] = TextBox2.Text;
        jobDetail.JobDataMap["regex"] = TextBox3.Text;
        jobDetail.JobDataMap["overrideemails"] = txtEmails.Text;
        jobDetail.JobDataMap["flush"] = chkflush.Checked;
        jobDetail.JobDataMap["impUsername"] = txtImpUsername.Text;
        jobDetail.JobDataMap["impDomain"] = txtImpDomain.Text;
        jobDetail.JobDataMap["impPassword"] = txtImpPassword.Text;
        Trigger[] triggers = sched.GetTriggersOfJob(hdnID.Value, hdnGroupID.Value);

        if (ddlScheduleType.SelectedIndex == 0)
        {
            foreach (SimpleTrigger trigger in triggers.OfType<SimpleTrigger>())
            {
                if (ddlInterval.SelectedIndex == 0)
                {
                    trigger.RepeatInterval = TimeSpan.Parse("00:00:01");
                }
                else if (ddlInterval.SelectedIndex == 1)
                {
                    trigger.RepeatInterval = TimeSpan.Parse("00:01:00");
                }
                else if (ddlInterval.SelectedIndex == 2)
                {
                    trigger.RepeatInterval = TimeSpan.Parse("00:00:01");
                }
            }
        }

        else
        {
            foreach (CronTrigger trigger in triggers.OfType<CronTrigger>())
            {
                trigger.CronExpressionString = txtCron.Text;

            }
        }


    }

(I know what I'm doing with the foreach loops is stupid, but there is only ever one trigger with a job and it's a snippet of code I recieved here).

Problem is, the page posts back fine and the new values still stay in the textboxes. But when I go view the job again, nothing changes at all. What am I doing wrong? It's confusing as there are no errors at all.

Note the hiddenfields are also correctly set.

Thanks

The ButtonSubmit_Click event is certainly working as I've debugged the program and the program goes through that.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

椒妓 2024-10-05 13:18:41

通过调用 sched.GetTriggersOfJob 和 sched.GetJobDetail 获得的实例是真实触发器/作业的克隆。
在您重新安排更改的触发器或使用更改的触发器添加更改的作业之前,调度程序不会使用您对这些对象的更改。

我认为您应该能够使用 RescheduleJob 如果您只更改触发器,则可以 删除原始触发器和添加一个新的。

The instance you get by calling sched.GetTriggersOfJob and sched.GetJobDetail are clones of the real triggers / jobs.
Your changes to those objects are not used by the scheduler until you reschedule the changed trigger or add a the changed job with the changed trigger.

I think you should be able to use RescheduleJob if you only change the triggers and you could remove the original trigger and add a new one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文