public ITask ScheduleNextAsyncFrame(ILifecycleObject @object, Action action, string taskName) { SimpleTask task = new SimpleTask(this, @object, action, ExecutionTargetContext.NextAsyncFrame); TriggerEvent(task); return(task); }
public ITask ScheduleEveryPhysicUpdate(ILifecycleObject @object, Action action, string taskName) { SimpleTask task = new SimpleTask(this, @object, action, ExecutionTargetContext.EveryPhysicsUpdate); TriggerEvent(task); return(task); }
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); }
public EventAction(ILifecycleObject owner, EventCallback action, EventHandler handler, Type eventType) { Owner = owner; Action = action; Handler = handler; TargetEventNames = EventManager.GetEventNames(eventType); TargetEventType = eventType; }
public EventAction(ILifecycleObject owner, EventCallback action, EventHandler handler, Type eventType) { Owner = new Util.WeakReference <ILifecycleObject>(owner); Action = action; Handler = handler; TargetEventNames = EventBus.GetEventNames(eventType); TargetEventType = eventType; }
public void Unsubscribe <TEvent>(ILifecycleObject @object) where TEvent : IEvent { if ([email protected]) { return; } eventListeners.RemoveAll(c => c.Owner == @object); }
public void Unsubscribe(ILifecycleObject @object) { if ([email protected]) { return; } eventListeners.RemoveAll(c => !c.Owner.IsAlive || c.Owner.Target == @object); }
public void Unsubscribe(ILifecycleObject @object, Type eventType) { if ([email protected]) { return; } eventListeners.RemoveAll(c => c.Owner == @object && CheckEvent(c, GetEventNames(eventType))); }
/// <inheritdoc /> public ThreadSafeTask(int taskId, string name, ITaskScheduler scheduler, ILifecycleObject owner, Action action, ExecutionTargetContext executionTargetContext) { TaskId = taskId; Name = name; Scheduler = scheduler; Owner = owner; Action = action; ExecutionTarget = executionTargetContext; }
internal SimpleTask(int taskId, string taskName, ITaskScheduler scheduler, ILifecycleObject owner, Action action, ExecutionTargetContext executionTarget) { Name = taskName; ownerRef = new Core.Util.WeakReference <ILifecycleObject>(owner); Action = action; ExecutionTarget = executionTarget; Scheduler = scheduler; TaskId = taskId; }
internal SimpleTask(ITaskScheduler scheduler, ILifecycleObject owner, Action action, ExecutionTargetContext executionTarget) { Owner = owner; Action = action; ExecutionTarget = executionTarget; Scheduler = scheduler; TaskId = ++taskIds; }
internal SimpleTask(int taskId, string taskName, ITaskScheduler scheduler, ILifecycleObject owner, Action action, ExecutionTargetContext executionTarget) { Name = taskName; Owner = owner; Action = action; ExecutionTarget = executionTarget; Scheduler = scheduler; TaskId = taskId; }
public static ITask RunOnMainThread(this ITaskScheduler taskScheduler, ILifecycleObject owner, Action action, string taskName) { if (Thread.CurrentThread == taskScheduler.MainThread) { action(); return(null); } return(taskScheduler.ScheduleUpdate(owner, action, taskName, ExecutionTargetContext.NextFrame)); }
public EventAction( ILifecycleObject owner, EventCallback action, EventHandler handler, List <string> eventNames) { Owner = new Util.WeakReference <ILifecycleObject>(owner); Action = action; Handler = handler; TargetEventNames = eventNames; }
public void Unsubscribe(ILifecycleObject @object, string eventName) { if ([email protected]) { return; } eventListeners.RemoveAll(c => c.Owner == @object && CheckEvent(c, new List <string> { eventName })); }
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 void Unsubscribe(ILifecycleObject @object, Type eventType, Type eventEmitterType) { if ([email protected]) { return; } eventListeners.RemoveAll(c => !c.Owner.IsAlive || c.Owner.Target == @object && CheckEvent(c, GetEventNames(eventType)) && CheckEmitter(c, GetEmitterName(eventEmitterType), false)); }
public EventAction( ILifecycleObject owner, EventCallback action, EventHandler handler, List <string> eventNames) { Owner = owner; Action = action; Handler = handler; TargetEventNames = eventNames; }
public void Subscribe(ILifecycleObject @object, EventCallback callback, Type eventType, Type eventEmitterType) { if ([email protected]) { return; } EventHandler handler = GetEventHandler(callback.Method, GetEmitterName(eventEmitterType)); eventListeners.Add(new EventAction(@object, callback.Invoke, handler, eventType)); }
public void Unsubscribe <TEvent, TEmitter>(ILifecycleObject @object) where TEvent : IEvent where TEmitter : IEventEmitter { if ([email protected]) { return; } eventListeners.RemoveAll(c => c.Owner == @object && CheckEvent(c, GetEventNames(typeof(TEvent))) && CheckEmitter(c, GetEmitterName(typeof(TEmitter)), false)); }
public EventAction(ILifecycleObject owner, IEventListener listener, MethodInfo method, EventHandler handler, Type type) { Owner = owner; Listener = listener; Action = (sender, @event) => method.Invoke(listener, new object[] { sender, @event }); Handler = handler; TargetEventNames = EventManager.GetEventNames(type); TargetEventType = type; }
public EventAction(ILifecycleObject owner, IEventListener listener, MethodInfo method, EventHandler handler, Type type) { Owner = new Util.WeakReference <ILifecycleObject>(owner); Listener = listener; Action = (sender, @event) => method.InvokeWithTaskSupport(listener, new object[] { sender, @event }); Handler = handler; TargetEventNames = EventBus.GetEventNames(type); TargetEventType = type; }
public void Subscribe <TEvent, TEmitter>(ILifecycleObject @object, EventCallback <TEvent> callback) where TEvent : IEvent where TEmitter : IEventEmitter { if ([email protected]) { return; } EventHandler handler = GetEventHandler(callback.Method, GetEmitterName(typeof(TEmitter))); eventListeners.Add(new EventAction(@object, (sender, @event) => callback.Invoke(sender, (TEvent)@event), handler, typeof(TEvent))); }
public void Subscribe(ILifecycleObject @object, string emitterName, string eventName, EventCallback callback) { if ([email protected]) { return; } EventHandler handler = GetEventHandler(callback.Method, emitterName); eventListeners.Add(new EventAction(@object, callback, handler, new List <string> { eventName })); }
public static IEnumerable <Type> FindTypes <T>(this ILifecycleObject @object, bool includeAbstractAndInterfaces = true, Func <Type, bool> predicate = null) { IEnumerable <Type> filter = @object.FindAllTypes(includeAbstractAndInterfaces) .Where(t => typeof(T).IsAssignableFrom(t)); if (predicate != null) { filter = filter.Where(predicate); } return(filter); }
public void Unsubscribe(ILifecycleObject @object, string emitterName, string eventName) { if ([email protected]) { return; } eventListeners.RemoveAll(c => c.Owner == @object && c.Handler.EmitterName.Equals(emitterName, StringComparison.OrdinalIgnoreCase) && CheckEvent(c, new List <string> { eventName })); }
/// <inheritdoc /> public ITask ScheduleUpdate(ILifecycleObject @object, Action action, string taskName, ExecutionTargetContext target) { ThreadSafeTask task; lock (taskIdLock) { task = new ThreadSafeTask(taskId++, taskName, this, @object, action, target); } lock (lockObj) { tasks.Add(task); } return(task); }
/// <inheritdoc /> public ITask ScheduleAt(ILifecycleObject @object, Action action, string taskName, DateTime date, bool runAsync = false) { ThreadSafeTask task; ExecutionTargetContext context = runAsync ? ExecutionTargetContext.Async : ExecutionTargetContext.NextFrame; lock (taskIdLock) { task = new ThreadSafeTask(taskId++, taskName, this, @object, action, context, TimeSpan.Zero, date, null); } lock (lockObj) { tasks.Add(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); }
public void AddEventListener(ILifecycleObject @object, IEventListener eventListener) { if ([email protected]) { return; } // ReSharper disable once UseIsOperator.2 if (!typeof(IEventListener).IsInstanceOfType(eventListener)) { throw new ArgumentException( "The eventListener to register has to implement IEventListener!", nameof(eventListener)); } if (eventListeners.Any(c => c.Listener?.GetType() == eventListener.GetType())) { return; } Type type = eventListener.GetType(); foreach (Type @interface in type.GetInterfaces() .Where(c => typeof(IEventListener).IsAssignableFrom(c) && c.GetGenericArguments().Length > 0)) { foreach (MethodInfo method in @interface.GetMethods()) { EventHandler handler = (EventHandler)method.GetCustomAttributes(typeof(EventHandler), false) .FirstOrDefault() ?? new EventHandler { Priority = ServicePriority.Normal }; Type eventType = @interface.GetGenericArguments()[0]; eventListeners.Add(new EventAction(@object, eventListener, method, handler, eventType)); } } }