Ejemplo n.º 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);
            });
        }
Ejemplo n.º 2
0
        public IScheduledTask ScheduleUpdate(ILifecycleObject @object, Action action, string taskName, ExecutionTargetContext target)
        {
            if ([email protected])
            {
                return(null);
            }

            ScheduledTask task = new ScheduledTask(++taskIds, taskName, this, @object, action, target);

            TriggerEvent(task, async(sender, @event) =>
            {
                if (target != ExecutionTargetContext.Sync && @object.IsAlive)
                {
                    return;
                }

                if (@event != null && ((ICancellableEvent)@event).IsCancelled)
                {
                    return;
                }

                action();
                InternalTasks.Remove(task);
            });

            return(task);
        }
Ejemplo n.º 3
0
        protected internal virtual void RunTask(IScheduledTask t)
        {
            var task = (ScheduledTask)t;

            if (!task.IsReferenceAlive)
            {
                InternalTasks.Remove(task);
                return;
            }

            if (!t.Owner.IsAlive)
            {
                return;
            }

            if (task.StartTime != null && task.StartTime > DateTime.UtcNow)
            {
                return;
            }

            if (task.EndTime != null && task.EndTime < DateTime.UtcNow)
            {
                task.EndTime = DateTime.UtcNow;
                RemoveTask(task);
                {
                    return;
                }
            }

            if (task.Period != null &&
                task.LastRunTime != null &&
                DateTime.UtcNow - task.LastRunTime < task.Period)
            {
                return;
            }

            try
            {
            }
            catch (Exception ex)
            {
                Container.Resolve <ILogger>().LogError("An exception occured in task: " + task.Name, ex);
                task.EndTime = DateTime.UtcNow;
                RemoveTask(task);
                return;
            }

            if (task.ExecutionTarget == ExecutionTargetContext.NextFrame ||
                task.ExecutionTarget == ExecutionTargetContext.NextPhysicsUpdate ||
                task.ExecutionTarget == ExecutionTargetContext.Async ||
                task.ExecutionTarget == ExecutionTargetContext.NextAsyncFrame ||
                task.ExecutionTarget == ExecutionTargetContext.Sync)
            {
                task.EndTime = DateTime.UtcNow;
                RemoveTask(task);
            }
        }
Ejemplo n.º 4
0
        protected virtual void TriggerEvent(ScheduledTask task, EventCallback cb = null)
        {
            if (task.ExecutionTarget == ExecutionTargetContext.Async ||
                task.ExecutionTarget == ExecutionTargetContext.NextAsyncFrame ||
                task.ExecutionTarget == ExecutionTargetContext.EveryAsyncFrame)
            {
                asyncTaskRunner.NotifyTaskScheduled();
            }

            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, async @event =>
            {
                task.IsCancelled = e.IsCancelled;

                if (!e.IsCancelled)
                {
                    InternalTasks.Add(task);
                }

                cb?.Invoke(owner, @event);
            });
        }
Ejemplo n.º 5
0
 protected virtual void RemoveTask(ITask task)
 {
     InternalTasks.Remove(task);
 }
Ejemplo n.º 6
0
 protected virtual void RemoveTask(IScheduledTask task)
 {
     InternalTasks.Remove((ScheduledTask)task);
 }