private void add(PoI poi, bool isThreat)
{
var effectStates = new List<EffectState>();
var resourceStates = new List<ResourceState>();
var activePhases = new List<string>();
// Clear all influences
poi.Labels[InfluenceLabel] = string.Empty;
// Process the labels
foreach (var label in poi.Labels)
{
// Test to see if there is a match in the InputText
var match = regex.Match(label.Key);
if (!match.Success) continue;
var eamType = match.Groups[1].Value.ToLower(); // Index 0 represents the capture
var title = match.Groups[2].Value.ToLower();
switch (eamType)
{
case "effect":
if (string.IsNullOrEmpty(label.Value)) continue;
EffectLevel level;
if (!Enum.TryParse<EffectLevel>(label.Value, out level) || level == EffectLevel.None) continue;
var isDisturbance = label.Key.EndsWith(DisturbanceLevelLabel);
var effect = new EffectState(title, level, isDisturbance);
effectStates.Add(effect);
break;
case "capacity":
if (string.IsNullOrEmpty(label.Value) || string.Equals(label.Value, "0", StringComparison.InvariantCultureIgnoreCase)) continue;
var resourceState = new ResourceState(title);
resourceState.AddCapacity(label.Value);
resourceStates.Add(resourceState);
break;
case "phase":
if (TryGetPhaseState(title) == null) phaseStates.Add(new PhaseState(title));
if (!string.Equals(label.Value, "true", StringComparison.InvariantCultureIgnoreCase)) continue;
activePhases.Add(title);
break;
}
}
// Update each phase that is affected
foreach (var title in activePhases)
{
var phase = TryGetPhaseState(title);
if (phase == null) return;
if (isThreat)
phase.Threats .Add(new PoIState(poi, effectStates));
else
phase.Measures.Add(new PoIState(poi, effectStates, resourceStates));
foreach (var rs in resourceStates)
{
ResourceState resourceState;
if (phase.resourceStates.TryGetValue(rs.Name, out resourceState)) resourceState.AddCapacityAsNumber(rs.Capacity);
else phase.resourceStates.TryAdd(rs.Name, rs);
}
}
}