I have a need to create a ‘transactional’ process using an external API that does not support COM+ or .NET transactions (Sharepoint to be exact)
What I need to do is to be able to perform a number of processes in a sequence, but any failure in that sequence means that I will have to manually undo all of the previous steps. In my case there are only 2 types of step, both af which are fairly easy to undo/roll back.
Does anyony have any suggestions for design patterns or structures that could be usefull for this ?
If your changes are done to the SharePoint object model, you can use the fact that changes are not committed until you call the
Update()method of the modified object, such asSPList.Update()orSPWeb.Update().Otherwise, I would use the Command Design Pattern. Chapter 6 in Head First Design Patterns even has an example that implements the undo functionality.