@@ -461,7 +461,7 @@ public virtual Result<FeatureDecision> GetVariationForFeatureRollout(FeatureFlag
461461 //Check forced decision first
462462 var rule = rolloutRules [ index ] ;
463463 var decisionContext = new OptimizelyDecisionContext ( featureFlag . Key , rule . Key ) ;
464- var forcedDecisionResponse = user . FindValidatedForcedDecision ( decisionContext , config ) ;
464+ var forcedDecisionResponse = ValidatedForcedDecision ( decisionContext , config , user ) ;
465465
466466 reasons += forcedDecisionResponse . DecisionReasons ;
467467 if ( forcedDecisionResponse . ResultObject != null )
@@ -550,10 +550,9 @@ public virtual Result<FeatureDecision> GetVariationForFeatureExperiment(FeatureF
550550
551551 if ( string . IsNullOrEmpty ( experiment . Key ) )
552552 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+
557556 reasons += forcedDecisionResponse . DecisionReasons ;
558557
559558 if ( forcedDecisionResponse ? . ResultObject != null )
@@ -662,5 +661,32 @@ private Result<string> GetBucketingId(string userId, UserAttributes filteredAttr
662661
663662 return Result < string > . NewResult ( bucketingId , reasons ) ;
664663 }
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+ }
665691 }
666692}
0 commit comments