Problems with custom linking tool

I’m trying to do the following:

When a link is drawn, hit a web service to create some data. When the web service returns, add the link to the model. The link should not be added to the model until the web service returns.

I can’t quite seem to figure out how to do this. I saw LinkingTool.DoMouseUp, but I couldn’t figure out how to determine what the From and To nodes would be as well as whether or not a valid link could be drawn. Deriving my own class from LinkingTool and overriding DoMouseUp to first call base.DoMouseUp results in the link being added to the model – definitely not the behavior which I’m after.

The solution I’ve come up with is to handle the Diagram.LinkDrawn event, grab the Link from the DiagramEventArgs, examine its From/To, pass that data to my web service, and then immediately rollback the last transaction. This works, but seems like a terrible solution.

It sounds to me as if you really want to override …Model.InsertLink(NodeType, PortKey, NodeType, PortKey) to do what you want and return null. The LinkingTool calls …Model.AddLink which calls InsertLink to create the link and add it to the model. If it returns null the LinkingTool will automatically rollback any transaction.

Then when the “real” link is created, you can update the model. If you are using a GraphLinksModel you can just call AddLink(LinkType).

Thanks, exactly what I was looking for!