Skip to content

Commit d2393e2

Browse files
authored
Merge pull request #1 from optimizely/master
Pull changes from source repository
2 parents db932a5 + 34a74cb commit d2393e2

File tree

5 files changed

+24
-16
lines changed

5 files changed

+24
-16
lines changed

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
- stage: 'Unit Tests'
4949
language: csharp
5050
dist: xenial
51-
mono: 5.2.0
51+
mono: 6.12.0
5252
solution: "./OptimizelySDK.Travis.sln"
5353
install:
5454
- nuget restore ./OptimizelySDK.Travis.sln
@@ -67,9 +67,9 @@ jobs:
6767
- stage: 'NetStandard16'
6868
language: csharp
6969
# dotnet only works on trusty https://github.com/travis-ci/travis-ci/issues/5189
70-
dist: trusty
70+
dist: xenial
7171
mono: none
72-
dotnet: 2.1.502
72+
dotnet: 3.1
7373
install:
7474
- dotnet restore OptimizelySDK.NetStandard16/OptimizelySDK.NetStandard16.csproj
7575
script:
@@ -84,9 +84,9 @@ jobs:
8484
- stage: 'NetStandard20'
8585
language: csharp
8686
# dotnet only works on trusty https://github.com/travis-ci/travis-ci/issues/5189
87-
dist: trusty
87+
dist: xenial
8888
mono: none
89-
dotnet: 2.1.502
89+
dotnet: 3.1
9090
install:
9191
- dotnet restore OptimizelySDK.NetStandard20/OptimizelySDK.NetStandard20.csproj
9292
script:

OptimizelySDK.Tests/OptimizelyConfigTests/OptimizelyConfigTest.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -531,12 +531,6 @@ public void TestGetOptimizelyConfigService()
531531
audiences: new OptimizelyAudience[]
532532
{
533533
new OptimizelyAudience("0", "$$dummy", "{\"type\": \"custom_attribute\", \"name\": \"$opt_dummy_attribute\", \"value\": \"impossible_value\"}"),
534-
new OptimizelyAudience("3468206643", "$$dummyExactBoolean", "{\"type\": \"custom_attribute\", \"name\": \"$opt_dummy_attribute\", \"value\": \"impossible_value\"}"),
535-
new OptimizelyAudience("3468206646", "$$dummyExactNumber", "{\"type\": \"custom_attribute\", \"name\": \"$opt_dummy_attribute\", \"value\": \"impossible_value\"}"),
536-
new OptimizelyAudience("3988293899", "$$dummyExists", "{\"type\": \"custom_attribute\", \"name\": \"$opt_dummy_attribute\", \"value\": \"impossible_value\"}"),
537-
new OptimizelyAudience("3468206647", "$$dummyGtNumber", "{\"type\": \"custom_attribute\", \"name\": \"$opt_dummy_attribute\", \"value\": \"impossible_value\"}"),
538-
new OptimizelyAudience("3468206644", "$$dummyLtNumber", "{\"type\": \"custom_attribute\", \"name\": \"$opt_dummy_attribute\", \"value\": \"impossible_value\"}"),
539-
new OptimizelyAudience("3988293898", "$$dummySubstringString", "{\"type\": \"custom_attribute\", \"name\": \"$opt_dummy_attribute\", \"value\": \"impossible_value\"}"),
540534
new OptimizelyAudience("3468206643", "exactBoolean", "[\"and\",[\"or\",[\"or\",{\"name\":\"should_do_it\",\"type\":\"custom_attribute\",\"match\":\"exact\",\"value\":true}]]]"),
541535
new OptimizelyAudience("3468206646", "exactNumber", "[\"and\",[\"or\",[\"or\",{\"name\":\"lasers\",\"type\":\"custom_attribute\",\"match\":\"exact\",\"value\":45.5}]]]"),
542536
new OptimizelyAudience("3468206642", "exactString", "[\"and\", [\"or\", [\"or\", {\"name\": \"house\", \"type\": \"custom_attribute\", \"value\": \"Gryffindor\"}]]]"),

OptimizelySDK/OptlyConfig/OptimizelyConfig.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
using Newtonsoft.Json;
18+
using System;
1819
using System.Collections.Generic;
1920

2021
namespace OptimizelySDK.OptlyConfig
@@ -27,7 +28,15 @@ public class OptimizelyConfig
2728
public OptimizelyEvent[] Events { get; private set; }
2829
public OptimizelyAudience[] Audiences { get; private set; }
2930
public OptimizelyAttribute[] Attributes { get; private set; }
31+
32+
/// <summary>
33+
/// This experimentsMap is for experiments of legacy projects only.
34+
/// For flag projects, experiment keys are not guaranteed to be unique
35+
/// across multiple flags, so this map may not include all experiments
36+
/// when keys conflict.
37+
/// </summary>
3038
public IDictionary<string, OptimizelyExperiment> ExperimentsMap { get; private set; }
39+
3140
public IDictionary<string, OptimizelyFeature> FeaturesMap { get; private set; }
3241

3342
private string _datafile;

OptimizelySDK/OptlyConfig/OptimizelyConfigService.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,14 @@ private OptimizelyEvent[] GetEvents(ProjectConfig projectConfig)
7474

7575
private OptimizelyAudience[] GetAudiences(ProjectConfig projectConfig)
7676
{
77-
var filteredAudiencesArr = Array.FindAll(projectConfig.Audiences, aud => !aud.Id.Equals("$opt_dummy_audience"));
78-
var optimizelyAudience = filteredAudiencesArr.Select(aud => new OptimizelyAudience(aud.Id, aud.Name, aud.Conditions));
7977
var typedAudiences = projectConfig.TypedAudiences?.Select(aud => new OptimizelyAudience(aud.Id,
8078
aud.Name,
8179
JsonConvert.SerializeObject(aud.Conditions)));
80+
var typedAudienceIds = typedAudiences.Select(ta => ta.Id).ToList();
81+
var filteredAudiencesArr = Array.FindAll(projectConfig.Audiences, aud => !aud.Id.Equals("$opt_dummy_audience")
82+
&& !typedAudienceIds.Contains(aud.Id));
83+
var optimizelyAudience = filteredAudiencesArr.Select(aud => new OptimizelyAudience(aud.Id, aud.Name, aud.Conditions));
84+
8285
optimizelyAudience = optimizelyAudience.Concat(typedAudiences).OrderBy( aud => aud.Name);
8386

8487
return optimizelyAudience.ToArray<OptimizelyAudience>();
@@ -224,12 +227,11 @@ private IDictionary<string, OptimizelyFeature> GetFeaturesMap(ProjectConfig proj
224227
foreach (var featureFlag in projectConfig.FeatureFlags)
225228
{
226229

227-
var featureExperimentMap = experimentsMapById.Where(expMap => featureFlag.ExperimentIds.Contains(expMap.Key))
228-
.ToDictionary(k => k.Value.Key, v => v.Value);
230+
var experimentRules = featureFlag.ExperimentIds.Select(experimentId => experimentsMapById[experimentId]).ToList();
229231

230232
var featureVariableMap = featureFlag.Variables.Select(v => (OptimizelyVariable)v).ToDictionary(k => k.Key, v => v) ?? new Dictionary<string, OptimizelyVariable>();
231233

232-
var experimentRules = featureExperimentMap.Select(exMap => exMap.Value).ToList();
234+
var featureExperimentMap = experimentRules.ToDictionary(experiment => experiment.Key, experiment => experiment);
233235
var rollout = projectConfig.GetRolloutFromId(featureFlag.RolloutId);
234236
var deliveryRules = GetDeliveryRules(featureFlag.Id, rollout.Experiments, projectConfig);
235237

OptimizelySDK/OptlyConfig/OptimizelyFeature.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
using System;
1617
using System.Collections.Generic;
1718

1819
namespace OptimizelySDK.OptlyConfig
@@ -22,6 +23,8 @@ public class OptimizelyFeature : Entity.IdKeyEntity
2223

2324
public List<OptimizelyExperiment> ExperimentRules { get; private set; }
2425
public List<OptimizelyExperiment> DeliveryRules { get; private set; }
26+
27+
[Obsolete("Use experimentRules and deliveryRules.")]
2528
public IDictionary<string, OptimizelyExperiment> ExperimentsMap { get; private set; }
2629
public IDictionary<string, OptimizelyVariable> VariablesMap { get; private set; }
2730

0 commit comments

Comments
 (0)