public IScheduleTrigger CreateTrigger(Trigger trigger)
        {
            switch(trigger.TriggerType)
            {
                case TaskTriggerType.Boot:
                    return new ScheduleTrigger(TaskState.Ready, new Dev2BootTrigger(_serviceConvertorFactory, trigger as BootTrigger), _service, _serviceConvertorFactory);
                case TaskTriggerType.Daily:
                    return new ScheduleTrigger(TaskState.Ready, new Dev2DailyTrigger(_serviceConvertorFactory, trigger as DailyTrigger), _service, _serviceConvertorFactory);
                case TaskTriggerType.Event:
                    return new ScheduleTrigger(TaskState.Ready, new Dev2EventTrigger(_serviceConvertorFactory, trigger as EventTrigger), _service, _serviceConvertorFactory);
                case TaskTriggerType.Idle:
                    return new ScheduleTrigger(TaskState.Ready, new Dev2IdleTrigger(_serviceConvertorFactory, trigger as IdleTrigger), _service, _serviceConvertorFactory);
                case TaskTriggerType.Logon:
                    return new ScheduleTrigger(TaskState.Ready, new Dev2LogonTrigger(_serviceConvertorFactory, trigger as LogonTrigger), _service, _serviceConvertorFactory);
                case TaskTriggerType.Monthly:
                    return new ScheduleTrigger(TaskState.Ready, new Dev2MonthlyTrigger(_serviceConvertorFactory, trigger as MonthlyTrigger), _service, _serviceConvertorFactory);
                case TaskTriggerType.MonthlyDOW:
                    return new ScheduleTrigger(TaskState.Ready, new Dev2MonthlyDowTrigger(_serviceConvertorFactory, trigger as MonthlyDOWTrigger), _service, _serviceConvertorFactory);
                case TaskTriggerType.Registration:
                    return new ScheduleTrigger(TaskState.Ready, new Dev2RegistrationTrigger(_serviceConvertorFactory, trigger as RegistrationTrigger), _service, _serviceConvertorFactory);
                case TaskTriggerType.SessionStateChange:
                    return new ScheduleTrigger(TaskState.Ready, new Dev2Trigger(_serviceConvertorFactory, trigger as SessionStateChangeTrigger), _service, _serviceConvertorFactory);
                case TaskTriggerType.Time:
                    return new ScheduleTrigger(TaskState.Ready, new Dev2TimeTrigger(_serviceConvertorFactory, trigger as TimeTrigger), _service, _serviceConvertorFactory);
                case TaskTriggerType.Weekly:
                    return new ScheduleTrigger(TaskState.Ready, new Dev2WeeklyTrigger(_serviceConvertorFactory, trigger), _service, _serviceConvertorFactory);
                default:
                    return new ScheduleTrigger(TaskState.Ready, new Dev2Trigger(_serviceConvertorFactory, trigger), _service, _serviceConvertorFactory);

            }
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="TriggerEditDialog"/> class.
		/// </summary>
		/// <param name="trigger">The <see cref="Trigger"/> to edit.</param>
		/// <param name="supportV1Only">If set to <c>true</c> support V1 triggers only.</param>
		public TriggerEditDialog(Trigger trigger, bool supportV1Only)
		{
			InitializeComponent();

			this.SupportV1Only = supportV1Only;

			// Populate combo boxes
			delaySpan.Items.AddRange(new TimeSpan2[] { TimeSpan2.FromSeconds(30), TimeSpan2.FromMinutes(1), TimeSpan2.FromMinutes(30), TimeSpan2.FromHours(1), TimeSpan2.FromHours(8), TimeSpan2.FromDays(1) });
			repeatSpan.Items.AddRange(new TimeSpan2[] { TimeSpan2.FromMinutes(5), TimeSpan2.FromMinutes(10), TimeSpan2.FromMinutes(15), TimeSpan2.FromMinutes(30), TimeSpan2.FromHours(1) });
			durationSpan.Items.AddRange(new TimeSpan2[] { TimeSpan2.Zero, TimeSpan2.FromMinutes(15), TimeSpan2.FromMinutes(30), TimeSpan2.FromHours(1), TimeSpan2.FromHours(12), TimeSpan2.FromDays(1) });
			durationSpan.FormattedZero = EditorProperties.Resources.TimeSpanIndefinitely;
			stopIfRunsSpan.Items.AddRange(new TimeSpan2[] { TimeSpan2.FromMinutes(30), TimeSpan2.FromHours(1), TimeSpan2.FromHours(2), TimeSpan2.FromHours(4), TimeSpan2.FromHours(8), TimeSpan2.FromHours(12), TimeSpan2.FromDays(1), TimeSpan2.FromDays(3) });

			if (trigger != null)
				this.Trigger = trigger;
			else
				this.Trigger = new TimeTrigger();
		}
 public IScheduledResource CreateResource(string name, SchedulerStatus status, Trigger trigger,
                                          string workflowName)
 {
     return new ScheduledResource(name, status, DateTime.MinValue, CreateTrigger(trigger), workflowName);
 }
        private static void CheckTriggerTypes(Trigger t)
        {
            IDev2TaskService s = new Dev2TaskService(new TaskServiceConvertorFactory());
            ITaskServiceConvertorFactory fact = new TaskServiceConvertorFactory();
            ServerSchedulerFactory schedulerFactory = new ServerSchedulerFactory(s, fact, new DirectoryHelper());


            var trig = schedulerFactory.CreateTrigger(t);
            Assert.AreEqual(t.TriggerType, trig.Trigger.TriggerType);
            Assert.AreEqual(t.ToString(), trig.Trigger.ToString());
        }
Esempio n. 5
0
 public Dev2WeeklyTrigger(ITaskServiceConvertorFactory taskServiceConvertorFactory, Trigger instance)
     : base(taskServiceConvertorFactory, instance)
 {
 }
Esempio n. 6
0
        /// <summary>
        /// Creates a new task, registers the taks, and returns the instance.
        /// </summary>
        /// <param name="path">The task name. If this value is NULL, the task will be registered in the root task folder and the task name will be a GUID value that is created by the Task Scheduler service. A task name cannot begin or end with a space character. The '.' character cannot be used to specify the current task folder and the '..' characters cannot be used to specify the parent task folder in the path.</param>
        /// <param name="trigger">The <see cref="Trigger"/> to determine when to run the task.</param>
        /// <param name="action">The <see cref="Action"/> to determine what happens when the task is triggered.</param>
        /// <returns>A <see cref="Task"/> instance of the registered task.</returns>
        public Task AddTask(string path, Trigger trigger, Action action)
        {
            TaskDefinition td = NewTask();
            td.Principal.LogonType = TaskLogonType.InteractiveToken;

            // Create a trigger that will fire the task at a specific date and time
            td.Triggers.Add(trigger);

            // Create an action that will launch Notepad whenever the trigger fires
            td.Actions.Add(action);

            // Register the task in the root folder
            return RootFolder.RegisterTaskDefinition(path, td);
        }
        private static IEnumerable<Trigger> ProcessCronTimes(CronExpression cron, Trigger baseTrigger)
        {
            List<Trigger> ret = new List<Trigger>();
            // A single time
            if (cron.Minutes.vals.Length == 1 && cron.Hours.vals.Length == 1)
            {
                baseTrigger.StartBoundary = baseTrigger.StartBoundary.Date + new TimeSpan(cron.Hours.vals[0], cron.Minutes.vals[0], 0);
                ret.Add(baseTrigger);
            }
            // Multiple, non-repeating, hours and/or minutes
            else if (cron.Minutes.vals.Length > 1 && !cron.Minutes.range && cron.Hours.vals.Length > 1 && !cron.Hours.range)
            {
                for (int h = 0; h < cron.Hours.vals.Length; h++)
                {
                    for (int m = 0; m < cron.Minutes.vals.Length; m++)
                    {
                        Trigger newTr = (Trigger)baseTrigger.Clone();
                        newTr.StartBoundary = newTr.StartBoundary.Date + new TimeSpan(cron.Hours.vals[h], cron.Minutes.vals[m], 0);
                        ret.Add(newTr);
                    }
                }
            }
            // Repeating hours and/or minutes
            else if (cron.Minutes.step > 0 || cron.Hours.step > 0)
            {
                int h_start = 0, h_end = 23, m_start = 0, m_end = 59;
                if (cron.Minutes.range)
                {
                    m_start = cron.Minutes.vals[0];
                    m_end = cron.Minutes.vals[1];
                }
                else if (cron.Minutes.vals.Length == 1)
                    m_start = m_end = cron.Minutes.vals[0];

                if (cron.Hours.range)
                {
                    h_start = cron.Hours.vals[0];
                    h_end = cron.Hours.vals[1];
                }
                else if (cron.Hours.vals.Length == 1)
                    h_start = h_end = cron.Hours.vals[0];

                if (h_start == h_end)
                {
                    Trigger newTr = (Trigger)baseTrigger.Clone();
                    newTr.StartBoundary = newTr.StartBoundary.Date + new TimeSpan(h_start, m_start, 0);
                    newTr.Repetition.Interval = TimeSpan.FromMinutes(cron.Minutes.step);
                    newTr.Repetition.Duration = TimeSpan.FromHours(1);
                    ret.Add(newTr);
                }
                else if (m_start == m_end)
                {
                    Trigger newTr = (Trigger)baseTrigger.Clone();
                    newTr.StartBoundary = newTr.StartBoundary.Date + new TimeSpan(h_start, m_start, 0);
                    newTr.Repetition.Interval = TimeSpan.FromHours(cron.Hours.step);
                    newTr.Repetition.Duration = TimeSpan.FromHours(h_end - h_start);
                    ret.Add(newTr);
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            return ret;
        }
Esempio n. 8
0
 public static bool TriggerEquals(Microsoft.Win32.TaskScheduler.Trigger a, Microsoft.Win32.TaskScheduler.Trigger b)
 {
     return(a.ToString() == b.ToString() && a.StartBoundary == b.StartBoundary && a.EndBoundary == b.EndBoundary && a.ExecutionTimeLimit == b.ExecutionTimeLimit);
 }
Esempio n. 9
0
 /// <summary>
 /// Copies the properties from another <see cref="Trigger"/> the current instance. This will not copy any properties associated with any derived triggers except those supporting the <see cref="ITriggerDelay"/> interface.
 /// </summary>
 /// <param name="sourceTrigger">The source <see cref="Trigger"/>.</param>
 public override void CopyProperties(Trigger sourceTrigger)
 {
     base.CopyProperties(sourceTrigger);
     if (sourceTrigger.GetType() == this.GetType())
     {
         this.DaysInterval = ((DailyTrigger)sourceTrigger).DaysInterval;
     }
 }
Esempio n. 10
0
 /// <summary>
 /// Copies the properties from another <see cref="Trigger"/> the current instance. This will not copy any properties associated with any derived triggers except those supporting the <see cref="ITriggerDelay"/> interface.
 /// </summary>
 /// <param name="sourceTrigger">The source <see cref="Trigger"/>.</param>
 public virtual void CopyProperties(Trigger sourceTrigger)
 {
     this.Enabled = sourceTrigger.Enabled;
     this.EndBoundary = sourceTrigger.EndBoundary;
     try { this.ExecutionTimeLimit = sourceTrigger.ExecutionTimeLimit; }
     catch { }
     this.Repetition.Duration = sourceTrigger.Repetition.Duration;
     this.Repetition.Interval = sourceTrigger.Repetition.Interval;
     this.Repetition.StopAtDurationEnd = sourceTrigger.Repetition.StopAtDurationEnd;
     this.StartBoundary = sourceTrigger.StartBoundary;
     if (sourceTrigger is ITriggerDelay && this is ITriggerDelay)
         try { ((ITriggerDelay)this).Delay = ((ITriggerDelay)sourceTrigger).Delay; }
         catch { }
     if (sourceTrigger is ITriggerUserId && this is ITriggerUserId)
         try { ((ITriggerUserId)this).UserId = ((ITriggerUserId)sourceTrigger).UserId; }
         catch { }
 }
Esempio n. 11
0
 /// <summary>
 /// Copies the properties from another <see cref="Trigger"/> the current instance. This will not copy any properties associated with any derived triggers except those supporting the <see cref="ITriggerDelay"/> interface.
 /// </summary>
 /// <param name="sourceTrigger">The source <see cref="Trigger"/>.</param>
 public override void CopyProperties(Trigger sourceTrigger)
 {
     base.CopyProperties(sourceTrigger);
     if (sourceTrigger.GetType() == this.GetType())
         this.StateChange = ((SessionStateChangeTrigger)sourceTrigger).StateChange;
 }
Esempio n. 12
0
 internal RepetitionPattern(Trigger parent)
 {
     pTrigger = parent;
     if (pTrigger.v2Trigger != null)
         v2Pattern = pTrigger.v2Trigger.Repetition;
 }
		private void triggerSelectPage_Commit(object sender, AeroWizard.WizardPageConfirmEventArgs e)
		{
			bool hasValue = (this.trigger != null);
			AvailableWizardTriggers selTrig = (AvailableWizardTriggers)triggerSelectionList.SelectedItem.Tag;
			switch (selTrig)
			{
				case AvailableWizardTriggers.Event:
					e.Page.NextPage = onEventTriggerPage;
					if (!hasValue || this.trigger.TriggerType != TaskTriggerType.Event)
						trigger = new EventTrigger();
					break;
				case AvailableWizardTriggers.Time:
					e.Page.NextPage = oneTimeTriggerPage;
					if (!hasValue || this.trigger.TriggerType != TaskTriggerType.Time)
						trigger = new TimeTrigger();
					oneTimeStartTimePicker.Value = trigger.StartBoundary;
					break;
				case AvailableWizardTriggers.Daily:
					e.Page.NextPage = dailyTriggerPage;
					if (!hasValue || this.trigger.TriggerType != TaskTriggerType.Daily)
						dailyTriggerUI1.Trigger = (trigger = new DailyTrigger());
					break;
				case AvailableWizardTriggers.Weekly:
					e.Page.NextPage = weeklyTriggerPage;
					if (!hasValue || this.trigger.TriggerType != TaskTriggerType.Weekly)
						weeklyTriggerUI1.Trigger = (trigger = new WeeklyTrigger());
					break;
				case AvailableWizardTriggers.Monthly:
					e.Page.NextPage = monthlyTriggerPage;
					if (!hasValue || (this.trigger.TriggerType != TaskTriggerType.Monthly && this.trigger.TriggerType != TaskTriggerType.MonthlyDOW))
						monthlyTriggerUI1.Trigger = (trigger = new MonthlyTrigger());
					break;
				case AvailableWizardTriggers.Idle:
					e.Page.NextPage = actionSelectPage;
					if (!hasValue || this.trigger.TriggerType != TaskTriggerType.Idle)
						trigger = new IdleTrigger();
					break;
				case AvailableWizardTriggers.Boot:
					e.Page.NextPage = actionSelectPage;
					if (!hasValue || this.trigger.TriggerType != TaskTriggerType.Boot)
						trigger = new BootTrigger();
					break;
				case AvailableWizardTriggers.Logon:
					e.Page.NextPage = actionSelectPage;
					if (!hasValue || this.trigger.TriggerType != TaskTriggerType.Logon)
						trigger = new LogonTrigger();
					break;
				default:
					e.Cancel = true;
					break;
			}
			if (e.Page.NextPage != actionSelectPage && e.Page.NextPage != null)
				e.Page.NextPage.NextPage = actionSelectPage;
		}
		private void onEventTriggerPage_Commit(object sender, AeroWizard.WizardPageConfirmEventArgs e)
		{
			trigger = eventTriggerUI1.Trigger;
		}
		private void monthlyTriggerUI1_TriggerTypeChanged(object sender, EventArgs e)
		{
			if (!onAssignment)
			{
				Trigger newTrigger = null;
				if (monthlyTriggerUI1.TriggerType == TaskTriggerType.Monthly)
					newTrigger = new MonthlyTrigger();
				else
					newTrigger = new MonthlyDOWTrigger();
				if (trigger != null)
					newTrigger.CopyProperties(trigger);
				monthlyTriggerUI1.Trigger = (trigger = newTrigger);
			}
		}
 public ITrigger CreateTrigger(Trigger trigger)
 {
     return new Dev2Trigger(this, trigger);
 }
Esempio n. 17
0
 public Dev2Trigger(ITaskServiceConvertorFactory taskServiceConvertorFactory, Trigger instance)
 {
     _taskServiceConvertorFactory = taskServiceConvertorFactory;
     _instance = instance;
 }
Esempio n. 18
0
 /// <summary>
 /// Copies the properties from another <see cref="Trigger"/> the current instance. This will not copy any properties associated with any derived triggers except those supporting the <see cref="ITriggerDelay"/> interface.
 /// </summary>
 /// <param name="sourceTrigger">The source <see cref="Trigger"/>.</param>
 public override void CopyProperties(Trigger sourceTrigger)
 {
     base.CopyProperties(sourceTrigger);
     this.Subscription = ((EventTrigger)sourceTrigger).Subscription;
     ((EventTrigger)sourceTrigger).ValueQueries.CopyTo(this.ValueQueries);
 }
Esempio n. 19
0
 /// <summary>
 /// Copies the properties from another <see cref="Trigger"/> the current instance. This will not copy any properties associated with any derived triggers except those supporting the <see cref="ITriggerDelay"/> interface.
 /// </summary>
 /// <param name="sourceTrigger">The source <see cref="Trigger"/>.</param>
 public override void CopyProperties(Trigger sourceTrigger)
 {
     base.CopyProperties(sourceTrigger);
     if (sourceTrigger.GetType() == this.GetType())
     {
         this.DaysOfWeek = ((MonthlyDOWTrigger)sourceTrigger).DaysOfWeek;
         this.MonthsOfYear = ((MonthlyDOWTrigger)sourceTrigger).MonthsOfYear;
         try { this.RunOnLastWeekOfMonth = ((MonthlyDOWTrigger)sourceTrigger).RunOnLastWeekOfMonth; } catch { }
         this.WeeksOfMonth = ((MonthlyDOWTrigger)sourceTrigger).WeeksOfMonth;
     }
 }
        /// <summary>
        /// Creates a new task, registers the taks, and returns the instance.
        /// </summary>
        /// <param name="path">The task name. If this value is NULL, the task will be registered in the root task folder and the task name will be a GUID value that is created by the Task Scheduler service. A task name cannot begin or end with a space character. The '.' character cannot be used to specify the current task folder and the '..' characters cannot be used to specify the parent task folder in the path.</param>
        /// <param name="trigger">The <see cref="Trigger"/> to determine when to run the task.</param>
        /// <param name="action">The <see cref="Action"/> to determine what happens when the task is triggered.</param>
        /// <param name="UserId">The user credentials used to register the task.</param>
        /// <param name="Password">The password for the userId used to register the task.</param>
        /// <param name="LogonType">A <see cref="TaskLogonType"/> value that defines what logon technique is used to run the registered task.</param>
        /// <returns>
        /// A <see cref="Task"/> instance of the registered task.
        /// </returns>
        public Task AddTask(string path, Trigger trigger, Action action, string UserId = null, string Password = null, TaskLogonType LogonType = TaskLogonType.InteractiveToken)
        {
            TaskDefinition td = NewTask();

            // Create a trigger that will fire the task at a specific date and time
            td.Triggers.Add(trigger);

            // Create an action that will launch Notepad whenever the trigger fires
            td.Actions.Add(action);

            // Register the task in the root folder
            return RootFolder.RegisterTaskDefinition(path, td, TaskCreation.CreateOrUpdate, UserId, Password, LogonType);
        }