/// <summary> /// Constructor, Intializing RelayCommands and Lists /// </summary> public StopwatchTimersVM() { // Relay commands to handle any task related to FirstStopwatch StartFirstStopwatchCommand = new RelayCommand(() => StartFirstStopwatch()); StopFirstStopwatchCommand = new RelayCommand(() => StopFirstStopwatch()); PauseFirstStopwatchCommand = new RelayCommand(() => PauseFirstStopwatch()); ResetFirstStopwatchCommand = new RelayCommand(() => ResetFirstStopwatch()); EmptyFirstStopWatchListCommand = new RelayCommand(() => EmptyFirstStopwatchList()); // Relay commands to handle any task related to SecondStopwatch StartSecondStopwatchCommand = new RelayCommand(() => StartSecondStopwatch()); StopSecondStopwatchCommand = new RelayCommand(() => StopSecondStopwatch()); PauseSecondStopwatchCommand = new RelayCommand(() => PauseSecondStopwatch()); ResetSecondStopwatchCommand = new RelayCommand(() => ResetSecondStopwatch()); EmptySecondStopWatchListCommand = new RelayCommand(() => EmptySecondStopwatchList()); // Relay commands to handle any task related to ThirdStopwatch StartThirdStopwatchCommand = new RelayCommand(() => StartThirdStopwatch()); StopThirdStopwatchCommand = new RelayCommand(() => StopThirdStopwatch()); PauseThirdStopwatchCommand = new RelayCommand(() => PauseThirdStopwatch()); ResetThirdStopwatchCommand = new RelayCommand(() => ResetThirdStopwatch()); EmptyThirdStopWatchListCommand = new RelayCommand(() => EmptyThirdStopwatchList()); // Filling the HoursList with 0-24 hours for (short i = 0; i <= 99; i++) { HoursList.Add(i); } // Filling the MinutesList and SecondsList with 0-60 minutes for (short i = 0; i <= 60; i++) { MinutesList.Add(i); SecondsList.Add(i); } StartFirstTimerCommand = new RelayCommand(() => StartFirstTimer()); PauseFirstTimerCommand = new RelayCommand(() => PauseFirstTimer()); StopFirstTimerCommand = new RelayCommand(() => StopFirstTimer()); StartSecondTimerCommand = new RelayCommand(() => StartSecondTimer()); PauseSecondTimerCommand = new RelayCommand(() => PauseSecondTimer()); StopSecondTimerCommand = new RelayCommand(() => StopSecondTimer()); StartThirdTimerCommand = new RelayCommand(() => StartThirdTimer()); PauseThirdTimerCommand = new RelayCommand(() => PauseThirdTimer()); StopThirdTimerCommand = new RelayCommand(() => StopThirdTimer()); }
/// <summary> /// 编译分析时程表达式 /// </summary> private void BuildExpression() { // Format : "* * * * * * *" // 第1列表示秒数0~59 每 秒用*或者*/1表示 // 第2列表示分钟0~59 每分钟用*或者*/1表示 // 第3列表示小时0~23 每小时用*或者*/1表示 // 第4列表示日期1~31 每 天用*或者*/1表示 // 第5列表示月份1~12 每 月用*或者*/1表示 // 第6列表示星期0~6 每 天用*表示*/1表示 0表示星期天 // 第7列表示月份2000~2099 每年用*或者*/1表示 // * 代表任意 * 每个 // / 代表每隔 /2 每隔2 // - 代表区间 1-7 从1至7 // , 表示单独 1,3 1和3 // 例子: 1-10/2 * * 17 9 * * 描述为 9月17日,在每分钟内,从1-10秒间每隔2秒触发一次 if (string.IsNullOrEmpty(CronExpressionString)) { throw new FormatException("CronExpressionString bad format."); } // 分割字符串 string[] columns = CronExpressionString.Trim().Split(new char[] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); // 验证表达式字符串 CronExpressionHelper.ValidateCronExpression(columns); // 构造基础数据 for (int i = 0; i < columns.Length; i++) { string item = columns[i]; switch (i) { case 0: // 秒 SecondsList = CronExpressionHelper.ParseSecondExpression(item); break; case 1: // 分钟 MinutesList = CronExpressionHelper.ParseMinuteExpression(item); break; case 2: // 小时 HoursList = CronExpressionHelper.ParseHourExpression(item); break; case 3: // 日期 DaysList = CronExpressionHelper.ParseDayExpression(item); break; case 4: // 月份 MonthsList = CronExpressionHelper.ParseMonthExpression(item); break; case 5: // 星期 WeekdaysList = CronExpressionHelper.ParseWeekdayExpression(item); break; case 6: // 年份 YearsList = CronExpressionHelper.ParseYearExpression(item); break; default: CronExpressionValidationException.Throw("Maybe validation parsed error."); break; } } if (SecondsList == null || MinutesList == null || HoursList == null || DaysList == null || MonthsList == null || WeekdaysList == null || YearsList == null) { CronExpressionValidationException.Throw("CronExpression parsed collections null."); } // 列表内数据从小到大排序 SecondsList.Sort(); MinutesList.Sort(); HoursList.Sort(); DaysList.Sort(); MonthsList.Sort(); WeekdaysList.Sort(); YearsList.Sort(); }