Transaction is being rolled back while showing a MessageBox

I am creating a similar diagram and while dropping the link from one node to other I was showing a message box for confirmation and I add links from a pallet

while adding links I am not getting issue if I add from pallet but if I am relinking the existing link to other node during message box AbortTransation is happening rather than “moveselection” transaction.

I’m confused about exactly what’s happening. Is this the situation?

  • the user has selected a Link that is relinkable
  • the user drags one of the relinking handles, thereby starting the RelinkingTool
  • at some time you put up a MessageBox

The question is when and how you put up that MessageBox. In general it is not a good idea to interrupt user actions with modal dialogs.

Have you overridden any methods on RelinkingTool? Have you implemented any Diagram.LinkRelinked event listener?

I have inherited DraggingTool and overridden DropOnto and DoDrop
I am displaying MessageBox in those methods

Are you overriding both methods? That’s unusual. Also, are you calling the base method in both overrides? What are you doing in those overrides? It is unlikely that you need to override DoDrop, and I am guessing that in doing so you have broken the DraggingTool’s transaction.

Yes I am overriding both the methods and I am calling the base methods in both overrides
In both overrides I have written some validations and displaying a confirmation MessageBox
If overridden has broken the transaction the dragging link from pallet should also broke the transaction which isn’t happening.

Is there any difference between dragging a link from link pallet and re-linking the connected link to other node?

Wait – have you set DraggingTool.DraggableLinks to true and are you talking about dragging a Link in order to reconnect both ends of an existing Link?

Then yes, DraggingTool.DropOnto does handle the reconnection of the dragged Link.

Try not overriding DraggingTool.DoDrop.

I tried not overriding DraggingTool.DoDrop and I am displaying MessageBox in DropOnto before displaying the MessageBox, ChangeLinkFromPort transactions are being called followed by RolledbackTransaction

What are your overrides and Diagram event listeners?

Hi Walter,

DraggingTool - DropOnto
RelinkingTool- IsValidLink

Diagram EventListeners


Does any of your code cancel the transaction? Or set DiagramTool.TransactionResult to null, or fail to set it?

What does your DropOnto method do? What does your Model Changed listener do?

  1. To be specific, the DraggingTool code works fine while “AddingLink” but it rollbacks in “MoveSelection”. We do have some Rollback transactions but none of them gets called explicitly in this scenario.
  2. We are not setting TransactionResult at all.
  3. DropOnto() - We get the DraggedLink and check either FromData or ToData for a certain property. If it is set to some value, we show a message box and ask the user if he would like to continue, if he selects Yes, we go ahead and perform our operation, if not we are calling DoCancel() and RollbackTransaction().
    As and when we call the MessageBox.Show() - the transaction is rolled back.

Model Changed - We are storing the custom data to the database for CommittedTransactions.

  1. In DropOnto() - DoCancel() does cancel the Dragging Tool but UI doesn’t get refreshed ? Any idea ?
    This again works fine in “AddingLink” but not in “MoveSelection”

Thanks in advance. :)

If there is some path in which TransactionResult is not set, then a call to StopTransaction (GoXam for WPF 2.2.4) will result in a rollback.

When calling DoCancel inside DropOnto, what UI does not get “refreshed”? Can the user “refresh” it somehow?

  1. So, is it mandatory to assign values to TransactionResult for every transaction of ours ??
    Even at that point where we show the dialog, if we skip that code execution, it works fine but we need that Message Box to be shown.
  2. When calling DoCancel() in DropOnto() the diagram doesn’t refresh.
    Lets say I have moved my Link from Terminal A to Terminal B and in DraggingTool, I have called DoCanel(), the link shows connected to Terminal B rather than Terminal A. (Note: This works fine when I am adding a link from Palette control which triggers AddingLink)

Yes, it is mandatory to set TransactionResult to a non-null value if you want the transaction to commit instead of to rollback. However you are callling the base method of DoDrop, or you are not overriding that method at all, which should result in setting TransactionResult in the normal behavior.

When I try calling MessageBox.Show in an override of DropOnto, it always works well, completing the move as expected:

    protected override void DropOnto(Point pt) {

Hi Walter,

We are calling the base.DropOnto(pt) method. That’s the first line in our override as well. Is there any way to know what triggered the Rollback Transaction ???

In the mean time, I will try setting the TransactionResult and see if that works,

Thanks for your time :)

The implementation of DraggingToolDoDrop first sets TransactionResult, then calls DropOnto, then raises a Diagram event, and finally calls StopTransaction (which looks at TransactionResult to decide whether to commit or rollback).

The built-in implementation of DropOnto does not set TransactionResult.

For debugging I suppose you could override StopTransaction to check the value of DiagramTool.TransactionResult before calling the base method.