UndoScopes and transactional integrity

Started by Visisthebest, September 29, 2020, 08:55:18 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Visisthebest

The EndUndoScope method provides a really useful option to cancel the changes made since the beginning of a particular UndoScope:
https://docs.microsoft.com/en-us/office/vba/api/visio.application.endundoscope

This is very useful to make sure all changes to the Visio diagram are made in its entirety before committing 'an complete correct transaction'. If there is an issue, we can cancel the changes made in this undoscope.

What is very hard to test though is what happens if for instance a user's battery dies during the UndoScope and an AutoSave runs during the UndoScope. Is it possible that a partial set of changes is applied to the diagram in the file that the user can recover from Office's file recovery function? This possibility requires more error-checking.

Thank you for sharing your insights!
Visio 2021 Professional

Paul Herber

It might be worth testing to see if auto-save occurs during an undo scope.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Visisthebest

If it doesn't and a huge undo scope takes 20 minutes, then an Autosave every 5 minutes might not execute for more than 20 minutes which sounds unsafe if the user expects a 5-minute autosave.
Visio 2021 Professional

Nikolay

Just wondering how undo scope can be 20 minutes.
From what I understand it should be instant (user clicks the "undo" button), should it not?

Also, I usually ignore such corner-cases like "battery dying in the middle of undo" as unlikely.
Visio is also not a database to take these into account.

Visisthebest

Thinking about what cases of diagram data corruption I could be overlooking, of course more realistic ones than a huge undoscope that adds a ton of complicated shapes and manipulates them. This is just an idea for a test to discover Visio's behavior.
Visio 2021 Professional

Paul Herber

Quote from: Nikolay on September 29, 2020, 11:54:09 AM
Just wondering how undo scope can be 20 minutes.
From what I understand it should be instant (user clicks the "undo" button), should it not?

Undo scope starts when the named scope is created, then the actions are performed, then the scope is closed.

scopeID = beginUndoScope("scopeName")
   do undoableactions
endUndoScope(scopeID)

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Visisthebest

Yes exactly Paul so in Visio creating a 20-minute long undoscope not that hard :)
Visio 2021 Professional

Nikolay

#7
I mean, from the user prospective, undo scopes are the items under "undo" button, even though they are created programmatically (that's where the "scopename" goes).
So making a 20 minutes undo scope means, user clicks undo button and goes for a coffee, as everything will freeze fo 20 minutes  :)

Btw, if an add-on does something like that, there are good chance to get "blacklisted" : Visio freezes, user kills it, and on the next start Visio suggests to blacklist the add-on with "yes" selected by default.

Visisthebest

Yes you're right that should not be proper behavior, but we thought of it as a test to understand the 'transactional' behavior of the undoscopes.

For instance, for our current solution it is essential that some data like the UniqueID is set in a shape, if a shape would be created but not properly initialized with data we want to set bcommit to False when running the endundoscope method:
https://docs.microsoft.com/en-us/office/vba/api/visio.application.endundoscope

to avoid creating a 'corrupt' diagram.

Visio 2021 Professional