File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
RealTimeWeatherMonitoringApp/Infrastructure Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ using RealTimeWeatherMonitoringApp . Domain . Interfaces ;
2+ using RealTimeWeatherMonitoringApp . Domain . Models ;
3+ using RealTimeWeatherMonitoringApp . Infrastructure . Configuration ;
4+ using RealTimeWeatherMonitoringApp . Infrastructure . Evaluators ;
5+ using RealTimeWeatherMonitoringApp . Infrastructure . Interfaces . Factory ;
6+
7+ namespace RealTimeWeatherMonitoringApp . Infrastructure . Factory ;
8+
9+ public class WeatherEvaluatorFactory : IEvaluatorFactory < WeatherData >
10+ {
11+ public IEvaluator < WeatherData > CreateEvaluator ( ConditionConfiguration config )
12+ {
13+ var value = config . Value ;
14+ var comparison = GetComparisonOperator ( config . Operator ) ;
15+ return config . Type . ToLower ( ) switch
16+ {
17+ "temperature" => new WeatherTemperatureEvaluator ( value , comparison ) ,
18+ "humidity" => new WeatherHumidityEvaluator ( value , comparison ) ,
19+ _ => throw new ArgumentException ( $ "Unsupported condition type: { config . Type } ")
20+ } ;
21+ }
22+
23+ private Func < double , double , bool > GetComparisonOperator ( string @operator )
24+ {
25+ return @operator switch
26+ {
27+ "greaterThan" => ( x , y ) => x > y ,
28+ "lessThan" => ( x , y ) => x < y ,
29+ _ => throw new ArgumentException ( $ "Unsupported operator: { @operator } ")
30+ } ;
31+ }
32+ }
Original file line number Diff line number Diff line change 1+ using RealTimeWeatherMonitoringApp . Domain . Interfaces ;
2+ using RealTimeWeatherMonitoringApp . Infrastructure . Configuration ;
3+
4+ namespace RealTimeWeatherMonitoringApp . Infrastructure . Interfaces . Factory ;
5+
6+ public interface IEvaluatorFactory < in TEvaluated >
7+ {
8+ /// <exception cref="ArgumentException">When the configuration is invalid for the output data type</exception>
9+ IEvaluator < TEvaluated > CreateEvaluator ( ConditionConfiguration configuration ) ;
10+ }
You can’t perform that action at this time.
0 commit comments