/// <summary>
        /// Reads crontab file and produces list of rules.
        /// </summary>
        /// <returns>List of crontab rules read from a file.</returns>
        public CrontabRuleList GetRuleList()
        {
            //TODO - can't parse */2 value format
            if (this.filename.Equals(string.Empty))
            {
                return new CrontabRuleList();
            }
            CrontabRuleList tasks = new CrontabRuleList();
            TextReader r = new StreamReader(this.filename);
            String line = String.Empty;
            while ((line = r.ReadLine()) != null)
            {

                Regex reg = new Regex(@"^\s*" +
                    @"^(?<minute>[0-9]+(?:(?:\,|\-)[0-9]+)*|\*)\s+" +
                    @"(?<hour>[0-9]+(?:(?:\,|\-)[0-9]+)*|\*)\s+" +
                    @"(?<day>[0-9]+(?:(?:\,|\-)[0-9]+)*|\*)\s+" +
                    @"(?<month>[0-9]+(?:(?:\,|\-)[0-9]+)*|\*)\s+" +
                    @"(?<weekday>[0-9]+(?:(?:\,|\-)[0-9]+)*|\*)\s+(?<taskName>.*)", RegexOptions.Singleline);
                if (reg.IsMatch(line))
                {
                    Match m = reg.Match(line);
                    GroupCollection gc = m.Groups;
                    //Console.WriteLine(gc["minute"]);
                    if (gc["minute"].Success && gc["hour"].Success && gc["day"].Success && gc["month"].Success && gc["weekday"].Success
                        && gc["taskName"].Success)
                    {
                        CrontabRawRule t = new CrontabRawRule();
                        t.Minute = this.validateRawValue(gc["minute"].Value);
                        t.Hour = this.validateRawValue(gc["hour"].Value);
                        t.Day = this.validateRawValue(gc["day"].Value);
                        t.Month = this.validateRawValue(gc["month"].Value);
                        t.Weekday = this.validateRawValue(gc["weekday"].Value);
                        t.TaskName = gc["taskName"].Value;
                        CrontabRule cr = t.GetRule();
                        tasks.Add(cr);
                    }
                }

            }
            r.Close();
            return tasks;
        }
        /// <summary>
        /// Reads crontab file and produces list of rules.
        /// </summary>
        /// <returns>List of crontab rules read from a file.</returns>
        public CrontabRuleList GetRuleList()
        {
            //TODO - can't parse */2 value format
            if (this.filename.Equals(string.Empty))
            {
                return(new CrontabRuleList());
            }
            CrontabRuleList tasks = new CrontabRuleList();
            TextReader      r     = new StreamReader(this.filename);
            String          line  = String.Empty;

            while ((line = r.ReadLine()) != null)
            {
                Regex reg = new Regex(@"^\s*" +
                                      @"^(?<minute>[0-9]+(?:(?:\,|\-)[0-9]+)*|\*)\s+" +
                                      @"(?<hour>[0-9]+(?:(?:\,|\-)[0-9]+)*|\*)\s+" +
                                      @"(?<day>[0-9]+(?:(?:\,|\-)[0-9]+)*|\*)\s+" +
                                      @"(?<month>[0-9]+(?:(?:\,|\-)[0-9]+)*|\*)\s+" +
                                      @"(?<weekday>[0-9]+(?:(?:\,|\-)[0-9]+)*|\*)\s+(?<taskName>.*)", RegexOptions.Singleline);
                if (reg.IsMatch(line))
                {
                    Match           m  = reg.Match(line);
                    GroupCollection gc = m.Groups;
                    //Console.WriteLine(gc["minute"]);
                    if (gc["minute"].Success && gc["hour"].Success && gc["day"].Success && gc["month"].Success && gc["weekday"].Success &&
                        gc["taskName"].Success)
                    {
                        CrontabRawRule t = new CrontabRawRule();
                        t.Minute   = this.validateRawValue(gc["minute"].Value);
                        t.Hour     = this.validateRawValue(gc["hour"].Value);
                        t.Day      = this.validateRawValue(gc["day"].Value);
                        t.Month    = this.validateRawValue(gc["month"].Value);
                        t.Weekday  = this.validateRawValue(gc["weekday"].Value);
                        t.TaskName = gc["taskName"].Value;
                        CrontabRule cr = t.GetRule();
                        tasks.Add(cr);
                    }
                }
            }
            r.Close();
            return(tasks);
        }
Beispiel #3
0
 /// <summary>
 /// Creates crontab rule object based on contab raw rule.
 /// </summary>
 public CrontabRule(CrontabRawRule c)
     : this()
 {
     this.CrontabRawRule = c;
 }
Beispiel #4
0
 /// <summary>
 /// Creates crontab rule object based on contab raw rule.
 /// </summary>
 public CrontabRule(CrontabRawRule c)
     : this()
 {
     this.CrontabRawRule = c;
 }