Skip to content

Commit 71124a5

Browse files
committed
Introduce & Implement BotController
1 parent aaefa2b commit 71124a5

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

RealTimeWeatherMonitoringApp/Domain/Common/BotEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ namespace RealTimeWeatherMonitoringApp.Domain.Common;
22

33
public class BotEventArgs : EventArgs
44
{
5-
public string Message { get; set; }
5+
public string Message { get; }
66
public BotEventArgs(string message) => Message = message;
77
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}

0 commit comments

Comments
 (0)