コード例 #1
0
ファイル: CronExpression.cs プロジェクト: CSStudio/SwarmTask
        ////////////////////////////////////////////////////////////////////////////
        //
        // 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();
                }

                var exprOn = SECOND;

                var exprsTok = expression.Trim().Split(new[] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var exprTok in exprsTok)
                {
                    var 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 == DAY_OF_MONTH && 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 == DAY_OF_WEEK && 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");
                    }

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

                    exprOn++;
                }

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

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

                var dow = GetSet(DAY_OF_WEEK);
                var dom = GetSet(DAY_OF_MONTH);

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

                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
ファイル: TreeSet.cs プロジェクト: CSStudio/SwarmTask
 /// <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();
     var i = 0;
     while ((i < Count) && (_comparator.Compare(this[i], limit) < 0))
     {
         i++;
     }
     for (; i < Count; i++)
     {
         newList.Add(this[i]);
     }
     return newList;
 }