Securely Undoing the Command.

Securely Undoing the Command.

structure1EKNKU
Enthusiast Enthusiast
312 Views
2 Replies
Message 1 of 3

Securely Undoing the Command.

structure1EKNKU
Enthusiast
Enthusiast

Hello!

 

I need to conditionally disable executing commands. The problem is that some of the conditions can only be checked after the command is fully executed.

 

I use the Idling event to be able to make my stuff at this very moment but I'm out of the ideas how to safely return to the state as it would be if the command hadn't ever be executed. I mean: I can undo the command by posting the PostableCommand.Undo and this would be fine but it activates the Redo option. The problem is that PostableCommand.Redo cannot be bound, otherwise I would just undo all the executions of Redo command (or even block it by binding its Execute() to an empty function) so I also cannot really rely on my Idling function to check whether Redo was indeed the last executed command and, if this is the case, undo it.

 

What is the recommended approach? Of course I assume that I would only use it where there is a point of having a state as if the command had never been executed, I don't want miracles like undoing deleting the file or printing it.

313 Views
2 Replies
Replies (2)
Message 2 of 3

dtartaglia_PYEBEB5KA84W
Enthusiast
Enthusiast

Are these commands from a custom add-in you have the source code for? If so can you add logic in the command itself to not execute unless your conditions are met?

0 Likes
Message 3 of 3

structure1EKNKU
Enthusiast
Enthusiast

No, these are commands like PostableCommand.CreateGroup, where what user enters in the appearing forms (for example, group names) actually decides about whether I want to allow the command or not. I would also undo (and forbid retrying) some commands if their full execution takes more than a given amount of time.

0 Likes