Exemplo n.º 1
0
        private void setupTask(string tskName)
        {
            using (Scheduler.TaskService tsrv = new Scheduler.TaskService()) {
                Scheduler.TaskDefinition tskDef = tsrv.FindTask(tskName).Definition;

                tskDef.Settings.DisallowStartIfOnBatteries = false;
                tskDef.Settings.RunOnlyIfNetworkAvailable  = true;
                tskDef.RegistrationInfo.Author             = _taskAuthor;
                tskDef.RegistrationInfo.Documentation      = "TimeSharp time keeper utility";
                tskDef.Principal.RunLevel         = Scheduler.TaskRunLevel.Highest;
                tskDef.Settings.MultipleInstances = Scheduler.TaskInstancesPolicy.IgnoreNew;
                tskDef.Settings.WakeToRun         = false;
                tskDef.Settings.Compatibility     = Scheduler.TaskCompatibility.V2_1;

                //add auxiliary triggers
                Scheduler.SessionStateChangeTrigger unlockSessionTrigger = new Scheduler.SessionStateChangeTrigger(Scheduler.TaskSessionStateChangeType.SessionUnlock)
                {
                    Enabled = true
                };
                Scheduler.LogonTrigger logonTrigger = new Scheduler.LogonTrigger()
                {
                    Enabled            = true,
                    Delay              = TimeSpan.FromMinutes(1),
                    StartBoundary      = DateTime.Now,
                    ExecutionTimeLimit = TimeSpan.FromMinutes(5)
                };
                tskDef.Triggers.AddRange(new Scheduler.Trigger[] { unlockSessionTrigger, logonTrigger });

                tsrv.RootFolder.RegisterTaskDefinition(tskName, tskDef,
                                                       Scheduler.TaskCreation.CreateOrUpdate, _adminsGroupName, null,
                                                       Scheduler.TaskLogonType.Group);
            }
        }
		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;
			}
		}