/// <summary> /// Changes the value of the capabiltiy to the given value and informs all dependent degraders about the change /// </summary> /// <param name="ruleSet">Ruleset of the capability containing also the triggers</param> /// <param name="targetCapability">The target capability value</param> /// <param name="alreadyUpdated">The capabilities that already have been updated</param> private static void ChangeCapabilityTo( CapabilityRuleSet ruleSet, int targetCapability, HashSet <ICapability> alreadyUpdated) { var current = ruleSet.Capability.Current; if (current != targetCapability) { ruleSet.Capability.Current = targetCapability; foreach (var dependent in ruleSet.DependentCapabilities) { dependent.Degrader.UpdateDegradation(dependent, alreadyUpdated); } foreach (var trigger in ruleSet.Triggers) { trigger(ruleSet.Capability); } } }
/// <summary> /// Gets the ruleset for a certain capability. If the ruleset does not exist before, /// it will be created and a new instance will be returned. /// </summary> /// <param name="targetCapability">Capability whose ruleset is queried</param> /// <param name="createIfNotExisting">true, if the ruleset shall be created</param> /// <returns>The found capability set</returns> private CapabilityRuleSet GetRuleSetFor(ICapability targetCapability, bool createIfNotExisting) { CheckThatInDegrader(targetCapability); CapabilityRuleSet result; if (!_rules.TryGetValue(targetCapability, out result)) { if (!createIfNotExisting) { throw new InvalidOperationException("Given capability does not exist"); } result = new CapabilityRuleSet { Capability = targetCapability }; _rules[targetCapability] = result; } return(result); }