Пример #1
0
        /// <summary>
        /// Set a forced decision.
        /// </summary>
        /// <param name="context">The context object containing flag and rule key.</param>
        /// <param name="decision">OptimizelyForcedDecision object containing variation key.</param>
        /// <returns></returns>
        public bool SetForcedDecision(OptimizelyDecisionContext context, OptimizelyForcedDecision decision)
        {
            lock (mutex)
            {
                ForcedDecisionsStore[context] = decision;
            }

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Removes a forced decision.
        /// </summary>
        /// <param name="context">The context object containing flag and rule key.</param>
        /// <returns>Whether the item was removed.</returns>
        public bool RemoveForcedDecision(OptimizelyDecisionContext context)
        {
            if (context == null || !context.IsValid)
            {
                Logger.Log(LogLevel.WARN, "FlagKey cannot be null");
                return(false);
            }

            lock (mutex)
            {
                return(ForcedDecisionsStore.Remove(context));
            }
        }
Пример #3
0
 public OptimizelyForcedDecision this[OptimizelyDecisionContext context]
 {
     get
     {
         if (context != null && context.IsValid &&
             ForcedDecisionsMap.TryGetValue(context.GetKey(), out OptimizelyForcedDecision flagForcedDecision))
         {
             return(flagForcedDecision);
         }
         return(null);
     }
     set
     {
         if (context != null && context.FlagKey != null)
         {
             ForcedDecisionsMap[context.GetKey()] = value;
         }
     }
 }
Пример #4
0
        /// <summary>
        /// Gets a forced variation
        /// </summary>
        /// <param name="context">The context object containing flag and rule key.</param>
        /// <returns>The variation key for a forced decision</returns>
        public OptimizelyForcedDecision GetForcedDecision(OptimizelyDecisionContext context)
        {
            if (context == null || !context.IsValid)
            {
                Logger.Log(LogLevel.WARN, "flagKey cannot be null");
                return(null);
            }

            if (ForcedDecisionsStore.Count == 0)
            {
                return(null);
            }

            OptimizelyForcedDecision decision = null;

            lock (mutex)
            {
                decision = ForcedDecisionsStore[context];
            }
            return(decision);
        }
Пример #5
0
        /// <summary>
        /// Finds a validated forced decision.
        /// </summary>
        /// <param name="context">Object containing flag and rule key of which forced decision is set.</param>
        /// <param name="config">The Project config.</param>
        /// <returns>A result with the variation</returns>
        public Result <Variation> FindValidatedForcedDecision(OptimizelyDecisionContext context, ProjectConfig config)
        {
            DecisionReasons reasons        = new DecisionReasons();
            var             forcedDecision = GetForcedDecision(context);

            if (config != null && forcedDecision != null)
            {
                var loggingKey   = context.RuleKey != null ? "flag (" + context.FlagKey + "), rule (" + context.RuleKey + ")" : "flag (" + context.FlagKey + ")";
                var variationKey = forcedDecision.VariationKey;
                var variation    = config.GetFlagVariationByKey(context.FlagKey, variationKey);
                if (variation != null)
                {
                    reasons.AddInfo("Decided by forced decision.");
                    reasons.AddInfo("Variation ({0}) is mapped to {1} and user ({2}) in the forced decision map.", variationKey, loggingKey, UserId);
                    return(Result <Variation> .NewResult(variation, reasons));
                }
                else
                {
                    reasons.AddInfo("Invalid variation is mapped to {0} and user ({1}) in the forced decision map.", loggingKey, UserId);
                }
            }
            return(Result <Variation> .NullResult(reasons));
        }
Пример #6
0
 public bool Remove(OptimizelyDecisionContext context)
 {
     return(ForcedDecisionsMap.Remove(context.GetKey()));
 }