-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathEngine.cs
More file actions
47 lines (45 loc) · 1.93 KB
/
Engine.cs
File metadata and controls
47 lines (45 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.Linq;
using System.Collections.Generic;
using FlagsmithEngine.Exceptions;
using FlagsmithEngine.Interfaces;
using FlagsmithEngine.Segment;
using FlagsmithEngine.Environment.Models;
using FlagsmithEngine.Feature.Models;
using FlagsmithEngine.Identity.Models;
using FlagsmithEngine.Trait.Models;
using System.Collections;
using System.Data;
namespace FlagsmithEngine
{
public class Engine : IEngine
{
/// <summary>
/// Get the evaluation result for a given context
/// </summary>
/// <typeparam name="SegmentMetadataT">Segment metadata type</typeparam>
/// <typeparam name="FeatureMetadataT">Feature metadata type</typeparam>
/// <param name="context"></param>
/// <returns></returns>
public EvaluationResult<SegmentMetadataT, FeatureMetadataT> GetEvaluationResult<SegmentMetadataT, FeatureMetadataT>(EvaluationContext<SegmentMetadataT, FeatureMetadataT> context)
{
context = GetEnrichedEvaluationContext(context);
var result = new EvaluationResult<SegmentMetadataT, FeatureMetadataT>();
var segmentEvaluationResult = ContextEvaluator.EvaluateSegments(context);
result.Flags = ContextEvaluator.EvaluateFlags(context, segmentEvaluationResult.SegmentOverrides);
result.Segments = segmentEvaluationResult.Segments;
return result;
}
private EvaluationContext<SegmentMetadataT, FeatureMetadataT> GetEnrichedEvaluationContext<SegmentMetadataT, FeatureMetadataT>(EvaluationContext<SegmentMetadataT, FeatureMetadataT> context)
{
if (context.Identity != null)
{
if (string.IsNullOrEmpty(context.Identity.Key))
{
context = context.Clone();
context.Identity.Key = context.Environment.Key + "_" + context.Identity.Identifier;
}
}
return context;
}
}
}