/// <summary> /// Add a condition to the collection. /// </summary> /// <param name="conditionName">The unique name of the condition.</param> /// <param name="condition">The condition instance that will be added to the collection.</param> /// <exception cref="System.ArgumentException">Thrown if a condition with the given name already exists in the collection.</exception> public void AddCondition(string conditionName, IRatingCondition condition) { _ratingConditions.Add(conditionName, condition); if (condition is ICachableCondition cachableCondition && cachableCondition.CacheCurrentValue) { if (!RatingConditionCache.Load(conditionName, cachableCondition)) { RatingConditionCache.Save(conditionName, cachableCondition); } } }
/// <summary> /// Initialize the rating gateway with a single condition. /// </summary> /// <param name="conditionName">The unique name of the condition.</param> /// <param name="condition">The condition instance that will be added to the collection.</param> /// <param name="ratingView">Optional; pass a custom rating view. If not specified or null, <see cref="DefaultRatingView"/> will be used instead.</param> /// <param name="ratingCache">Optional; pass a custom condition cache. If not specified or null, <see cref="DefaultRatingConditionCache"/> will be used instead.</param> /// <remarks>Call it only once in the lifetime of a <see cref="RatingGateway"/>. All other calls after the initial one, do just return.</remarks> public static void Initialize(string conditionName, IRatingCondition condition, IRatingView?ratingView = default, IRatingConditionCache?ratingCache = default) { if (Current.IsInitialized) { return; } Current.IsInitialized = true; Current.AddCondition(conditionName, condition); if (ratingView != null) { Current.RatingView = ratingView; } if (ratingCache != null) { Current.RatingConditionCache = ratingCache; } }