1
1
/*
2
- * Copyright 2019-2021, Optimizely
2
+ * Copyright 2019-2021, 2023, Optimizely
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
6
6
* You may obtain a copy of the License at
7
7
*
8
- * http ://www.apache.org/licenses/LICENSE-2.0
8
+ * https ://www.apache.org/licenses/LICENSE-2.0
9
9
*
10
10
* Unless required by applicable law or agreed to in writing, software
11
11
* distributed under the License is distributed on an "AS IS" BASIS,
15
15
*/
16
16
17
17
using System ;
18
- using System . Collections ;
19
18
using System . Collections . Generic ;
20
19
using System . Linq ;
21
20
using System . Text ;
22
21
using Newtonsoft . Json ;
23
22
using Newtonsoft . Json . Linq ;
24
23
using OptimizelySDK . Entity ;
24
+ using OptimizelySDK . Logger ;
25
25
26
26
namespace OptimizelySDK . OptlyConfig
27
27
{
28
28
public class OptimizelyConfigService
29
29
{
30
- private OptimizelyConfig OptimizelyConfig ;
30
+ private OptimizelyConfig _optimizelyConfig ;
31
31
32
- private IDictionary < string , List < FeatureVariable > > featureIdVariablesMap ;
32
+ private IDictionary < string , List < FeatureVariable > > _featureIdVariablesMap ;
33
33
34
- public OptimizelyConfigService ( ProjectConfig projectConfig )
34
+ private readonly ILogger _logger ;
35
+
36
+ public OptimizelyConfigService ( ProjectConfig projectConfig , ILogger logger = null )
35
37
{
36
38
if ( projectConfig == null )
37
39
{
38
40
return ;
39
41
}
40
42
41
- featureIdVariablesMap = GetFeatureVariablesByIdMap ( projectConfig ) ;
43
+ _logger = logger ?? new DefaultLogger ( ) ;
44
+
45
+ _featureIdVariablesMap = GetFeatureVariablesByIdMap ( projectConfig ) ;
42
46
var attributes = GetAttributes ( projectConfig ) ;
43
47
var audiences = GetAudiences ( projectConfig ) ;
44
48
var experimentsMapById = GetExperimentsMapById ( projectConfig ) ;
@@ -47,7 +51,7 @@ public OptimizelyConfigService(ProjectConfig projectConfig)
47
51
var featureMap = GetFeaturesMap ( projectConfig , experimentsMapById ) ;
48
52
var events = GetEvents ( projectConfig ) ;
49
53
50
- OptimizelyConfig = new OptimizelyConfig ( projectConfig . Revision ,
54
+ _optimizelyConfig = new OptimizelyConfig ( projectConfig . Revision ,
51
55
projectConfig . SDKKey ,
52
56
projectConfig . EnvironmentKey ,
53
57
attributes ,
@@ -118,6 +122,12 @@ IDictionary<string, OptimizelyExperiment> experimentsMapById
118
122
119
123
foreach ( var experiment in experimentsMapById . Values )
120
124
{
125
+ if ( experimentKeyMaps . ContainsKey ( experiment . Key ) )
126
+ {
127
+ _logger . Log ( LogLevel . WARN ,
128
+ $ "Duplicate experiment keys found in datafile: { experiment . Key } ") ;
129
+ }
130
+
121
131
experimentKeyMaps [ experiment . Key ] = experiment ;
122
132
}
123
133
@@ -210,7 +220,7 @@ bool isFeatureEnabled
210
220
211
221
if ( ! string . IsNullOrEmpty ( featureId ) )
212
222
{
213
- variablesMap = featureIdVariablesMap [ featureId ] ? .
223
+ variablesMap = _featureIdVariablesMap [ featureId ] ? .
214
224
Select ( f => new OptimizelyVariable ( f . Id ,
215
225
f . Key ,
216
226
f . Type . ToString ( ) . ToLower ( ) ,
@@ -451,7 +461,7 @@ private IDictionary<string, FeatureVariable> GetVariableIdMap(ProjectConfig proj
451
461
452
462
public OptimizelyConfig GetOptimizelyConfig ( )
453
463
{
454
- return OptimizelyConfig ;
464
+ return _optimizelyConfig ;
455
465
}
456
466
}
457
467
}
0 commit comments