public void Dev2RegistrationTrigger_Construct_Test()
        {

            var idleTrigger = new RegistrationTrigger();
            Dev2RegistrationTrigger wrappedIdle = new Dev2RegistrationTrigger(_taskServiceConvertorFactory.Object, idleTrigger);
            Assert.AreEqual(idleTrigger, wrappedIdle.Instance);

        }
		private void triggerTypeCombo_SelectedValueChanged(object sender, EventArgs e)
		{
			if (triggerTypeCombo.SelectedValue == null)
				return;

			Trigger newTrigger = null;
			switch (TriggerView)
			{
				case TaskTriggerDisplayType.Schedule:
				default:
					settingsTabControl.SelectedTab = scheduleTab;
					if (!onAssignment)
					{
						schedOneRadio.Checked = schedMonthlyRadio.Checked = schedDailyRadio.Checked = schedWeeklyRadio.Checked = false;
						schedOneRadio.Checked = true;
						return;
					}
					break;
				case TaskTriggerDisplayType.Logon:
					logonRemotePanel.Visible = false;
					settingsTabControl.SelectedTab = logonTab;
					if (!onAssignment) newTrigger = new LogonTrigger();
					break;
				case TaskTriggerDisplayType.Boot:
					settingsTabControl.SelectedTab = startupTab;
					if (!onAssignment) newTrigger = new BootTrigger();
					break;
				case TaskTriggerDisplayType.Idle:
					settingsTabControl.SelectedTab = idleTab;
					if (!onAssignment) newTrigger = new IdleTrigger();
					break;
				case TaskTriggerDisplayType.Event:
					settingsTabControl.SelectedTab = onEventTab;
					if (!onAssignment) newTrigger = new EventTrigger();
					break;
				case TaskTriggerDisplayType.Registration:
					settingsTabControl.SelectedTab = startupTab;
					if (!onAssignment) newTrigger = new RegistrationTrigger();
					break;
				case TaskTriggerDisplayType.SessionConnect:
				case TaskTriggerDisplayType.SessionDisconnect:
				case TaskTriggerDisplayType.WorkstationLock:
				case TaskTriggerDisplayType.WorkstationUnlock:
					logonRemotePanel.Visible = (int)TriggerView < (int)TaskTriggerDisplayType.WorkstationLock;
					settingsTabControl.SelectedTab = logonTab;
					if (!onAssignment)
						newTrigger = new SessionStateChangeTrigger() { StateChange = (TaskSessionStateChangeType)(TriggerView - 110) };
					break;
				case TaskTriggerDisplayType.Custom:
					settingsTabControl.SelectedTab = customTab;
					triggerTypeCombo.Enabled = okBtn.Enabled = false;
					break;
			}

			if (newTrigger != null && !onAssignment)
			{
				if (trigger != null)
					newTrigger.CopyProperties(trigger);
				this.Trigger = newTrigger;
			}
		}
예제 #3
0
파일: Form1.cs 프로젝트: dlmotter/Sandbox
        private void setScheduledEvents()
        {
            using (TaskService taskService = new TaskService())
            {
                // Delete old task if it exists
                if (taskService.FindTask("Wallpaper Setter") != null)
                {
                    taskService.RootFolder.DeleteTask("Wallpaper Setter");
                }

                // Define the trigger
                Trigger trigger;
                if (frequencyDdl.Text.Equals("Hour") || frequencyDdl.Text.Equals("Minute"))
                {
                    // Run either every hour or every minute from registration
                    trigger = new RegistrationTrigger();
                    if (frequencyDdl.Text.Equals("Hour"))
                    {
                        trigger.Repetition = new RepetitionPattern(new TimeSpan(1, 0, 0), TimeSpan.Zero);
                    }
                    else
                    {
                        trigger.Repetition = new RepetitionPattern(new TimeSpan(0, 1, 0), TimeSpan.Zero);
                    }
                }
                else
                {
                    // If they specify daily, or don't specify a frequency, run every day at 6 am
                    // TODO make that time configurable
                    DateTime now = DateTime.Now;
                    DateTime next = now.Date.AddHours(24 + 6);
                    next = next.AddDays((now - next).Days);

                    trigger = new DailyTrigger();
                    trigger.StartBoundary = next;
                }

                // Define the task
                TaskDefinition newTask = taskService.NewTask();
                newTask.RegistrationInfo.Description = "Wallpaper Setter";
                newTask.Triggers.Add(trigger);
                newTask.Actions.Add(new ExecAction(utilPath, workingDirectory: Directory.GetCurrentDirectory()));
                newTask.Settings.Enabled = true;
                taskService.RootFolder.RegisterTaskDefinition("Wallpaper Setter", newTask);

                // Registration triggers get run automatically when created. But other types don't, so run manually if needed.
                if (newTask.Triggers[0].TriggerType != TaskTriggerType.Registration)
                {
                    taskService.RootFolder.Tasks["Wallpaper Setter"].Run();
                }
            }
        }