/// <inheritdoc /> public override bool Evaluate() { if (_disposed) { throw new ObjectDisposedException("DataModelConditionEvent"); } if (EventPath?.GetValue() is not IDataModelEvent dataModelEvent) { return(false); } // Only evaluate to true once every time the event has been triggered since the last evaluation if (dataModelEvent.LastTrigger <= LastTrigger) { return(false); } LastTrigger = DateTime.Now; // If there is a child (root group), it must evaluate to true whenever the event triggered if (Children.Any()) { return(Children[0].EvaluateObject(dataModelEvent.LastEventArgumentsUntyped)); } // If there are no children, we always evaluate to true whenever the event triggered return(true); }
/// <summary> /// Returns the <see cref="IDataModelEvent" /> this <see cref="DataModelConditionEvent" /> is triggered by /// </summary> /// <returns>The <see cref="IDataModelEvent" /> this <see cref="DataModelConditionEvent" /> is triggered by</returns> public IDataModelEvent?GetDataModelEvent() { if (_valueChangedEvent != null) { return(_valueChangedEvent); } return(EventPath?.GetValue() as IDataModelEvent); }
internal void Initialize() { ClearChildren(); if (Entity.EventPath == null) { return; } // Ensure the list path is valid and points to a list DataModelPath eventPath = new(null, Entity.EventPath); // Can't check this on an invalid list, if it becomes valid later lets hope for the best if (eventPath.IsValid && !PointsToEvent(eventPath)) { return; } EventPath = eventPath; SubscribeToEventPath(); EventArgumentType = GetEventArgumentType(); // There should only be one child and it should be a group if (Entity.Children.FirstOrDefault() is DataModelConditionGroupEntity rootGroup) { AddChild(new DataModelConditionGroup(this, rootGroup)); } else { Entity.Children.Clear(); AddChild(new DataModelConditionGroup(this)); } if (EventPath?.GetValue() is IDataModelEvent dataModelEvent) { LastTrigger = dataModelEvent.LastTrigger; } }