Ejemplo n.º 1
0
        private async Task parseJobs(string crontabFile)
        {
            foreach (string jobStr in crontabFile.Split('\n'))
            {
                if (!string.IsNullOrEmpty(jobStr) && !jobStr.StartsWith('#'))
                {
                    Match  jobRegex = Regex.Match(jobStr, @"(?<schedule>\S+ \S+ \S+ \S+ \S+) (?<command>.+)");
                    string schedule = jobRegex.Groups[1].Value;
                    string command, comment = null;

                    if (jobRegex.Groups[2].Value.Contains('#'))
                    {
                        string[] commandAndComment = jobRegex.Groups[2].Value.Split('#');
                        command = commandAndComment[0].Trim();
                        comment = commandAndComment[1].Trim();
                    }
                    else
                    {
                        command = jobRegex.Groups[2].Value;
                    }

                    CronJob job = new CronJob(schedule, command);
                    job.Comment = comment;
                    jobs.Add(job);
                }
            }
        }
Ejemplo n.º 2
0
 public void AddJob(CronJob job)
 {
     jobs.Add(job);
 }