protected virtual void TriggerEvent(SimpleTask task, EventCallback cb = null) { TaskScheduleEvent e = new TaskScheduleEvent(task); if (!(task.Owner is IEventEmitter owner)) { return; } IEventBus eventBus = Container.Resolve <IEventBus>(); if (eventBus == null) { InternalTasks.Add(task); cb?.Invoke(owner, null); return; } eventBus.Emit(owner, e, @event => { task.IsCancelled = e.IsCancelled; if (!e.IsCancelled) { InternalTasks.Add(task); } cb?.Invoke(owner, @event); }); }
public ITask ScheduleUpdate(ILifecycleObject @object, Action action, string taskName, ExecutionTargetContext target) { if ([email protected]) { return(null); } SimpleTask task = new SimpleTask(++taskIds, taskName, this, @object, action, target); TriggerEvent(task, (sender, @event) => { if (target != ExecutionTargetContext.Sync && @object.IsAlive) { return; } if (@event != null && ((ICancellableEvent)@event).IsCancelled) { return; } action(); InternalTasks.Remove(task); }); return(task); }
public ITask ScheduleAt(ILifecycleObject @object, Action action, string taskName, DateTime date, bool runAsync = false) { SimpleTask task = new SimpleTask(++taskIds, taskName, this, @object, action, runAsync ? ExecutionTargetContext.Async : ExecutionTargetContext.Sync) { StartTime = date }; TriggerEvent(task); return(task); }
public ITask SchedulePeriodically(ILifecycleObject @object, Action action, string taskName, TimeSpan period, TimeSpan?delay = null, bool runAsync = false) { SimpleTask task = new SimpleTask(++taskIds, taskName, this, @object, action, runAsync ? ExecutionTargetContext.Async : ExecutionTargetContext.Sync) { Period = period }; if (delay != null) { task.StartTime = DateTime.Now + delay; } TriggerEvent(task); return(task); }