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.


Rogier
2018-12-17T14:18:00Z
Hello

i want to build a job wich i can use to activate the de-activated mail triggers.

Is there a easy way to build this?

Reason is that we restart our servers (included Exchange server) every 2 weeks. After restart all mail triggers are de-activated and i have to restart them all manualy 1 by 1. I want to do that automatically.

Is a job wich check's this the right solution or is there maybe an other solution for this problem ?

Hope to here from you VC experts.

Rogier
Sponsor
Forum information
thordw
2018-12-17T14:52:35Z
Hi

I've faced a similar problem with file/remote-file triggers when our system where a bit shaky and
deavtivated all the time.

I solved it by using the Visual Cron api and created a small #net program, that did what i wanted.
Rogier
2018-12-17T21:19:48Z
i don't have experience with Visual Cron api or #net program
thordw
2018-12-18T09:12:15Z
Hi

Neither did I, but wasn't to hard in the end.
Do you have any programming experience?

I could create an easy code snippet that does the trick for you.
thomas
2018-12-18T11:54:56Z
If you don't want to use the api, the only alternative is to create a job with tasks that activate all triggers. You have to create one task for each job that has triggers you want to activate, so this solution depends on how many you have

Capture.PNG
Rogier
2018-12-18T12:15:32Z
i found that solution also but then i have to create a task for all jobs and that will become a hell of job. But once done it's solved.
thordw
2018-12-18T12:26:45Z
Hi

It would be time consuming to update and maintain such a job.
This code would do that for you (not tested tho 😛 )

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VisualCronAPI;
using VisualCron;

namespace TriggerEnabler
{
    class Program
    {

        private readonly static TriggerClass.TriggerT triggerType = TriggerClass.TriggerT.EventType;
        private readonly static EventClass.EventTy eventType = EventClass.EventTy.Mail;

        private static void Main(string[] args)
        {
            Server s;
            Client c = new Client();
            Connection conn = new Connection
            {
                Address = "<server address>",
                UserName = "<user>",
                PassWord = "<pass>"
            };
            s = c.Connect(conn, true);
            if (s.Connected) {
                LoopJobs(s);
                s.Disconnect();
            }
        }

        private static void LoopJobs(Server server) {
            foreach (JobClass job in server.Jobs.GetAll())
            {
                // We only update the jobs that have been updated
                if (CheckTriggers(job))
                {
                    Console.WriteLine("Saving job: " + job.Name);
                    server.Jobs.Update(job);
                }
            }
        }

        private static bool CheckTriggers(JobClass job) {
            bool updated = false;
            foreach (TriggerClass trigger in job.Triggers)
            {
                // We skip triggers that are active
                if (trigger.Active)
                {
                    continue;
                }
                // Check that the triggers are of the type we want
                if (CheckTriggerType(trigger, triggerType, eventType)) {
                    //Enable trigger
                    Console.WriteLine("Setting trigger: " + trigger.Description + " for job: " + job.Name + " to active");
                    trigger.Active = true;
                    updated = true;
                }
            }
            return updated;
        }

        private static bool CheckTriggerType(TriggerClass trigger, TriggerClass.TriggerT triggerType, EventClass.EventTy eventType) {
            return trigger.TriggerType.Equals(triggerType) && trigger.TEvent.EventType.Equals(eventType);
        }
    }
}
Rogier
2018-12-18T13:39:32Z
thank you very much for this.
Scroll to Top