Community forum

Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


pdzugas
2012-05-16T12:42:15Z
I need to add new job with single task that should be triggered just once in very specific date/time. Currently my code (sort of) works but I can't figure out why is job's Next run showing 'No Trigger specified' even though when I open edit trigger window there is shown the correct time in status bar. Please see the screenshot included to see what I mean:

I'm using VisualCron 6.0.9 (trial license still), tried 6.1.0 as well without success.
Desired scheduleDate parameter for test case was May 31, 2012.
        internal static void CreateVisualCronTask(DateTime scheduleDate, string packageCode)
        {
            Server server = null;
            Client client = new Client();
            client.LogToFile = false;

            try
            {
                Connection connection = new Connection();
                connection.ConnectionType = Connection.ConnectionT.Remote;
                connection.Address = Configuration.VisualCronHostIP;
                connection.Port = Configuration.VisualCronHostPort;
                connection.UserName = Configuration.VisualCronUser;
                connection.PassWord = Configuration.VisualCronUserPassword;
                connection.UseADLogon = false;
                connection.ClientType = ClientConnectionClass.ClientT.APIClient;

                server = client.Connect(connection, true);
            }
            catch
            {
                throw;
            }

            if (server != null && server.Connected)
            {
                JobClass job = new JobClass();
                job.Name = Configuration.VisualCronJobName;
                job.Description = Configuration.VisualCronJobDescription;
                job.Group = "MegaSign";
                job.RunOnce = true;

                #region Trigger definition

                TriggerClass trigger = job.AddTrigger(TimeClass.TimeTriggerT.Custom);
                trigger.Description = "Runs only once";
                trigger.TTime.AllYears = false;
                trigger.TTime.AllMonths = false;
                trigger.TTime.AllDays = false;
                trigger.TTime.AllHours = false;
                trigger.TTime.AllMinutes = false;
                trigger.TTime.AllSeconds = false;
                //TTime indices are zero-based
                trigger.TTime.YearBetweenStart = scheduleDate.Year;
                trigger.TTime.YearBetweenStop = scheduleDate.Year;
                trigger.TTime.YearIsBetween = true;
                trigger.TTime.Months[scheduleDate.Month - 1] = true;
                trigger.TTime.Days[scheduleDate.Day - 1] = true;

                trigger.TTime.Hours[0] = true;
                trigger.TTime.Minutes[0] = true;
                trigger.TTime.Seconds[0] = true;

                trigger.TTime.SpecificType = TimeClass.SpecificT.Days;
                trigger.TTime.DayType = true;
                trigger.FirstRun = scheduleDate;

                #endregion

                #region Task definition

                TaskClass task = job.AddTask(TaskClass.TaskT.Execute);
                task.Name = string.Format("Run Sender with PackageCode={0}", packageCode);
#if DEBUG
                task.Execute.CmdLine = "C:\\FakeSender.cmd";
#else
                task.Execute.CmdLine = Configuration.PathToEchoSignSenderApp;
#endif
                task.Execute.Arguments = packageCode;

                task.ExecutionContext.ExecutionType = ExecutionContextClass.ExecutionT.Foreground;

                var newJob = server.Jobs.Add(job);

                #endregion

                if (Configuration.StartPastPackagesImmediately && scheduleDate < DateTime.Now)
                    server.Jobs.Run(newJob, true);

                server.Disconnect();
            }
        }

TIA for any solution, it's quite urgent and we have the first release deployed to customer already.
Sponsor
Forum information
Support
2012-05-16T12:51:26Z
Try setting the Trigger.TTime.InitDate to the same value as FirstRun.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
pdzugas
2012-05-18T08:10:10Z
Originally Posted by: Support 

Try setting the Trigger.TTime.InitDate to the same value as FirstRun.


That didn't help either. It's strange because once I open VCClient console and get into Add/Edit time trigger dialog and just confirm it by clicking OK button without actually opening/changing anything else there, then clicking OK at Edit Job window will populate proper date 05/31/2012 into Next run column immediately.
This clearly looks like API issue to me rather than VC bug itself.😢
Support
2012-05-18T08:11:39Z
Originally Posted by: pdzugas 

Originally Posted by: Support 

Try setting the Trigger.TTime.InitDate to the same value as FirstRun.


That didn't help either. It's strange because once I open VCClient console and get into Add/Edit time trigger dialog and just confirm it by clicking OK button without actually opening/changing anything else there, then clicking OK at Edit Job window will populate proper date 05/31/2012 into Next run column immediately.
This clearly looks like API issue to me rather than VC bug itself.😢



The Client is using the same API. Please compare with the API sample for adding a Custom Time Trigger.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
pdzugas
2012-05-18T08:35:40Z
You mean this sample?
private void btnAddJobCustomTrigger_Click(object sender, EventArgs e)
        {
            // create JobClass
            JobClass j = new JobClass();
            // set name of Job
            j.Name = "ExecuteJob 2";
            // add description to Job
            j.Description = "Job with Custom Time Trigger";

            // create custom trigger
            TriggerClass tr = j.AddTrigger(TimeClass.TimeTriggerT.Custom);
            tr.Description = "Run daily at 11 PM / 23:00";
            tr.TTime.AllYears = true;
            tr.TTime.AllMonths = true;
            tr.TTime.AllDays = true;
            tr.TTime.AllHours = false;
            tr.TTime.AllMinutes = false;
            tr.TTime.Hours[23] = true;
            tr.TTime.Minutes[0] = true;
            tr.TTime.Seconds[0] = true;

            // send Job to Server
            s.Jobs.Add(j);
        }

It's useless for me - I do not want to run the task DAILY, I need it to run only once at one single specified time.
Support
2012-05-18T08:44:08Z
I mean it is hard to see, right away, with your code what is wrong. If the sample works then you can go for there.

I would also compare the XML file after creating it with your code and then manually in the interface to see what the diff is.

The settings are stored in jobs.xml file.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
pdzugas
2012-05-18T09:02:01Z
Alright, I'll try to compare XML files later.
However, why don't YOU try my example to see what is wrong with that?
The only important part to test is below, all other parts seem to work fine:
#region Trigger definition
 
                TriggerClass trigger = job.AddTrigger(TimeClass.TimeTriggerT.Custom);
                trigger.Description = "Runs only once";
                trigger.TTime.AllYears = false;
                trigger.TTime.AllMonths = false;
                trigger.TTime.AllDays = false;
                trigger.TTime.AllHours = false;
                trigger.TTime.AllMinutes = false;
                trigger.TTime.AllSeconds = false;
                //TTime indices are zero-based
                trigger.TTime.YearBetweenStart = scheduleDate.Year;
                trigger.TTime.YearBetweenStop = scheduleDate.Year;
                trigger.TTime.YearIsBetween = true;
                trigger.TTime.Months[scheduleDate.Month - 1] = true;
                trigger.TTime.Days[scheduleDate.Day - 1] = true;
 
                trigger.TTime.Hours[0] = true;
                trigger.TTime.Minutes[0] = true;
                trigger.TTime.Seconds[0] = true;
 
                trigger.TTime.SpecificType = TimeClass.SpecificT.Days;
                trigger.TTime.DayType = true;
                trigger.FirstRun = scheduleDate;
 
                #endregion


Clearly there is something missing when accessing/creating trigger object via API as opposed to human add/edit via UI.
Support
2012-05-18T09:14:20Z
This will probably take at least an hour to test out why. We do not have time to check this today but will get back to you on Monday if you go through the priority support:

http://www.visualcron.com/Contact.aspx 

The API is provided as-is and require that a developer sits down and try this (not the same type of support as just answering a question or trying something out in the Client).
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Support
2012-05-21T07:10:35Z
We have looked at the case. While we do not know what exact values you put into month, day and year the problem is that you, in some way, define a date in the past. The "No trigger specified" text is somewhat confusing maybe but the Trigger is clearly defined in the past. We tried the exact code using different dates as input.

Just a reminder:

Today is 2012-05-21. If I for example use these values it will not run:

                    trigger.TTime.YearBetweenStart = 2005;
                    trigger.TTime.YearBetweenStop = 2012;
                    trigger.TTime.YearIsBetween = true;
                    trigger.TTime.Months[5 - 1] = true;
                    trigger.TTime.Days[21 - 1] = true;
                    trigger.TTime.Hours[0] = true;
                    trigger.TTime.Minutes[0] = true;
                    trigger.TTime.Seconds[0] = true;


The reason for this is that hour, minute and second is 0 and that is the "first time" on the current day.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
pdzugas
2012-05-21T14:38:01Z
Originally Posted by: Support 

While we do not know what exact values you put into month, day and year the problem is that you, in some way, define a date in the past. The "No trigger specified" text is somewhat confusing maybe but the Trigger is clearly defined in the past.


Sorry to disappoint you but I am not defining a date in the past yet it still shows "No Trigger specified" unless I manually open all dialog windows and confirm by clicking OK - please try my code below. Today is 2012-05-21 and my scheduleDate = 2012-05-23 00:00:00 during debugging. Are you sure that version 6.0.9 was used for your testing?
TriggerClass trigger = job.AddTrigger(TimeClass.TimeTriggerT.Custom);
            trigger.Description = "Runs only once";
            trigger.TTime.AllYears = false;
            trigger.TTime.AllMonths = false;
            trigger.TTime.AllDays = false;
            trigger.TTime.AllHours = false;
            trigger.TTime.AllMinutes = false;
            trigger.TTime.AllSeconds = false;
            //TTime indices are zero-based
            trigger.TTime.YearBetweenStart = scheduleDate.Year;
            trigger.TTime.YearBetweenStop = scheduleDate.Year;
            trigger.TTime.YearIsBetween = true;
            trigger.TTime.Months[scheduleDate.Month - 1] = true;
            trigger.TTime.Days[scheduleDate.Day - 1] = true;
            trigger.TTime.Hours[0] = true;
            trigger.TTime.Minutes[0] = true;
            trigger.TTime.Seconds[0] = true;

            trigger.TTime.SpecificType = TimeClass.SpecificT.Days;
            trigger.TTime.DayType = true;
            trigger.FirstRun = scheduleDate;
            trigger.TTime.InitDate = scheduleDate;
Support
2012-05-21T15:44:50Z
Ok, I see the problem now. We probably need to make creation of Trigger a little more simplified but what is missing in your code is this line:

trigger.TTime.Years[0] = 2012;
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
pdzugas
2012-05-22T06:07:12Z
Originally Posted by: Support 

trigger.TTime.Years[0] = 2012;


This one-liner really did the trick, thank you! 😁
And yes, you definitely need to make Custom Time trigger creation via API more simple or at least include what was mentioned in this thread as a practical example of how should be one-time specific date/time trigger created properly.
Scroll to Top