/// <summary> /// Returns the priority of the event /// The priority is determine by a default value but can be overwritten by the remote configuration /// </summary> /// <typeparam name="TEvent">The name of the event</typeparam> /// <returns>EventPriority</returns> /// <exception cref="ArgumentOutOfRangeException">In case the event name is not defined in EventPrioritiesConfiguration</exception> /// <exception cref="InvalidOperationException">In case the method was called before Init() was called - should not happen in a normal flow of the agent</exception> public static EventPriority GetEventPriority <TEvent>() where TEvent : IEvent { EnsureInitialized(); //Get the event property var eventType = _remoteConfiguration.GetType().GetProperty(typeof(TEvent).Name); if (eventType == null) { throw new ArgumentOutOfRangeException(paramName: $"{nameof(EventPriority)}", message: $"TwinConfiguration error: Couldn't find priority configuration for: {typeof(TEvent).Name}"); } EventPriority eventPriority = (EventPriority)eventType.GetValue(_remoteConfiguration); SimpleLogger.Debug($"Event {eventType} has event priority {eventPriority}"); return(eventPriority); }
/// <summary> /// Returns the priority of the event /// The priority is determine by a default value but can be overwritten by the remote configuration /// </summary> /// <typeparam name="TEvent">The name of the event</typeparam> /// <returns>EventPriority</returns> /// <exception cref="MisconfigurationException">In case the event name is not defined in EventPrioritiesConfiguration</exception> /// <exception cref="InvalidOperationException">In case the method was called before Init() was called - should not happen in a normal flow of the agent</exception> public static EventPriority GetEventPriority <TEvent>() where TEvent : IEvent { //If init() was not called - throw exception if (!_isInitialized) { throw new InvalidOperationException("GetEventPriority was called before AgentConfiguration initialization"); } //Get the event property var eventType = _remoteConfiguration.GetType().GetProperty(typeof(TEvent).Name); if (eventType == null) { throw new MisconfigurationException($"TwinConfiguration error: Couldn't find priority configuration for: {typeof(TEvent).Name}"); } EventPriority eventPriority = (EventPriority)eventType.GetValue(_remoteConfiguration); SimpleLogger.Debug($"Event {eventType} has event priority {eventPriority}"); return(eventPriority); }