// Constructors public TaskSetting(string taskSettingId, string taskSettingName, ITaskTrigger taskTrigger, ITaskAction taskAction) { #region Contracts if (string.IsNullOrEmpty(taskSettingName) == true) { throw new ArgumentNullException(); } if (taskTrigger == null) { throw new ArgumentNullException(); } if (taskAction == null) { throw new ArgumentNullException(); } #endregion // Arguments this.TaskSettingId = taskSettingId; this.TaskSettingName = taskSettingName; this.TaskTrigger = taskTrigger; this.TaskAction = taskAction; }
public virtual void Dispose() { if (iTrigger != null) { Marshal.ReleaseComObject(iTrigger); iTrigger = null; } }
/// <summary> /// Break the connection between this Trigger and the system Task Scheduler. This /// releases COM resources used in bound Triggers. /// </summary> internal void Unbind() { if (iTaskTrigger != null) { Marshal.ReleaseComObject(iTaskTrigger); iTaskTrigger = null; } }
internal virtual void Bind(ITask iTask) { if (_v1Trigger == null) { ushort num; _v1Trigger = iTask.CreateTrigger(out num); } SetV1TriggerData(); }
/// <summary> /// Internal base constructor for an unbound Trigger. /// </summary> internal Trigger() { iTaskTrigger = null; taskTrigger = new TaskTrigger(); taskTrigger.TriggerSize = (ushort)Marshal.SizeOf(taskTrigger); taskTrigger.BeginYear = (ushort)DateTime.Today.Year; taskTrigger.BeginMonth = (ushort)DateTime.Today.Month; taskTrigger.BeginDay = (ushort)DateTime.Today.Day; }
/// <summary> /// Bind a Trigger object to an ITaskTrigger interface. This causes the Trigger to /// sync itself with the interface and remain in sync whenever it is modified in the future. /// If the Trigger is already bound, an ArgumentException is thrown. /// </summary> /// <param name="iTaskTrigger">An interface representing a trigger in Task Scheduler.</param> /// <exception cref="ArgumentException">Attempt to bind and already bound trigger.</exception> internal void Bind(ITaskTrigger iTaskTrigger) { if (this.iTaskTrigger != null) { throw new ArgumentException("Attempt to bind an already bound trigger"); } this.iTaskTrigger = iTaskTrigger; iTaskTrigger.SetTrigger(ref taskTrigger); }
/// <summary> /// Internal base constructor for an unbound Trigger. /// </summary> internal Trigger() { iTaskTrigger = null; taskTrigger = new TaskTrigger(); taskTrigger.TriggerSize = (ushort)Marshal.SizeOf(taskTrigger); taskTrigger.BeginYear = (ushort)DateTime.Today.Year; taskTrigger.BeginMonth = (ushort)DateTime.Today.Month; taskTrigger.BeginDay = (ushort)DateTime.Today.Day; }
internal virtual void Bind(ITask iTask) { if (_v1Trigger == null) { ushort num; _v1Trigger = iTask.CreateTrigger(out num); } SetV1TriggerData(); }
/// <summary> /// Internal constructor which initializes itself from /// from an ITaskTrigger interface. /// </summary> /// <param name="iTrigger">Instance of ITaskTrigger from system task scheduler.</param> internal Trigger(ITaskTrigger iTrigger) { if (iTrigger == null) throw new ArgumentNullException("iTrigger", "ITaskTrigger instance cannot be null"); taskTrigger = new TaskTrigger(); taskTrigger.TriggerSize = (ushort)Marshal.SizeOf(taskTrigger); iTrigger.GetTrigger(ref taskTrigger); iTaskTrigger = iTrigger; }
/// <summary> /// Gets the default triggers. /// </summary> /// <returns>IEnumerable{BaseTaskTrigger}.</returns> public IEnumerable<ITaskTrigger> GetDefaultTriggers() { var list = new ITaskTrigger[] { new IntervalTrigger{ Interval = TimeSpan.FromHours(12)} }.ToList(); return list; }
/// <summary> /// Gets the default triggers. /// </summary> /// <returns>IEnumerable{BaseTaskTrigger}.</returns> public IEnumerable <ITaskTrigger> GetDefaultTriggers() { var list = new ITaskTrigger[] { new IntervalTrigger { Interval = TimeSpan.FromHours(12) } }.ToList(); return(list); }
/// <summary> /// Internal constructor which initializes itself from /// from an ITaskTrigger interface. /// </summary> /// <param name="iTrigger">Instance of ITaskTrigger from system task scheduler.</param> internal Trigger(ITaskTrigger iTrigger) { if (iTrigger == null) { throw new ArgumentNullException("iTrigger", "ITaskTrigger instance cannot be null"); } taskTrigger = new TaskTrigger(); taskTrigger.TriggerSize = (ushort)Marshal.SizeOf(taskTrigger); iTrigger.GetTrigger(ref taskTrigger); iTaskTrigger = iTrigger; }
// Concat public static ITaskTrigger Concat(this ITaskTrigger firstTrigger, ITaskTrigger secondTrigger) { #region Contracts if (firstTrigger == null) throw new ArgumentNullException(); if (secondTrigger == null) throw new ArgumentNullException(); #endregion // Return return new ConcatTrigger(firstTrigger, secondTrigger); }
// Constructors public ConcatTrigger(ITaskTrigger firstTrigger, ITaskTrigger secondTrigger) { #region Contracts if (firstTrigger == null) throw new ArgumentNullException(); if (secondTrigger == null) throw new ArgumentNullException(); #endregion // Arguments _firstTrigger = firstTrigger; _secondTrigger = secondTrigger; }
/// <summary> /// Gets the default triggers. /// </summary> /// <returns>IEnumerable{BaseTaskTrigger}.</returns> public IEnumerable <ITaskTrigger> GetDefaultTriggers() { var list = new ITaskTrigger[] { new IntervalTrigger { Interval = TimeSpan.FromHours(12) } }.ToList(); if (!_config.Configuration.DisableStartupScan) { list.Add(new StartupTrigger()); } return(list); }
/// <summary> /// Gets the default triggers. /// </summary> /// <returns>IEnumerable{BaseTaskTrigger}.</returns> public IEnumerable<ITaskTrigger> GetDefaultTriggers() { var list = new ITaskTrigger[] { new IntervalTrigger{ Interval = TimeSpan.FromHours(12)} }.ToList(); if (!_config.Configuration.DisableStartupScan) { list.Add(new StartupTrigger()); } return list; }
// Constructors public TaskSetting(string taskSettingId, string taskSettingName, ITaskTrigger taskTrigger, ITaskAction taskAction) { #region Contracts if (string.IsNullOrEmpty(taskSettingName) == true) throw new ArgumentNullException(); if (taskTrigger == null) throw new ArgumentNullException(); if (taskAction == null) throw new ArgumentNullException(); #endregion // Arguments this.TaskSettingId = taskSettingId; this.TaskSettingName = taskSettingName; this.TaskTrigger = taskTrigger; this.TaskAction = taskAction; }
public static TaskResult Execute(this ITaskTrigger job, Func <TaskResult> action, double timeoutInMilliseconds, CancellationToken token) { try { SystemTasks.Task.Delay(TimeSpan.FromMilliseconds(timeoutInMilliseconds), token).Wait(token); if (token.IsCancellationRequested) { return(TaskResult.Aborted); } return(action()); } catch (Exception e) { return(TaskResult.Aborted); } }
// Concat public static ITaskTrigger Concat(this ITaskTrigger firstTrigger, ITaskTrigger secondTrigger) { #region Contracts if (firstTrigger == null) { throw new ArgumentNullException(); } if (secondTrigger == null) { throw new ArgumentNullException(); } #endregion // Return return(new ConcatTrigger(firstTrigger, secondTrigger)); }
// Constructors public ConcatTrigger(ITaskTrigger firstTrigger, ITaskTrigger secondTrigger) { #region Contracts if (firstTrigger == null) { throw new ArgumentNullException(); } if (secondTrigger == null) { throw new ArgumentNullException(); } #endregion // Arguments _firstTrigger = firstTrigger; _secondTrigger = secondTrigger; }
/// <summary> /// Gets the trigger info. /// </summary> /// <param name="trigger">The trigger.</param> /// <returns>TaskTriggerInfo.</returns> public static TaskTriggerInfo GetTriggerInfo(ITaskTrigger trigger) { var info = new TaskTriggerInfo { Type = trigger.GetType().Name }; var dailyTrigger = trigger as DailyTrigger; if (dailyTrigger != null) { info.TimeOfDayTicks = dailyTrigger.TimeOfDay.Ticks; } var weeklyTaskTrigger = trigger as WeeklyTrigger; if (weeklyTaskTrigger != null) { info.TimeOfDayTicks = weeklyTaskTrigger.TimeOfDay.Ticks; info.DayOfWeek = weeklyTaskTrigger.DayOfWeek; } var intervalTaskTrigger = trigger as IntervalTrigger; if (intervalTaskTrigger != null) { info.IntervalTicks = intervalTaskTrigger.Interval.Ticks; } var systemEventTrigger = trigger as SystemEventTrigger; if (systemEventTrigger != null) { info.SystemEvent = systemEventTrigger.SystemEvent; } if (trigger.TaskOptions != null) { info.MaxRuntimeMs = trigger.TaskOptions.MaxRuntimeMs; } return info; }
/// <summary> /// Gets the trigger info. /// </summary> /// <param name="trigger">The trigger.</param> /// <returns>TaskTriggerInfo.</returns> public static TaskTriggerInfo GetTriggerInfo(ITaskTrigger trigger) { var info = new TaskTriggerInfo { Type = trigger.GetType().Name }; var dailyTrigger = trigger as DailyTrigger; if (dailyTrigger != null) { info.TimeOfDayTicks = dailyTrigger.TimeOfDay.Ticks; } var weeklyTaskTrigger = trigger as WeeklyTrigger; if (weeklyTaskTrigger != null) { info.TimeOfDayTicks = weeklyTaskTrigger.TimeOfDay.Ticks; info.DayOfWeek = weeklyTaskTrigger.DayOfWeek; } var intervalTaskTrigger = trigger as IntervalTrigger; if (intervalTaskTrigger != null) { info.IntervalTicks = intervalTaskTrigger.Interval.Ticks; } var systemEventTrigger = trigger as SystemEventTrigger; if (systemEventTrigger != null) { info.SystemEvent = systemEventTrigger.SystemEvent; } if (trigger.TaskOptions != null) { info.MaxRuntimeMs = trigger.TaskOptions.MaxRuntimeMs; } return(info); }
/// <summary> /// Creates a new, bound Trigger object from an ITaskTrigger interface. The type of the /// concrete object created is determined by the type of ITaskTrigger. /// </summary> /// <param name="iTaskTrigger">Instance of ITaskTrigger.</param> /// <returns>One of the concrete classes derived from Trigger.</returns> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentException">Unable to recognize trigger type.</exception> internal static Trigger CreateTrigger(ITaskTrigger iTaskTrigger) { if (iTaskTrigger == null) { throw new ArgumentNullException("iTaskTrigger", "Instance of ITaskTrigger cannot be null"); } TaskTrigger sTaskTrigger = new TaskTrigger(); sTaskTrigger.TriggerSize = (ushort)Marshal.SizeOf(sTaskTrigger); iTaskTrigger.GetTrigger(ref sTaskTrigger); switch ((TriggerType)sTaskTrigger.Type) { case TriggerType.RunOnce: return(new RunOnceTrigger(iTaskTrigger)); case TriggerType.RunDaily: return(new DailyTrigger(iTaskTrigger)); case TriggerType.RunWeekly: return(new WeeklyTrigger(iTaskTrigger)); case TriggerType.RunMonthlyDOW: return(new MonthlyDOWTrigger(iTaskTrigger)); case TriggerType.RunMonthly: return(new MonthlyTrigger(iTaskTrigger)); case TriggerType.OnIdle: return(new OnIdleTrigger(iTaskTrigger)); case TriggerType.OnSystemStart: return(new OnSystemStartTrigger(iTaskTrigger)); case TriggerType.OnLogon: return(new OnLogonTrigger(iTaskTrigger)); default: throw new ArgumentException("Unable to recognize type of trigger referenced in iTaskTrigger", "iTaskTrigger"); } }
internal static Trigger CreateTrigger(ITaskTrigger trigger, V1Interop.TaskTriggerType triggerType) { switch (triggerType) { case V1Interop.TaskTriggerType.RunOnce: return(new TimeTrigger(trigger)); case V1Interop.TaskTriggerType.RunDaily: return(new DailyTrigger(trigger)); case V1Interop.TaskTriggerType.RunWeekly: return(new WeeklyTrigger(trigger)); case V1Interop.TaskTriggerType.RunMonthly: return(new MonthlyTrigger(trigger)); case V1Interop.TaskTriggerType.RunMonthlyDOW: return(new MonthlyDOWTrigger(trigger)); case V1Interop.TaskTriggerType.OnIdle: return(new IdleTrigger(trigger)); case V1Interop.TaskTriggerType.OnSystemStart: return(new BootTrigger(trigger)); case V1Interop.TaskTriggerType.OnLogon: return(new LogonTrigger(trigger)); } return(null); }
internal BootTrigger(ITaskTrigger iTrigger) : base(iTrigger, TaskTriggerType.OnSystemStart) { }
internal static Trigger CreateTrigger(ITaskTrigger trigger) { return CreateTrigger(trigger, trigger.GetTrigger().Type); }
internal BootTrigger(ITaskTrigger iTrigger) : base(iTrigger, TaskTriggerType.OnSystemStart) { }
/// <summary> /// Internal constructor from ITaskTrigger interface. /// </summary> /// <param name="iTrigger">ITaskTrigger from system Task Scheduler.</param> internal StartableTrigger(ITaskTrigger iTrigger) : base(iTrigger) { }
internal IdleTrigger(ITaskTrigger iTrigger) : base(iTrigger, TaskTriggerType.OnIdle) { }
internal MonthlyTrigger(ITaskTrigger iTrigger) : base(iTrigger, TaskTriggerType.RunMonthly) { }
public WorkTask(string name, ITask task, ITaskTrigger taskTrigger) { this.Name = name; this.TaskTrigger = taskTrigger; this.Task = task; }
/// <summary> /// Internal constructor to create from existing ITaskTrigger interface. /// </summary> /// <param name="iTrigger">ITaskTrigger from system Task Scheduler.</param> internal RunOnceTrigger(ITaskTrigger iTrigger) : base(iTrigger) { }
/// <summary> /// Internal constructor to create from existing ITaskTrigger interface. /// </summary> /// <param name="iTrigger">ITaskTrigger interface from system Task Scheduler.</param> internal WeeklyTrigger(ITaskTrigger iTrigger) : base(iTrigger) { }
/// <summary> /// Internal constructor to create from existing ITaskTrigger interface. /// </summary> /// <param name="iTrigger">ITaskTrigger interface from system Task Scheduler.</param> internal OnSystemStartTrigger(ITaskTrigger iTrigger) : base(iTrigger) { }
internal Trigger(ITaskTrigger trigger, TaskTrigger data) { _v1Trigger = trigger; _v1TriggerData = data; _ttype = ConvertFromV1TriggerType(data.Type); }
/// <summary> /// Internal constructor to create from existing ITaskTrigger interface. /// </summary> /// <param name="iTrigger">ITaskTrigger from system Task Scheduler.</param> internal MonthlyTrigger(ITaskTrigger iTrigger) : base(iTrigger) { }
/// <summary> /// Internal constructor to create from existing ITaskTrigger interface. /// </summary> /// <param name="iTrigger">ITaskTrigger interface from system Task Scheduler.</param> internal WeeklyTrigger(ITaskTrigger iTrigger) : base(iTrigger) { }
/// <summary> /// Internal constructor to create from existing ITaskTrigger interface. /// </summary> /// <param name="iTrigger">ITaskTrigger from system Task Scheduler.</param> internal RunOnceTrigger(ITaskTrigger iTrigger) : base(iTrigger) { }
/// <summary> /// Internal constructor to create from existing ITaskTrigger interface. /// </summary> /// <param name="iTrigger">ITaskTrigger interface from system Task Scheduler.</param> internal OnSystemStartTrigger(ITaskTrigger iTrigger) : base(iTrigger) { }
/// <summary> /// Internal constructor to create from existing ITaskTrigger interface. /// </summary> /// <param name="iTrigger">Current base Trigger.</param> internal OnIdleTrigger(ITaskTrigger iTrigger) : base(iTrigger) { }
/// <summary> /// Internal constructor to create from existing ITaskTrigger interface. /// </summary> /// <param name="iTrigger">ITaskTrigger from system Task Scheduler.</param> internal OnLogonTrigger(ITaskTrigger iTrigger) : base(iTrigger) { }
/// <summary> /// Bind a Trigger object to an ITaskTrigger interface. This causes the Trigger to /// sync itself with the interface and remain in sync whenever it is modified in the future. /// If the Trigger is already bound, an ArgumentException is thrown. /// </summary> /// <param name="iTaskTrigger">An interface representing a trigger in Task Scheduler.</param> /// <exception cref="ArgumentException">Attempt to bind and already bound trigger.</exception> internal void Bind(ITaskTrigger iTaskTrigger) { if (this.iTaskTrigger != null) throw new ArgumentException("Attempt to bind an already bound trigger"); this.iTaskTrigger = iTaskTrigger; iTaskTrigger.SetTrigger(ref taskTrigger); }
internal MonthlyDOWTrigger(ITaskTrigger iTrigger) : base(iTrigger, V1.TaskTriggerType.RunMonthlyDOW) { }
internal static Trigger CreateTrigger(ITaskTrigger trigger, V1Interop.TaskTriggerType triggerType) { switch (triggerType) { case V1Interop.TaskTriggerType.RunOnce: return new TimeTrigger(trigger); case V1Interop.TaskTriggerType.RunDaily: return new DailyTrigger(trigger); case V1Interop.TaskTriggerType.RunWeekly: return new WeeklyTrigger(trigger); case V1Interop.TaskTriggerType.RunMonthly: return new MonthlyTrigger(trigger); case V1Interop.TaskTriggerType.RunMonthlyDOW: return new MonthlyDOWTrigger(trigger); case V1Interop.TaskTriggerType.OnIdle: return new IdleTrigger(trigger); case V1Interop.TaskTriggerType.OnSystemStart: return new BootTrigger(trigger); case V1Interop.TaskTriggerType.OnLogon: return new LogonTrigger(trigger); } return null; }
internal LogonTrigger(ITaskTrigger iTrigger) : base(iTrigger, TaskTriggerType.OnLogon) { }
internal Trigger(ITaskTrigger trigger, V1Interop.TaskTriggerType type) : this(trigger, trigger.GetTrigger()) { }
/// <summary> /// Internal constructor from ITaskTrigger interface. /// </summary> /// <param name="iTrigger">ITaskTrigger from system Task Scheduler.</param> internal StartableTrigger(ITaskTrigger iTrigger) : base(iTrigger) { }
/// <summary> /// Internal constructor to create from existing ITaskTrigger interface. /// </summary> /// <param name="iTrigger">ITaskTrigger from system Task Scheduler.</param> internal DailyTrigger(ITaskTrigger iTrigger) : base(iTrigger) { }
/// <summary> /// Internal constructor to create from existing ITaskTrigger interface. /// </summary> /// <param name="iTrigger">ITaskTrigger from system Task Scheduler.</param> internal DailyTrigger(ITaskTrigger iTrigger) : base(iTrigger) { }
internal static Trigger CreateTrigger(ITaskTrigger trigger) { return(CreateTrigger(trigger, trigger.GetTrigger().Type)); }
/// <summary> /// Internal constructor to create from existing ITaskTrigger interface. /// </summary> /// <param name="iTrigger">ITaskTrigger from system Task Scheduler.</param> internal MonthlyTrigger(ITaskTrigger iTrigger) : base(iTrigger) { }
internal Trigger(ITaskTrigger trigger, TaskTrigger data) { _v1Trigger = trigger; _v1TriggerData = data; _ttype = ConvertFromV1TriggerType(data.Type); }
/// <summary> /// Creates a new, bound Trigger object from an ITaskTrigger interface. The type of the /// concrete object created is determined by the type of ITaskTrigger. /// </summary> /// <param name="iTaskTrigger">Instance of ITaskTrigger.</param> /// <returns>One of the concrete classes derived from Trigger.</returns> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentException">Unable to recognize trigger type.</exception> internal static Trigger CreateTrigger(ITaskTrigger iTaskTrigger) { if (iTaskTrigger == null) throw new ArgumentNullException("iTaskTrigger", "Instance of ITaskTrigger cannot be null"); TaskTrigger sTaskTrigger = new TaskTrigger(); sTaskTrigger.TriggerSize = (ushort)Marshal.SizeOf(sTaskTrigger); iTaskTrigger.GetTrigger(ref sTaskTrigger); switch ((TriggerType)sTaskTrigger.Type) { case TriggerType.RunOnce: return new RunOnceTrigger(iTaskTrigger); case TriggerType.RunDaily: return new DailyTrigger(iTaskTrigger); case TriggerType.RunWeekly: return new WeeklyTrigger(iTaskTrigger); case TriggerType.RunMonthlyDOW: return new MonthlyDowTrigger(iTaskTrigger); case TriggerType.RunMonthly: return new MonthlyTrigger(iTaskTrigger); case TriggerType.OnIdle: return new OnIdleTrigger(iTaskTrigger); case TriggerType.OnSystemStart: return new OnSystemStartTrigger(iTaskTrigger); case TriggerType.OnLogon: return new OnLogonTrigger(iTaskTrigger); default: throw new ArgumentException("Unable to recognize type of trigger referenced in iTaskTrigger", "iTaskTrigger"); } }
internal Trigger(ITaskTrigger trigger, V1Interop.TaskTriggerType type) : this(trigger, trigger.GetTrigger()) { }
/// <summary> /// Break the connection between this Trigger and the system Task Scheduler. This /// releases COM resources used in bound Triggers. /// </summary> internal void Unbind() { if (iTaskTrigger != null) { Marshal.ReleaseComObject(iTaskTrigger); iTaskTrigger = null; } }
internal WeeklyTrigger(ITaskTrigger iTrigger) : base(iTrigger, V1Interop.TaskTriggerType.RunWeekly) { }
/// <summary> /// Internal constructor to create from existing ITaskTrigger interface. /// </summary> /// <param name="iTrigger">Current base Trigger.</param> internal OnIdleTrigger(ITaskTrigger iTrigger) : base(iTrigger) { }
public SchedulerTask(ITaskTrigger taskTrigger, Func<bool> command) { _taskTrigger = taskTrigger; _command = command; }
internal MonthlyTrigger(ITaskTrigger iTrigger) : base(iTrigger, TaskTriggerType.RunMonthly) { }
/// <summary> /// Internal constructor to create from existing ITaskTrigger interface. /// </summary> /// <param name="iTrigger">ITaskTrigger from system Task Scheduler.</param> internal OnLogonTrigger(ITaskTrigger iTrigger) : base(iTrigger) { }