コード例 #1
0
        private void BuildCronExpression()
        {
            switch (ExpressionType)
            {
            case CronExpressionType.EveryNSeconds:
                _cronString = $"0/{_interval} * * 1/1 * ? *";
                break;

            case CronExpressionType.EveryNMinutes:
                _cronString = $"0 0/{_interval} * 1/1 * ? *";
                break;

            case CronExpressionType.EveryNHours:
                _cronString = $"0 0 0/{_interval} 1/1 * ? *";
                break;

            case CronExpressionType.EveryNDaysAt:
            case CronExpressionType.EveryDayAt:
                _cronString = $"0 {_startMinute} {_startHour} 1/{_interval} * ? *";
                break;

            case CronExpressionType.EveryWeekDay:
                _cronString = $"0 {_startMinute} {_startHour} ? * MON-FRI *";
                break;

            case CronExpressionType.EverySpecificWeekDayAt:
                _cronString = $"0 {_startMinute} {_startHour} ? * {CronConverter.ToCronRepresentation(_daysOfWeek)} *";
                break;

            case CronExpressionType.EverySpecificDayEveryNMonthAt:
                _cronString = $"0 {_startMinute} {_startHour} {_dayNumber} 1/{_interval} ? *";
                break;

            case CronExpressionType.EverySpecificSeqWeekDayEveryNMonthAt:
                _cronString = $"0 {_startMinute} {_startHour} ? 1/{_interval} {CronConverter.ToCronRepresentationSingle(_daysOfWeek)}#{(int)_daySeqNumber} *";
                break;

            case CronExpressionType.EverySpecificDayOfMonthsAt:
                _cronString = $"0 {_startMinute} {_startHour} {_dayNumber} {CronConverter.ToCronRepresentation(_months)} ? *";
                break;

            case CronExpressionType.EverySpecificSeqWeekDayOfMonthsAt:
                _cronString = $"0 {_startMinute} {_startHour} ? {CronConverter.ToCronRepresentation(_months)} {CronConverter.ToCronRepresentationSingle(_daysOfWeek)}#{(int)_daySeqNumber} *";
                break;

            case CronExpressionType.SpecificDateAt:
                _cronString = $"{_startSecond} {_startMinute} {_startHour} {_dayNumber} {CronConverter.ToCronRepresentation(_months)} ? {_yearNumber}";
                break;

            default:
                throw new ArgumentException();
            }
        }
コード例 #2
0
        private void BuildCronExpression()
        {
            switch (ExpressionType)
            {
            case CronExpressionType.EveryNSeconds:
                _cronString = string.Format("0/{0} * * 1/1 * ? *", _interval);
                break;

            case CronExpressionType.EveryNMinutes:
                _cronString = string.Format("0 0/{0} * 1/1 * ? *", _interval);
                break;

            case CronExpressionType.EveryNHours:
                _cronString = string.Format("0 0 0/{0} 1/1 * ? *", _interval);
                break;

            case CronExpressionType.EveryNDaysAt:
            case CronExpressionType.EveryDayAt:
                _cronString = string.Format("0 {0} {1} 1/{2} * ? *", _startMinute, _startHour, _interval);
                break;

            case CronExpressionType.EveryWeekDay:
                _cronString = string.Format("0 {0} {1} ? * MON-FRI *", _startMinute, _startHour);
                break;

            case CronExpressionType.EverySpecificWeekDayAt:
                _cronString = string.Format("0 {0} {1} ? * {2} *", _startMinute, _startHour, CronConverter.ToCronRepresentation(_days));
                break;

            case CronExpressionType.EverySpecificDayEveryNMonthAt:
                _cronString = string.Format("0 {0} {1} {2} 1/{3} ? *", _startMinute, _startHour, _dayNumber, _interval);
                break;

            case CronExpressionType.EverySpecificSeqWeekDayEveryNMonthAt:
                _cronString = string.Format("0 {0} {1} ? 1/{2} {3}#{4} *", _startMinute, _startHour, _interval, CronConverter.ToCronRepresentationSingle(_days), _dayNumber);
                break;

            case CronExpressionType.EverySpecificDayOfMonthAt:
                _cronString = string.Format("0 {0} {1} {2} {3} ? *", _startMinute, _startHour, _dayNumber, (int)_month);
                break;

            case CronExpressionType.EverySpecificSeqWeekDayOfMonthAt:
                _cronString = string.Format("0 {0} {1} ? {2} {3}#{4} *", _startMinute, _startHour, (int)_month, CronConverter.ToCronRepresentationSingle(_days), _dayNumber);
                break;

            default:
                throw new ArgumentException();
            }
        }