示例#1
0
        public bool IsOnTime(int checkSpanSeconds, DateTime now)
        {
            bool result;

            //如果lastRightTime与当前时间的差值2倍的扫描间隔以内,则将认为当前时间不符合条件
            if ((now - this.lastRightTime).TotalMilliseconds < (double)(checkSpanSeconds * 1000 * 2))
            {
                result = false;
            }
            else
            {
                bool flag = false;
                switch (this.timingTaskType)
                {
                case TimingTaskType.PerHour:
                {
                    ShortTime shortTime = new ShortTime(now.Hour, this.excuteTime.Minute, this.excuteTime.Second);
                    flag = shortTime.IsOnTime(now, checkSpanSeconds);
                    if (!flag)
                    {
                        ShortTime shortTime2 = new ShortTime(now.AddHours(1.0).Hour, this.excuteTime.Minute, this.excuteTime.Second);
                        flag = shortTime2.IsOnTime(now, checkSpanSeconds);
                    }
                    if (!flag)
                    {
                        ShortTime shortTime3 = new ShortTime(now.AddHours(-1.0).Hour, this.excuteTime.Minute, this.excuteTime.Second);
                        flag = shortTime3.IsOnTime(now, checkSpanSeconds);
                    }
                    break;
                }

                case TimingTaskType.PerDay:
                    flag = this.excuteTime.IsOnTime(now, checkSpanSeconds);
                    break;

                case TimingTaskType.PerWeek:
                    flag = (now.DayOfWeek == this.dayOfWeek && this.excuteTime.IsOnTime(now, checkSpanSeconds));
                    break;

                case TimingTaskType.PerMonth:
                    flag = (now.Day == this.day && this.excuteTime.IsOnTime(now, checkSpanSeconds));
                    break;
                }
                if (flag)
                {
                    this.lastRightTime = now;
                }
                result = flag;
            }
            return(result);
        }
示例#2
0
        public bool IsOnTime(int checkSpanSeconds, DateTime now)
        {
            #region 防止在临界点时,执行两次
            TimeSpan span = now - this.lastRightTime;
            if (span.TotalMilliseconds < checkSpanSeconds * 1000 * 2)
            {
                return false;
            } 
            #endregion
            
            bool isOnTime = false;

            #region Switch
            switch (this.timingTaskType)
            {
                case TimingTaskType.PerHour:
                    {
                        ShortTime temp = new ShortTime(now.Hour, this.excuteTime.Minute, this.excuteTime.Second);
                        isOnTime = temp.IsOnTime(now, checkSpanSeconds);

                        if (!isOnTime)
                        {
                            ShortTime temp2 = new ShortTime(now.AddHours(1).Hour, this.excuteTime.Minute, this.excuteTime.Second);
                            isOnTime = temp2.IsOnTime(now, checkSpanSeconds);
                        }

                        if (!isOnTime)
                        {
                            ShortTime temp3 = new ShortTime(now.AddHours(-1).Hour, this.excuteTime.Minute, this.excuteTime.Second);
                            isOnTime = temp3.IsOnTime(now, checkSpanSeconds);
                        }

                        break;
                    }
                case TimingTaskType.PerDay:
                    {
                        isOnTime = this.excuteTime.IsOnTime(now, checkSpanSeconds);
                        break;
                    }
                case TimingTaskType.PerWeek:
                    {
                        if (now.DayOfWeek != this.dayOfWeek)
                        {
                            isOnTime = false;
                        }
                        else
                        {
                            isOnTime = this.excuteTime.IsOnTime(now, checkSpanSeconds);
                        }
                        break;
                    }
                case TimingTaskType.PerMonth:
                    {
                        if (now.Day != this.day)
                        {
                            isOnTime = false;
                        }
                        else
                        {
                            isOnTime = this.excuteTime.IsOnTime(now, checkSpanSeconds);
                        }
                        break;
                    }
                default:
                    {
                        break;
                    }
            } 
            #endregion

            if (isOnTime)
            {
                this.lastRightTime = now;
            }

            return isOnTime;
        } 
示例#3
0
        public bool IsOnTime(int checkSpanSeconds, DateTime now)
        {
            #region 防止在临界点时,执行两次
            TimeSpan span = now - this.lastRightTime;
            if (span.TotalMilliseconds < checkSpanSeconds * 1000 * 2)
            {
                return(false);
            }
            #endregion

            bool isOnTime = false;

            #region Switch
            switch (this.timingTaskType)
            {
            case TimingTaskType.PerHour:
            {
                ShortTime temp = new ShortTime(now.Hour, this.excuteTime.Minute, this.excuteTime.Second);
                isOnTime = temp.IsOnTime(now, checkSpanSeconds);

                if (!isOnTime)
                {
                    ShortTime temp2 = new ShortTime(now.AddHours(1).Hour, this.excuteTime.Minute, this.excuteTime.Second);
                    isOnTime = temp2.IsOnTime(now, checkSpanSeconds);
                }

                if (!isOnTime)
                {
                    ShortTime temp3 = new ShortTime(now.AddHours(-1).Hour, this.excuteTime.Minute, this.excuteTime.Second);
                    isOnTime = temp3.IsOnTime(now, checkSpanSeconds);
                }

                break;
            }

            case TimingTaskType.PerDay:
            {
                isOnTime = this.excuteTime.IsOnTime(now, checkSpanSeconds);
                break;
            }

            case TimingTaskType.PerWeek:
            {
                if (now.DayOfWeek != this.dayOfWeek)
                {
                    isOnTime = false;
                }
                else
                {
                    isOnTime = this.excuteTime.IsOnTime(now, checkSpanSeconds);
                }
                break;
            }

            case TimingTaskType.PerMonth:
            {
                if (now.Day != this.day)
                {
                    isOnTime = false;
                }
                else
                {
                    isOnTime = this.excuteTime.IsOnTime(now, checkSpanSeconds);
                }
                break;
            }

            default:
            {
                break;
            }
            }
            #endregion

            if (isOnTime)
            {
                this.lastRightTime = now;
            }

            return(isOnTime);
        }