private bool RunEvent(AnimalEvent e, AnimalBoxEventContext context) { IAnimalEventHandler handler = InstantiateEventHandler(e); if (!handler.Validate(e, context)) { return(false); } handler.Apply(e, context); return(true); }
public async Task <bool> RunEventsAsync(IEnumerable <AnimalEvent> events) { AnimalBoxEventContext eventContext = InstantiateBoxContext(); foreach (AnimalEvent e in events.OrderBy(e => e.Time)) { AdvanceTime(e.Time); if (!RunEvent(e, eventContext)) { // Rollback(); return(false); } } return(true); }