Exemplo n.º 1
0
 private int GetMinimumFromField(CrontabField fieldName)
 {
     string[] expressions;
     if (this.crontabFields.TryGetValue(fieldName, out expressions))
     {
         if (expressions[0].Equals("*"))
         {
             if (fieldName == CrontabField.Minute || fieldName == CrontabField.Hour)
             {
                 return(0);
             }
             else
             {
                 return(1);
             }
         }
         else
         {
             return(int.Parse(expressions[0]));
         }
     }
     else
     {
         return(0);
     }
 }
Exemplo n.º 2
0
 private void AddOrUpdateCronField(CrontabField cName, string[] filters)
 {
     if (this.crontabFields.ContainsKey(cName))
     {
         this.crontabFields[cName] = filters;
     }
     else
     {
         this.crontabFields.Add(cName, filters);
     }
 }
Exemplo n.º 3
0
        public void Format(CrontabField field, TextWriter writer, bool noNames)
        {
            if (field == null)
            {
                throw new ArgumentNullException(nameof(field));
            }

            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            var next  = field.GetFirst();
            var count = 0;

            while (next != -1)
            {
                var first = next;
                int last;

                do
                {
                    last = next;
                    next = field.Next(last + 1);
                } while (next - last == 1);

                if (count == 0 &&
                    first == _minValue && last == _maxValue)
                {
                    writer.Write('*');
                    return;
                }

                if (count > 0)
                {
                    writer.Write(',');
                }

                if (first == last)
                {
                    FormatValue(first, writer, noNames);
                }
                else
                {
                    FormatValue(first, writer, noNames);
                    writer.Write('-');
                    FormatValue(last, writer, noNames);
                }

                count++;
            }
        }
Exemplo n.º 4
0
        private CrontabSchedule(string expression)
        {
            Debug.Assert(expression != null);

            var fields = expression.Split((char[])Separators, StringSplitOptions.RemoveEmptyEntries);

            if (fields.Length != 5)
            {
                throw new FormatException(string.Format(
                                              "'{0}' is not a valid crontab expression. It must contain at least 5 components of a schedule "
                                              + "(in the sequence of minutes, hours, days, months, days of week).",
                                              expression));
            }

            _minutes    = CrontabField.Minutes(fields[0]);
            _hours      = CrontabField.Hours(fields[1]);
            _days       = CrontabField.Days(fields[2]);
            _months     = CrontabField.Months(fields[3]);
            _daysOfWeek = CrontabField.DaysOfWeek(fields[4]);
        }