Visio Guy

Visio Discussions => Programming & Code => Topic started by: Visisthebest on September 29, 2020, 08:55:18 AM

Title: UndoScopes and transactional integrity
Post by: Visisthebest on September 29, 2020, 08:55:18 AM
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!
Title: Re: UndoScopes and transactional integrity
Post by: Paul Herber on September 29, 2020, 10:06:40 AM
It might be worth testing to see if auto-save occurs during an undo scope.
Title: Re: UndoScopes and transactional integrity
Post by: Visisthebest on September 29, 2020, 10:59:26 AM
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.
Title: Re: UndoScopes and transactional integrity
Post by: 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?

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.
Title: Re: UndoScopes and transactional integrity
Post by: Visisthebest on September 29, 2020, 12:00:15 PM
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.
Title: Re: UndoScopes and transactional integrity
Post by: Paul Herber on September 29, 2020, 12:57:39 PM
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)

Title: Re: UndoScopes and transactional integrity
Post by: Visisthebest on September 29, 2020, 01:39:24 PM
Yes exactly Paul so in Visio creating a 20-minute long undoscope not that hard :)
Title: Re: UndoScopes and transactional integrity
Post by: Nikolay on September 29, 2020, 03:38:29 PM
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  :)
(https://i.paste.pics/A9C3Q.png)
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.
Title: Re: UndoScopes and transactional integrity
Post by: Visisthebest on September 29, 2020, 03:47:23 PM
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.