Exemplo n.º 1
0
        /// <summary>
        /// Creates rule list based on crontab raw rules.
        /// </summary>
        /// <returns>Crontab rule list created based on crontab raw rules.</returns>
        public CrontabRuleList GetRuleList()
        {
            CrontabRuleList crl = new CrontabRuleList();

            foreach (CrontabRawRule cr in this)
            {
                //czy tutuj mogą wpadać nulle?
                crl.Add(cr.GetRule());
            }
            return(crl);
        }
Exemplo n.º 2
0
        /// <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);
        }