Exemple #1
0
        /// <summary>
        ///     Updates the event the condition is triggered by
        /// </summary>
        public void UpdateEvent(DataModelPath?path)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("DataModelConditionEvent");
            }

            if (path != null && !path.IsValid)
            {
                throw new ArtemisCoreException("Cannot update event to an invalid path");
            }

            EventPath?.Dispose();
            EventPath = path != null ? new DataModelPath(path) : null;
            SubscribeToEventPath();
            CreateValueChangedEventIfNeeded();

            // Remove the old root group that was tied to the old data model
            ClearChildren();

            if (EventPath != null)
            {
                EventArgumentType = GetEventArgumentType();
                // Create a new root group
                AddChild(new DataModelConditionGroup(this));
            }
            else
            {
                EventArgumentType = null;
            }

            LastTrigger = GetDataModelEvent()?.LastTrigger ?? DateTime.Now;
        }
        /// <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);
        }
Exemple #3
0
 /// <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);
 }
Exemple #4
0
        private void EventPathOnPathInvalidated(object?sender, EventArgs e)
        {
            if (_reinitializing)
            {
                return;
            }

            _reinitializing = true;
            EventPath?.Dispose();
            Initialize();
            _reinitializing = false;
        }
        private Type?GetEventArgumentType()
        {
            if (EventPath == null || !EventPath.IsValid)
            {
                return(null);
            }

            // Cannot rely on EventPath.GetValue() because part of the path might be null
            Type eventType = EventPath.GetPropertyType() !;

            return(eventType.IsGenericType ? eventType.GetGenericArguments()[0] : typeof(DataModelEventArgs));
        }
Exemple #6
0
        /// <inheritdoc />
        protected override void Dispose(bool disposing)
        {
            _disposed = true;

            EventPath?.Dispose();

            foreach (DataModelConditionPart child in Children)
            {
                child.Dispose();
            }

            base.Dispose(disposing);
        }
Exemple #7
0
        private void CreateValueChangedEventIfNeeded()
        {
            Type?propertyType = EventPath?.GetPropertyType();

            if (propertyType == null)
            {
                return;
            }

            if (!typeof(IDataModelEvent).IsAssignableFrom(propertyType))
            {
                IDataModelEvent?instance = (IDataModelEvent?)Activator.CreateInstance(typeof(DataModelValueChangedEvent <>).MakeGenericType(propertyType), EventPath);
                _valueChangedEvent = instance ?? throw new ArtemisCoreException("Failed to create a DataModelValueChangedEvent for a property changed data model event");
            }
            else
            {
                _valueChangedEvent = null;
            }
        }
Exemple #8
0
 public EventList(ServerDataConfig c, EventPath p)
 {
     log         = new Logging("Event Data Collector", c.debug_level);
     debug_level = c.debug_level;
     if (p == EventPath.System)
     {
         path        = "System";
         hours       = c.sys_hours;
         event_level = c.sys_level;
         sample_rate = c.sys_sample_rate;
     }
     else if (p == EventPath.Application)
     {
         hours       = c.app_hours;
         path        = "Application";
         event_level = c.app_level;
         sample_rate = c.app_sample_rate;
     }
     log.debug(1, "Created eventlist " + path, 1);
 }
Exemple #9
0
        internal override void Save()
        {
            // Don't save an invalid state
            if (EventPath != null && !EventPath.IsValid)
            {
                return;
            }

            // Target list
            EventPath?.Save();
            Entity.EventPath = EventPath?.Entity;

            // Children
            Entity.Children.Clear();
            Entity.Children.AddRange(Children.Select(c => c.GetEntity()));
            foreach (DataModelConditionPart child in Children)
            {
                child.Save();
            }
        }
        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;
            }
        }
 public override void SetParent(EventContext parent, EventPath path)
 {
     base.SetParent(parent, path);
 }