示例#1
0
        /// <summary>
        /// Tanslates raw crontab rule into 'computer' readable rule described by CrontabRule class.
        /// </summary>
        /// <returns>Crontab rule in 'computer' readable format.</returns>
        public CrontabRule GetRule()
        {
            CrontabRule r = new CrontabRule(this);

            r.Minute.AddRange(this.parseValue(this.Minute));
            r.Hour.AddRange(this.parseValue(this.Hour));
            r.Day.AddRange(this.parseValue(this.Day));
            r.Month.AddRange(this.parseValue(this.Month));
            r.Weekday.AddRange(this.parseValue(this.Weekday));
            r.IsExcluded = this.isExcluded;
            r.TaskName   = this.TaskName;
            return(r);
        }
        /// <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);
        }
示例#3
0
        /// <summary>
        /// Tanslates raw crontab rule into 'computer' readable rule described by CrontabRule class.
        /// </summary>
        /// <returns>Crontab rule in 'computer' readable format.</returns>
        public CrontabRule GetRule()
        {
            CrontabRule r = new CrontabRule(this);

            r.Minute.AddRange(this.parseValue(this.Minute));
            r.Hour.AddRange(this.parseValue(this.Hour));
            r.Day.AddRange(this.parseValue(this.Day));
            r.Month.AddRange(this.parseValue(this.Month));
            r.Weekday.AddRange(this.parseValue(this.Weekday));
            r.IsExcluded = this.isExcluded;
            r.TaskName = this.TaskName;
            return r;
        }
示例#4
0
 /// <summary>
 /// Create crontab parser based on crontab rule and selected date.
 /// </summary>
 /// <param name="cr">crontab rule from which instances should be created</param>
 /// <param name="selectedDay">selected date for which instances should be created</param>
 public CrontabRuleParser(CrontabRule cr, DateTime selectedDay)
     : this()
 {
     this.rules.Add(cr);
     this.selectedDay = selectedDay;
 }
示例#5
0
 /// <summary>
 /// Create crontab parser based on crontab rule and selected date.
 /// </summary>
 /// <param name="cr">crontab rule from which instances should be created</param>
 /// <param name="selectedDay">selected date for which instances should be created</param>
 public CrontabRuleParser(CrontabRule cr, DateTime selectedDay)
     : this()
 {
     this.rules.Add(cr);
     this.selectedDay = selectedDay;
 }