/// <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);
        }
        /// <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);
        }
Example #3
0
        /// <summary>
        /// Filters rule list by task names.
        /// Excludes specified instances from the list.
        /// Method creates a new, filtered rule list, rather than changing the existing one.
        /// </summary>
        /// <param name="names">Task name to be excluded from instance list.</param>
        /// <returns>New, filtered rule list.</returns>
        public CrontabRuleList FilterByNames(String[] names, bool exclude)
        {
            if (names.Length == 0)
            {
                return(this);
            }
            List <CrontabRule> l = this.FindAll(
                (CrontabRule r) =>
            {
                foreach (String n in names)
                {
                    if (r.TaskName.Contains(n))
                    {
                        return(!exclude);
                    }
                }
                return(exclude);
            });
            CrontabRuleList list = new CrontabRuleList();

            list.AddRange(l);
            return(list);
        }
 /// <summary>
 /// Create crontab parser based on crontab rule list and selected date.
 /// </summary>
 /// <param name="cr">crontab rule list from which instances should be created</param>
 /// <param name="selectedDay">selected date for which instances should be created</param>
 public CrontabRuleParser(CrontabRuleList cr, DateTime selectedDay)
     : this()
 {
     this.rules.AddRange(cr);
     this.selectedDay = selectedDay;
 }
 /// <summary>
 /// Creates default, parser object.
 /// </summary>
 public CrontabRuleParser()
 {
     this.rules     = new CrontabRuleList();
     this.instances = new CrontabInstanceList();
 }