/// <summary>Returns the OverrideSet of the chosen index.</summary> /// <param name="index">Any integer value of your choice can be used to refer to an OverrideSet.</param> public OverrideSet <TObject> GetOverrideSet(int index) { if (!overrideSets.ContainsKey(index)) { overrideSets[index] = new OverrideSet <TObject>(); } return(overrideSets[index]); }
internal void CheckInstanceChanged(StatusInstance <TObject> instance) { bool stacked = instance.overrideSetIndex != null; if (stacked) { OverrideSet <TObject> overrideSet = rules.overrideSets[instance.overrideSetIndex.Value]; if (overrideSet == null) { throw new InvalidOperationException($"Override set {instance.overrideSetIndex.Value} does not exist"); } changeStack.Add(overrideSet.onChangedOverrides); } CheckRawChanged(instance.Status, instance.InstanceType); if (stacked) { changeStack.RemoveAt(changeStack.Count - 1); } }
private void CheckRawChanged(TBaseStatus status, InstanceType type) { bool stacked = false; if (rules.overrideSetsForStatuses.TryGetValue(status, out int overrideSetIndex)) { stacked = true; OverrideSet <TObject> overrideSet = rules.overrideSets[overrideSetIndex]; if (overrideSet == null) { throw new InvalidOperationException($"Override set {overrideSetIndex} does not exist"); } changeStack.Add(overrideSet.onChangedOverrides); } else if (rules.onChangedHandlers[status] != null) { stacked = true; changeStack.Add(rules.onChangedHandlers[status]); } var values = statusInstances[type][status].Select(x => x.Value); if (internalFeeds[type].ContainsKey(status)) { values = values.Concat(internalFeeds[type][status].Values); } IEnumerable <TBaseStatus> upstreamStatuses; // 'Upstream' and 'downstream' statuses change depending on the InstanceType. IEnumerable <TBaseStatus> downstreamStatuses; // Value changes to a status are also applied to statuses that this one extends... if (type == InstanceType.Feed) { upstreamStatuses = rules.statusesThatExtend[status]; downstreamStatuses = rules.statusesExtendedBy[status]; } else { upstreamStatuses = rules.statusesExtendedBy[status]; // ...while negative changes to a status go the other way, downstreamStatuses = rules.statusesThatExtend[status]; // being applied to statuses that extend this one. } foreach (TBaseStatus otherStatus in upstreamStatuses) { values = values.Concat(statusInstances[type][otherStatus].Select(x => x.Value)); if (internalFeeds[type].ContainsKey(otherStatus)) { values = values.Concat(internalFeeds[type][otherStatus].Values); } } int newValue = rules.GetAggregator(status, type)(values); int oldValue = currentRaw[type][status]; if (newValue != oldValue) { currentRaw[type][status] = newValue; if (type == InstanceType.Feed || type == InstanceType.Suppress) { CheckActualValueChanged(status); } } foreach (TBaseStatus otherStatus in downstreamStatuses) { CheckRawChanged(otherStatus, type); } if (stacked) { changeStack.RemoveAt(changeStack.Count - 1); } }