tags:

views:

22

answers:

1

Hi all, I need to be able to get the properties (i.e. cron expression or type of simple trigger (daily, hourly, etc) and it's parameters) of a trigger in C#, and display them and also let them be modified. I have this right now:

Trigger[] trigger = sched.GetTriggersOfJob(id, groupid);

But I can't find any methods to let me access this information. Any ideas?

A: 

How about

Trigger[] triggers = sched.GetTriggersOfJob(id, groupid);
foreach (SimpleTrigger simpleTrigger in triggers.OfType<SimpleTrigger>())
{
   //extract simple trigger info
}

foreach (CronTrigger cronTrigger in triggers.OfType<CronTrigger>())
{
  //extract cron trigger info
}

If efficiency is important, you can also do this in one loop:

Trigger[] triggers = sched.GetTriggersOfJob(id, groupid);
foreach (var trigger in triggers)
{
   SimpleTrigger simpleTrigger = trigger as SimpleTrigger;
   if (simpleTrigger != null)
   {
     //handle simple trigger
     continue;
   }
   //same for CronTrigger...
}
ohadsc
Thanks buddy, it's telling me that 'No overload for OfType takes 1 arguements' though
Chris
@Chris My mistake, it should work now. The more efficient solution should work anyway though.
ohadsc
Awesome, thanks :) one other, probably dumb issue - how do I go about extracting the trigger info? The trigger variable doesn't give me any more options for accessing the type of simple trigger, cron expression etc
Chris
The variable has all you need, I've edited the code to make it more apparent. whatever info you need can be gotten at: http://quartznet.sourceforge.net/apidoc/topic604.html and http://quartznet.sourceforge.net/apidoc/topic286.html
ohadsc
Ahh I see now, many thanks!
Chris
No problem! Consider upvoting if you liked the answer :)
ohadsc