Beispiel #1
0
        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);
            });
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }