Пример #1
0
        private bool ValidateOnceParams(ScheduledJobTrigger trigger = null)
        {
            if (MyInvocation.BoundParameters.ContainsKey(_paramDaysInterval))
            {
                string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidDaysInterval, ScheduledJobErrorStrings.TriggerOnceType);
                WriteValidationError(msg);
                return(false);
            }
            if (MyInvocation.BoundParameters.ContainsKey(_paramWeeksInterval))
            {
                string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidWeeksInterval, ScheduledJobErrorStrings.TriggerOnceType);
                WriteValidationError(msg);
                return(false);
            }
            if (MyInvocation.BoundParameters.ContainsKey(_paramUser))
            {
                string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidUser, ScheduledJobErrorStrings.TriggerOnceType);
                WriteValidationError(msg);
                return(false);
            }
            if (MyInvocation.BoundParameters.ContainsKey(_paramDaysOfWeek))
            {
                string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidDaysOfWeek, ScheduledJobErrorStrings.TriggerOnceType);
                WriteValidationError(msg);
                return(false);
            }

            if (MyInvocation.BoundParameters.ContainsKey(_paramRepetitionInfiniteDuration))
            {
                _repDuration = TimeSpan.MaxValue;
            }

            if (MyInvocation.BoundParameters.ContainsKey(_paramRepetitionInterval) || MyInvocation.BoundParameters.ContainsKey(_paramRepetitionDuration) ||
                MyInvocation.BoundParameters.ContainsKey(_paramRepetitionInfiniteDuration))
            {
                // Validate Once trigger repetition parameters.
                try
                {
                    ScheduledJobTrigger.ValidateOnceRepetitionParams(_repInterval, _repDuration);
                }
                catch (PSArgumentException e)
                {
                    WriteValidationError(e.Message);
                    return(false);
                }
            }

            if (trigger != null)
            {
                if (trigger.At == null && !MyInvocation.BoundParameters.ContainsKey(_paramAt))
                {
                    string msg = StringUtil.Format(ScheduledJobErrorStrings.MissingAtTime, ScheduledJobErrorStrings.TriggerOnceType);
                    WriteValidationError(msg);
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
        private bool ValidateOnceParams(ScheduledJobTrigger trigger = null)
        {
            string   str;
            bool     flag;
            DateTime?at;

            if (!base.MyInvocation.BoundParameters.ContainsKey(this._paramDaysInterval))
            {
                if (!base.MyInvocation.BoundParameters.ContainsKey(this._paramWeeksInterval))
                {
                    if (!base.MyInvocation.BoundParameters.ContainsKey(this._paramUser))
                    {
                        if (!base.MyInvocation.BoundParameters.ContainsKey(this._paramDaysOfWeek))
                        {
                            if (base.MyInvocation.BoundParameters.ContainsKey(this._paramRepetitionInterval) || base.MyInvocation.BoundParameters.ContainsKey(this._paramRepetitionDuration))
                            {
                                try
                                {
                                    ScheduledJobTrigger.ValidateOnceRepetitionParams(new TimeSpan?(this._repInterval), new TimeSpan?(this._repDuration));
                                    if (trigger != null)
                                    {
                                        at = trigger.At;
                                        if (!at.HasValue && !base.MyInvocation.BoundParameters.ContainsKey(this._paramAt))
                                        {
                                            str = StringUtil.Format(ScheduledJobErrorStrings.MissingAtTime, ScheduledJobErrorStrings.TriggerOnceType);
                                            this.WriteValidationError(str);
                                            return(false);
                                        }
                                    }
                                    return(true);
                                }
                                catch (PSArgumentException pSArgumentException1)
                                {
                                    PSArgumentException pSArgumentException = pSArgumentException1;
                                    this.WriteValidationError(pSArgumentException.Message);
                                    flag = false;
                                }
                                return(flag);
                            }
                            if (trigger != null)
                            {
                                at = trigger.At;
                                if (!at.HasValue && !base.MyInvocation.BoundParameters.ContainsKey(this._paramAt))
                                {
                                    str = StringUtil.Format(ScheduledJobErrorStrings.MissingAtTime, ScheduledJobErrorStrings.TriggerOnceType);
                                    this.WriteValidationError(str);
                                    return(false);
                                }
                            }
                            return(true);
                        }
                        else
                        {
                            string str1 = StringUtil.Format(ScheduledJobErrorStrings.InvalidDaysOfWeek, ScheduledJobErrorStrings.TriggerOnceType);
                            this.WriteValidationError(str1);
                            return(false);
                        }
                    }
                    else
                    {
                        string str2 = StringUtil.Format(ScheduledJobErrorStrings.InvalidUser, ScheduledJobErrorStrings.TriggerOnceType);
                        this.WriteValidationError(str2);
                        return(false);
                    }
                }
                else
                {
                    string str3 = StringUtil.Format(ScheduledJobErrorStrings.InvalidWeeksInterval, ScheduledJobErrorStrings.TriggerOnceType);
                    this.WriteValidationError(str3);
                    return(false);
                }
            }
            else
            {
                string str4 = StringUtil.Format(ScheduledJobErrorStrings.InvalidDaysInterval, ScheduledJobErrorStrings.TriggerOnceType);
                this.WriteValidationError(str4);
                return(false);
            }
        }
Пример #3
0
        internal void Validate()
        {
            TriggerFrequency triggerFrequency = this._frequency;

            switch (triggerFrequency)
            {
            case TriggerFrequency.None:
            {
                throw new ScheduledJobException(ScheduledJobErrorStrings.MissingJobTriggerType);
            }

            case TriggerFrequency.Once:
            {
                if (this._time.HasValue)
                {
                    if (!this._repInterval.HasValue && !this._repDuration.HasValue)
                    {
                        return;
                    }
                    ScheduledJobTrigger.ValidateOnceRepetitionParams(this._repInterval, this._repDuration);
                    return;
                }
                else
                {
                    string str = StringUtil.Format(ScheduledJobErrorStrings.MissingJobTriggerTime, ScheduledJobErrorStrings.TriggerOnceType);
                    throw new ScheduledJobException(str);
                }
            }

            case TriggerFrequency.Daily:
            {
                if (this._time.HasValue)
                {
                    if (this._interval >= 1)
                    {
                        return;
                    }
                    throw new ScheduledJobException(ScheduledJobErrorStrings.InvalidDaysIntervalParam);
                }
                else
                {
                    string str1 = StringUtil.Format(ScheduledJobErrorStrings.MissingJobTriggerTime, ScheduledJobErrorStrings.TriggerDailyType);
                    throw new ScheduledJobException(str1);
                }
            }

            case TriggerFrequency.Weekly:
            {
                if (this._time.HasValue)
                {
                    if (this._interval >= 1)
                    {
                        if (this._daysOfWeek != null && this._daysOfWeek.Count != 0)
                        {
                            return;
                        }
                        string str2 = StringUtil.Format(ScheduledJobErrorStrings.MissingJobTriggerDaysOfWeek, ScheduledJobErrorStrings.TriggerWeeklyType);
                        throw new ScheduledJobException(str2);
                    }
                    else
                    {
                        throw new ScheduledJobException(ScheduledJobErrorStrings.InvalidWeeksIntervalParam);
                    }
                }
                else
                {
                    string str3 = StringUtil.Format(ScheduledJobErrorStrings.MissingJobTriggerTime, ScheduledJobErrorStrings.TriggerWeeklyType);
                    throw new ScheduledJobException(str3);
                }
            }

            case TriggerFrequency.AtLogon:
            case TriggerFrequency.AtStartup:
            {
                return;
            }

            default:
            {
                return;
            }
            }
        }