@@ -461,7 +461,7 @@ public virtual Result<FeatureDecision> GetVariationForFeatureRollout(FeatureFlag
461
461
//Check forced decision first
462
462
var rule = rolloutRules [ index ] ;
463
463
var decisionContext = new OptimizelyDecisionContext ( featureFlag . Key , rule . Key ) ;
464
- var forcedDecisionResponse = user . FindValidatedForcedDecision ( decisionContext , config ) ;
464
+ var forcedDecisionResponse = ValidatedForcedDecision ( decisionContext , config , user ) ;
465
465
466
466
reasons += forcedDecisionResponse . DecisionReasons ;
467
467
if ( forcedDecisionResponse . ResultObject != null )
@@ -550,10 +550,9 @@ public virtual Result<FeatureDecision> GetVariationForFeatureExperiment(FeatureF
550
550
551
551
if ( string . IsNullOrEmpty ( experiment . Key ) )
552
552
continue ;
553
-
554
- var forcedDecisionResponse = user . FindValidatedForcedDecision (
555
- new OptimizelyDecisionContext ( featureFlag . Key , experiment ? . Key ) ,
556
- config ) ;
553
+ var decisionContext = new OptimizelyDecisionContext ( featureFlag . Key , experiment ? . Key ) ;
554
+ var forcedDecisionResponse = ValidatedForcedDecision ( decisionContext , config , user ) ;
555
+
557
556
reasons += forcedDecisionResponse . DecisionReasons ;
558
557
559
558
if ( forcedDecisionResponse ? . ResultObject != null )
@@ -662,5 +661,32 @@ private Result<string> GetBucketingId(string userId, UserAttributes filteredAttr
662
661
663
662
return Result < string > . NewResult ( bucketingId , reasons ) ;
664
663
}
664
+
665
+ /// <summary>
666
+ /// Finds a validated forced decision.
667
+ /// </summary>
668
+ /// <param name="context">Object containing flag and rule key of which forced decision is set.</param>
669
+ /// <param name="config">The Project config.</param>
670
+ /// <param name="user">Optimizely user context.</param>
671
+ /// <returns>A result with the variation</returns>
672
+ public Result < Variation > ValidatedForcedDecision ( OptimizelyDecisionContext context , ProjectConfig config , OptimizelyUserContext user )
673
+ {
674
+ DecisionReasons reasons = new DecisionReasons ( ) ;
675
+ var userId = user . GetUserId ( ) ;
676
+ var forcedDecision = user . GetForcedDecision ( context ) ;
677
+ if ( config != null && forcedDecision != null ) {
678
+ var loggingKey = context . RuleKey != null ? "flag (" + context . FlagKey + "), rule (" + context . RuleKey + ")" : "flag (" + context . FlagKey + ")" ;
679
+ var variationKey = forcedDecision . VariationKey ;
680
+ var variation = config . GetFlagVariationByKey ( context . FlagKey , variationKey ) ;
681
+ if ( variation != null ) {
682
+ reasons . AddInfo ( "Decided by forced decision." ) ;
683
+ reasons . AddInfo ( "Variation ({0}) is mapped to {1} and user ({2}) in the forced decision map." , variationKey , loggingKey , userId ) ;
684
+ return Result < Variation > . NewResult ( variation , reasons ) ;
685
+ } else {
686
+ reasons . AddInfo ( "Invalid variation is mapped to {0} and user ({1}) in the forced decision map." , loggingKey , userId ) ;
687
+ }
688
+ }
689
+ return Result < Variation > . NullResult ( reasons ) ;
690
+ }
665
691
}
666
692
}
0 commit comments