Fix traffic role editing and network validation#7
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces comprehensive validation for network edges and traffic profiles, ensuring numerical values are valid and non-negative. It also refactors the view model to centralize traffic definition creation and adds logic to handle name changes, including normalization and duplicate detection. A potential runtime exception was identified in the name change handler due to collection modification during iteration, which should be addressed by using a snapshot of the collection.
| foreach (var node in Nodes) | ||
| { | ||
| foreach (var profile in node.TrafficProfiles.Where(profile => Comparer.Equals(profile.TrafficType, e.OldValue))) | ||
| foreach (var profile in node.TrafficProfiles.Where(profile => Comparer.Equals(profile.TrafficType, oldValue))) |
There was a problem hiding this comment.
Iterating over node.TrafficProfiles while modifying its elements' properties can lead to an InvalidOperationException (Collection was modified) if the property change triggers a profile normalization that removes items from the collection. Since profile.TrafficType = normalizedName can cause NormalizeNodeTrafficProfiles to run and potentially remove duplicate profiles, you should create a snapshot of the matching profiles before iterating.
foreach (var profile in node.TrafficProfiles.Where(profile => Comparer.Equals(profile.TrafficType, oldValue)).ToList())
No description provided.