public void GenerateVariationKeyMap() { if (Variations == null) { return; } _VariationIdToVariationMap = ConfigParser <Variation> .GenerateMap(entities : Variations, getKey : a => a.Id, clone : true); _VariationKeyToVariationMap = ConfigParser <Variation> .GenerateMap(entities : Variations, getKey : a => a.Key, clone : true); isGenerateKeyMapCalled = true; }
//========================= Initialization =========================== /// <summary> /// Initialize the arrays and mappings /// This can't be done in the constructor because the object is created via serialization /// </summary> private void Initialize() { Groups = Groups ?? new Group[0]; Experiments = Experiments ?? new Experiment[0]; Events = Events ?? new Entity.Event[0]; Attributes = Attributes ?? new Attribute[0]; Audiences = Audiences ?? new Audience[0]; TypedAudiences = TypedAudiences ?? new Audience[0]; FeatureFlags = FeatureFlags ?? new FeatureFlag[0]; Rollouts = Rollouts ?? new Rollout[0]; _GroupIdMap = ConfigParser <Group> .GenerateMap(entities : Groups, getKey : g => g.Id.ToString(), clone : true); _ExperimentKeyMap = ConfigParser <Experiment> .GenerateMap(entities : Experiments, getKey : e => e.Key, clone : true); _EventKeyMap = ConfigParser <Entity.Event> .GenerateMap(entities : Events, getKey : e => e.Key, clone : true); _AttributeKeyMap = ConfigParser <Attribute> .GenerateMap(entities : Attributes, getKey : a => a.Key, clone : true); _AudienceIdMap = ConfigParser <Audience> .GenerateMap(entities : Audiences, getKey : a => a.Id.ToString(), clone : true); _FeatureKeyMap = ConfigParser <FeatureFlag> .GenerateMap(entities : FeatureFlags, getKey : f => f.Key, clone : true); _RolloutIdMap = ConfigParser <Rollout> .GenerateMap(entities : Rollouts, getKey : r => r.Id.ToString(), clone : true); // Overwrite similar items in audience id map with typed audience id map. var typedAudienceIdMap = ConfigParser <Audience> .GenerateMap(entities : TypedAudiences, getKey : a => a.Id.ToString(), clone : true); foreach (var item in typedAudienceIdMap) { _AudienceIdMap[item.Key] = item.Value; } foreach (Group group in Groups) { var experimentsInGroup = ConfigParser <Experiment> .GenerateMap(group.Experiments, getKey : e => e.Key, clone : true); foreach (Experiment experiment in experimentsInGroup.Values) { experiment.GroupId = group.Id; experiment.GroupPolicy = group.Policy; } // RJE: I believe that this is equivalent to this: // $this->_experimentKeyMap = array_merge($this->_experimentKeyMap, $experimentsInGroup); foreach (string key in experimentsInGroup.Keys) { _ExperimentKeyMap[key] = experimentsInGroup[key]; } } foreach (Experiment experiment in _ExperimentKeyMap.Values) { _VariationKeyMap[experiment.Key] = new Dictionary <string, Variation>(); _VariationIdMap[experiment.Key] = new Dictionary <string, Variation>(); _ExperimentIdMap[experiment.Id] = experiment; if (experiment.Variations != null) { foreach (Variation variation in experiment.Variations) { _VariationKeyMap[experiment.Key][variation.Key] = variation; _VariationIdMap[experiment.Key][variation.Id] = variation; } } } // Adding Rollout variations in variation id and key maps. foreach (var rollout in Rollouts) { foreach (var rolloutRule in rollout.Experiments) { _VariationKeyMap[rolloutRule.Key] = new Dictionary <string, Variation>(); _VariationIdMap[rolloutRule.Key] = new Dictionary <string, Variation>(); if (rolloutRule.Variations != null) { foreach (var variation in rolloutRule.Variations) { _VariationKeyMap[rolloutRule.Key][variation.Key] = variation; _VariationIdMap[rolloutRule.Key][variation.Id] = variation; } } } } // Adding experiments in experiment-feature map. foreach (var feature in FeatureFlags) { foreach (var experimentId in feature.ExperimentIds ?? new List <string>()) { if (ExperimentFeatureMap.ContainsKey(experimentId)) { ExperimentFeatureMap[experimentId].Add(feature.Id); } else { ExperimentFeatureMap[experimentId] = new List <string> { feature.Id } }; } } }
/// <summary> /// Initialize the arrays and mappings /// This can't be done in the constructor because the object is created via serialization /// </summary> private void Initialize() { Groups = Groups ?? new Group[0]; Experiments = Experiments ?? new Experiment[0]; Events = Events ?? new Entity.Event[0]; Attributes = Attributes ?? new Attribute[0]; Audiences = Audiences ?? new Audience[0]; FeatureFlags = FeatureFlags ?? new FeatureFlag[0]; Rollouts = Rollouts ?? new Rollout[0]; _ForcedVariationMap = new Dictionary <string, Dictionary <string, string> >(); _GroupIdMap = ConfigParser <Group> .GenerateMap(entities : Groups, getKey : g => g.Id.ToString(), clone : true); _ExperimentKeyMap = ConfigParser <Experiment> .GenerateMap(entities : Experiments, getKey : e => e.Key, clone : true); _EventKeyMap = ConfigParser <Entity.Event> .GenerateMap(entities : Events, getKey : e => e.Key, clone : true); _AttributeKeyMap = ConfigParser <Attribute> .GenerateMap(entities : Attributes, getKey : a => a.Key, clone : true); _AudienceIdMap = ConfigParser <Audience> .GenerateMap(entities : Audiences, getKey : a => a.Id.ToString(), clone : true); _FeatureKeyMap = ConfigParser <FeatureFlag> .GenerateMap(entities : FeatureFlags, getKey : f => f.Key, clone : true); _RolloutIdMap = ConfigParser <Rollout> .GenerateMap(entities : Rollouts, getKey : r => r.Id.ToString(), clone : true); foreach (Group group in Groups) { var experimentsInGroup = ConfigParser <Experiment> .GenerateMap(group.Experiments, getKey : e => e.Key, clone : true); foreach (Experiment experiment in experimentsInGroup.Values) { experiment.GroupId = group.Id; experiment.GroupPolicy = group.Policy; } // RJE: I believe that this is equivalent to this: // $this->_experimentKeyMap = array_merge($this->_experimentKeyMap, $experimentsInGroup); foreach (string key in experimentsInGroup.Keys) { _ExperimentKeyMap[key] = experimentsInGroup[key]; } } foreach (Experiment experiment in _ExperimentKeyMap.Values) { _VariationKeyMap[experiment.Key] = new Dictionary <string, Variation>(); _VariationIdMap[experiment.Key] = new Dictionary <string, Variation>(); _ExperimentIdMap[experiment.Id] = experiment; if (experiment.Variations != null) { foreach (Variation variation in experiment.Variations) { _VariationKeyMap[experiment.Key][variation.Key] = variation; _VariationIdMap[experiment.Key][variation.Id] = variation; } } } // Adding Rollout variations in variation id and key maps. foreach (var rollout in Rollouts) { foreach (var rolloutRule in rollout.Experiments) { _VariationKeyMap[rolloutRule.Key] = new Dictionary <string, Variation>(); _VariationIdMap[rolloutRule.Key] = new Dictionary <string, Variation>(); if (rolloutRule.Variations != null) { foreach (var variation in rolloutRule.Variations) { _VariationKeyMap[rolloutRule.Key][variation.Key] = variation; _VariationIdMap[rolloutRule.Key][variation.Id] = variation; } } } } }