File tree Expand file tree Collapse file tree 4 files changed +41
-1
lines changed
RealTimeWeatherMonitoringApp/Domain Expand file tree Collapse file tree 4 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,6 @@ namespace RealTimeWeatherMonitoringApp.Domain.Common;
22
33public class BotEventArgs : EventArgs
44{
5- public string Message { get ; set ; }
5+ public string Message { get ; }
66 public BotEventArgs ( string message ) => Message = message ;
77}
Original file line number Diff line number Diff line change 1+ namespace RealTimeWeatherMonitoringApp . Domain . Common ;
2+
3+ public class DataChangeEventArgs < TObserved > : EventArgs
4+ {
5+ public TObserved ? NewData { get ; }
6+ public DataChangeEventArgs ( TObserved newData ) => NewData = newData ;
7+ }
Original file line number Diff line number Diff line change 1+ using RealTimeWeatherMonitoringApp . Domain . Common ;
2+
3+ namespace RealTimeWeatherMonitoringApp . Domain . Interfaces ;
4+
5+ /// <summary>
6+ /// Controls the behaviour of a Bot model
7+ /// </summary>
8+ /// <typeparam name="TEvaluated">Evaluated data type of the bot</typeparam>
9+ public interface IBotController < TEvaluated >
10+ {
11+ /// <summary>
12+ /// Reacts to the incoming <see cref="DataChangeEventArgs{TEvaluated}"/>
13+ /// and potentially returns an event args if the data triggers a response.
14+ /// </summary>
15+ /// <param name="args">The event args containing the data to be evaluated by the bot controller.</param>
16+ /// <returns>A <see cref="BotEventArgs"/> if the data triggers the bot, otherwise null.</returns>
17+ BotEventArgs ? React ( DataChangeEventArgs < TEvaluated > args ) ;
18+ }
Original file line number Diff line number Diff line change 1+ using RealTimeWeatherMonitoringApp . Domain . Common ;
2+ using RealTimeWeatherMonitoringApp . Domain . Interfaces ;
3+
4+ namespace RealTimeWeatherMonitoringApp . Domain . Models . Controller ;
5+
6+ public class BotController < TEvaluated > : IBotController < TEvaluated >
7+ {
8+ private readonly Bot < TEvaluated > _bot ;
9+ public BotController ( Bot < TEvaluated > bot ) => _bot = bot ;
10+
11+ public BotEventArgs ? React ( DataChangeEventArgs < TEvaluated > args ) =>
12+ args . NewData != null && IsTriggeredBy ( args . NewData ) ? new BotEventArgs ( _bot . Message ) : null ;
13+
14+ private bool IsTriggeredBy ( TEvaluated data ) => _bot . Enabled && _bot . Evaluator . Evaluate ( data ) ;
15+ }
You can’t perform that action at this time.
0 commit comments