예제 #1
0
        ////////////////////////////////////////////////////////////////////////////
        //
        // Expression Parsing Functions
        //
        ////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Builds the expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        protected void BuildExpression(string expression) {
            expressionParsed = true;

            try {
                if (seconds == null) {
                    seconds = new TreeSet();
                }
                if (minutes == null) {
                    minutes = new TreeSet();
                }
                if (hours == null) {
                    hours = new TreeSet();
                }
                if (daysOfMonth == null) {
                    daysOfMonth = new TreeSet();
                }
                if (months == null) {
                    months = new TreeSet();
                }
                if (daysOfWeek == null) {
                    daysOfWeek = new TreeSet();
                }
                if (years == null) {
                    years = new TreeSet();
                }

                int exprOn = Second;

#if NET_20
                string[] exprsTok = expression.Trim().Split(new char[] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
#else
                string[] exprsTok = expression.Trim().Split(new char[] { ' ', '\t', '\r', '\n' });
#endif
                foreach (string exprTok in exprsTok) {
                    string expr = exprTok.Trim();

                    if (expr.Length == 0) {
                        continue;
                    }
                    if (exprOn > Year) {
                        break;
                    }

                    // throw an exception if L is used with other days of the month
                    if (exprOn == DayOfMonth && expr.IndexOf('L') != -1 && expr.Length > 1 && expr.IndexOf(",") >= 0) {
                        throw new FormatException("Support for specifying 'L' and 'LW' with other days of the month is not implemented");
                    }
                    // throw an exception if L is used with other days of the week
                    if (exprOn == DayOfWeek && expr.IndexOf('L') != -1 && expr.Length > 1 && expr.IndexOf(",") >= 0) {
                        throw new FormatException("Support for specifying 'L' with other days of the week is not implemented");
                    }

                    string[] vTok = expr.Split(',');
                    foreach (string v in vTok) {
                        StoreExpressionVals(0, v, exprOn);
                    }

                    exprOn++;
                }

                if (exprOn <= DayOfWeek) {
                    throw new FormatException("Unexpected end of expression.");
                }

                if (exprOn <= Year) {
                    StoreExpressionVals(0, "*", Year);
                }

                TreeSet dow = GetSet(DayOfWeek);
                TreeSet dom = GetSet(DayOfMonth);

                // Copying the logic from the UnsupportedOperationException below
                bool dayOfMSpec = !dom.Contains(NoSpec);
                bool dayOfWSpec = !dow.Contains(NoSpec);

                if (dayOfMSpec && !dayOfWSpec) {
                    // skip
                }
                else if (dayOfWSpec && !dayOfMSpec) {
                    // skip
                }
                else {
                    throw new FormatException("Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.");
                }
            }
            catch (FormatException) {
                throw;
            }
            catch (Exception e) {
                throw new FormatException(string.Format(CultureInfo.InvariantCulture, "Illegal cron expression format ({0})", e));
            }
        }
예제 #2
0
 /// <summary>
 /// Returns a portion of the list whose elements are greater than the limit object parameter.
 /// </summary>
 /// <param name="limit">The start element of the portion to extract.</param>
 /// <returns>The portion of the collection whose elements are greater than the limit object parameter.</returns>
 public ISortedSet TailSet(object limit) {
     ISortedSet newList = new TreeSet();
     int i = 0;
     while ((i < Count) && (comparator.Compare(this[i], limit) < 0)) {
         i++;
     }
     for (; i < Count; i++) {
         newList.Add(this[i]);
     }
     return newList;
 }