I have come across an issue wherein a ShapeNode's Incoming/Outgoing DiagramLinkCollection is being modified while I am performing a nested loop that checks Tag objects on links and their anchor points (I am not trying to delete or modify the links in the collections in any way while performing my loops). During the looping the order of the links inside the collections is changing (I am not programmatically doing this) which causes a collection modified exception.
Here is the code that has been giving me problems:
Private Function GetListOfFlowPaths(ByRef StartNode As MindFusion.Diagramming.ShapeNode, _
ByVal EntityNum As Entity1Or2) As System.Collections.Generic.List(Of HEXDesignII.FlowPath)
Dim ListOfFlowPaths As New System.Collections.Generic.List(Of HEXDesignII.FlowPath)
Dim FlwPth As HEXDesignII.FlowPath
Dim LastLink As MindFusion.Diagramming.DiagramLink
Dim NextLink As MindFusion.Diagramming.DiagramLink
Dim LastNode As MindFusion.Diagramming.ShapeNode = StartNode
Dim NextNode As MindFusion.Diagramming.ShapeNode
Dim iLink As MindFusion.Diagramming.DiagramLink
For Each iLink In StartNode.IncomingLinks
If GetLinkType(iLink) = LinkType.InletStart Then
NextLink = GetOutletLink(iLink)
If CType(NextLink.Tag, Entity1Or2) = EntityNum Then
'Found the starting link
LastLink = NextLink
'Get the FlowPath from the StartNode
FlwPth = GetFlowPath(LastLink, StartNode, False)
ListOfFlowPaths.Add(FlwPth)
LastNode = StartNode
Exit For
End If
End If
Next iLink
'Start the loop to define the list of flow paths for the defined entity flow
If GetLinkType(NextLink) <> LinkType.OutletEnd Then
'handles the 1 template case
Dim PathFinished As Boolean = False
Do
If LastLink IsNot Nothing Then
NextNode = LastLink.Destination
NextLink = GetOutletLink(LastLink)
If GetLinkType(NextLink) = LinkType.Outlet Then
'Found the final node in the path
FlwPth = GetFlowPath(LastLink, NextNode, True)
PathFinished = True
Else
If CType(NextLink.Tag, Entity1Or2) <> EntityNum Then
MsgBox("Assigned flow does not match between the inlet and outlet ports of at least one template", MsgBoxStyle.OkOnly, "HEXDesign Warning")
Else
FlwPth = GetFlowPath(NextLink, NextNode, False)
End If
End If
ListOfFlowPaths.Add(FlwPth)
LastLink = NextLink
LastNode = NextNode
End If
Loop Until PathFinished = True
End If
Return ListOfFlowPaths
End Function
Private Function GetOutletLink(ByRef InletLink As MindFusion.Diagramming.DiagramLink) As MindFusion.Diagramming.DiagramLink
'This routine can be called to get the flow connection link on the matching outlet port of the same node as the inlet link argument
Dim OutletLink As MindFusion.Diagramming.DiagramLink
Dim InltDest As Integer = InletLink.DestinationAnchor
For Each nodeLink As MindFusion.Diagramming.DiagramLink In InletLink.Destination.OutgoingLinks
If nodeLink.Visible Then
If InletLink.DestinationAnchor = GetAnchorIndex(InletLink.Destination, AnchorType.Inlet1) And _
nodeLink.OriginAnchor = GetAnchorIndex(nodeLink.Origin, AnchorType.Outlet1) Then
OutletLink = nodeLink
Exit For
ElseIf InletLink.DestinationAnchor = GetAnchorIndex(InletLink.Destination, AnchorType.Inlet2) And _
nodeLink.OriginAnchor = GetAnchorIndex(nodeLink.Origin, AnchorType.Outlet2) Then
OutletLink = nodeLink
Exit For
End If
End If
Next nodeLink
Return OutletLink
End Function
Private Function GetAnchorIndex(ByRef node As MindFusion.Diagramming.ShapeNode, ByVal AncType As AnchorType) As Integer
Dim index As Integer = -1
Dim counter As Integer
For Each AnchorPt As MindFusion.Diagramming.AnchorPoint In node.AnchorPattern.Points
If AnchorPt.Tag = AncType Then
index = counter
Exit For
End If
counter += 1
Next
Return index
End Function
The problem seems to only occur for this code structure where my nested looping and GetAnchorIndex() code is performed in separate functions.
While I have found a temporary patch to fix the error, the underlying problem still exists and could potentially influence future software development with FlowChart. I would greatly appreciate any insight or support that MindFusion can provide on this matter.
Thank you in advance.
- Chris