private CimInstance ConvertToWeekly(ScheduledJobTrigger trigger, CimSession cimSession)
        {
            CimClass    @class      = cimSession.GetClass(JobTriggerToCimInstanceConverter.CIM_TRIGGER_NAMESPACE, "MSFT_TaskWeeklyTrigger");
            CimInstance cimInstance = new CimInstance(@class);

            cimInstance.CimInstanceProperties["DaysOfWeek"].Value    = ScheduledJobWTS.ConvertDaysOfWeekToMask(trigger.DaysOfWeek);
            cimInstance.CimInstanceProperties["RandomDelay"].Value   = ScheduledJobWTS.ConvertTimeSpanToWTSString(trigger.RandomDelay);
            cimInstance.CimInstanceProperties["WeeksInterval"].Value = trigger.Interval;
            JobTriggerToCimInstanceConverter.AddCommonProperties(trigger, cimInstance);
            return(cimInstance);
        }
示例#2
0
        private void AddTaskTrigger(ITaskDefinition iTaskDefinition, ScheduledJobTrigger jobTrigger)
        {
            ITrigger         str;
            string           user;
            TriggerFrequency frequency = jobTrigger.Frequency;

            switch (frequency)
            {
            case TriggerFrequency.Once:
            {
                str = iTaskDefinition.Triggers.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_TIME);
                ITimeTrigger wTSString = str as ITimeTrigger;
                wTSString.RandomDelay = ScheduledJobWTS.ConvertTimeSpanToWTSString(jobTrigger.RandomDelay);
                TimeSpan?repetitionInterval = jobTrigger.RepetitionInterval;
                if (repetitionInterval.HasValue)
                {
                    TimeSpan?repetitionDuration = jobTrigger.RepetitionDuration;
                    if (repetitionDuration.HasValue)
                    {
                        TimeSpan?nullable = jobTrigger.RepetitionInterval;
                        wTSString.Repetition.Interval = ScheduledJobWTS.ConvertTimeSpanToWTSString(nullable.Value);
                        TimeSpan?repetitionDuration1 = jobTrigger.RepetitionDuration;
                        if (repetitionDuration1.Value != TimeSpan.MaxValue)
                        {
                            wTSString.Repetition.StopAtDurationEnd = true;
                            TimeSpan?nullable1 = jobTrigger.RepetitionDuration;
                            wTSString.Repetition.Duration = ScheduledJobWTS.ConvertTimeSpanToWTSString(nullable1.Value);
                        }
                        else
                        {
                            wTSString.Repetition.StopAtDurationEnd = false;
                        }
                    }
                }
                str.StartBoundary = ScheduledJobWTS.ConvertDateTimeToString(jobTrigger.At);
                int id = jobTrigger.Id;
                str.Id      = id.ToString(CultureInfo.InvariantCulture);
                str.Enabled = jobTrigger.Enabled;
                return;
            }

            case TriggerFrequency.Daily:
            {
                str = iTaskDefinition.Triggers.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_DAILY);
                IDailyTrigger interval = str as IDailyTrigger;
                interval.RandomDelay  = ScheduledJobWTS.ConvertTimeSpanToWTSString(jobTrigger.RandomDelay);
                interval.DaysInterval = (short)jobTrigger.Interval;
                str.StartBoundary     = ScheduledJobWTS.ConvertDateTimeToString(jobTrigger.At);
                int num = jobTrigger.Id;
                str.Id      = num.ToString(CultureInfo.InvariantCulture);
                str.Enabled = jobTrigger.Enabled;
                return;
            }

            case TriggerFrequency.Weekly:
            {
                str = iTaskDefinition.Triggers.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_WEEKLY);
                IWeeklyTrigger mask = str as IWeeklyTrigger;
                mask.RandomDelay   = ScheduledJobWTS.ConvertTimeSpanToWTSString(jobTrigger.RandomDelay);
                mask.WeeksInterval = (short)jobTrigger.Interval;
                mask.DaysOfWeek    = ScheduledJobWTS.ConvertDaysOfWeekToMask(jobTrigger.DaysOfWeek);
                str.StartBoundary  = ScheduledJobWTS.ConvertDateTimeToString(jobTrigger.At);
                int id1 = jobTrigger.Id;
                str.Id      = id1.ToString(CultureInfo.InvariantCulture);
                str.Enabled = jobTrigger.Enabled;
                return;
            }

            case TriggerFrequency.AtLogon:
            {
                str = iTaskDefinition.Triggers.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_LOGON);
                ILogonTrigger variable  = str as ILogonTrigger;
                ILogonTrigger variable1 = variable;
                if (ScheduledJobTrigger.IsAllUsers(jobTrigger.User))
                {
                    user = null;
                }
                else
                {
                    user = jobTrigger.User;
                }
                variable1.UserId = user;
                variable.Delay   = ScheduledJobWTS.ConvertTimeSpanToWTSString(jobTrigger.RandomDelay);
                int num1 = jobTrigger.Id;
                str.Id      = num1.ToString(CultureInfo.InvariantCulture);
                str.Enabled = jobTrigger.Enabled;
                return;
            }

            case TriggerFrequency.AtStartup:
            {
                str = iTaskDefinition.Triggers.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_BOOT);
                IBootTrigger wTSString1 = str as IBootTrigger;
                wTSString1.Delay = ScheduledJobWTS.ConvertTimeSpanToWTSString(jobTrigger.RandomDelay);
                int id2 = jobTrigger.Id;
                str.Id      = id2.ToString(CultureInfo.InvariantCulture);
                str.Enabled = jobTrigger.Enabled;
                return;
            }

            default:
            {
                return;
            }
            }
        }