|
1 | 1 | using System.Linq; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using FlagsmithEngine.Exceptions; |
4 | | -using System; |
5 | 4 | using FlagsmithEngine.Interfaces; |
6 | 5 | using FlagsmithEngine.Segment; |
7 | 6 | using FlagsmithEngine.Environment.Models; |
8 | 7 | using FlagsmithEngine.Feature.Models; |
9 | 8 | using FlagsmithEngine.Identity.Models; |
10 | 9 | using FlagsmithEngine.Trait.Models; |
| 10 | +using System.Collections; |
| 11 | +using System.Data; |
11 | 12 |
|
12 | 13 | namespace FlagsmithEngine |
13 | 14 | { |
14 | 15 | public class Engine : IEngine |
15 | 16 | { |
| 17 | + /// <summary> |
| 18 | + /// Get the evaluation result for a given context |
| 19 | + /// </summary> |
| 20 | + /// <typeparam name="SegmentMetadataT">Segment metadata type</typeparam> |
| 21 | + /// <typeparam name="FeatureMetadataT">Feature metadata type</typeparam> |
| 22 | + /// <param name="context"></param> |
| 23 | + /// <returns></returns> |
| 24 | + public EvaluationResult<SegmentMetadataT, FeatureMetadataT> GetEvaluationResult<SegmentMetadataT, FeatureMetadataT>(EvaluationContext<SegmentMetadataT, FeatureMetadataT> context) |
| 25 | + { |
| 26 | + context = GetEnrichedEvaluationContext(context); |
| 27 | + var result = new EvaluationResult<SegmentMetadataT, FeatureMetadataT>(); |
| 28 | + var segmentEvaluationResult = ContextEvaluator.EvaluateSegments(context); |
| 29 | + result.Flags = ContextEvaluator.EvaluateFlags(context, segmentEvaluationResult.SegmentOverrides); |
| 30 | + result.Segments = segmentEvaluationResult.Segments; |
| 31 | + return result; |
| 32 | + } |
| 33 | + |
| 34 | + private EvaluationContext<SegmentMetadataT, FeatureMetadataT> GetEnrichedEvaluationContext<SegmentMetadataT, FeatureMetadataT>(EvaluationContext<SegmentMetadataT, FeatureMetadataT> context) |
| 35 | + { |
| 36 | + if (context.Identity != null) |
| 37 | + { |
| 38 | + if (string.IsNullOrEmpty(context.Identity.Key)) |
| 39 | + { |
| 40 | + context = context.Clone(); |
| 41 | + context.Identity.Key = context.Environment.Key + "_" + context.Identity.Identifier; |
| 42 | + } |
| 43 | + } |
| 44 | + return context; |
| 45 | + } |
| 46 | + |
16 | 47 | /// <summary> |
17 | 48 | /// Get a list of feature states for a given environment |
18 | 49 | /// </summary> |
|
0 commit comments