<p>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)</p>

<p>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.</p>

<p>Does anyony have any suggestions for design patterns or structures that could be usefull for this ?</p>

[{'answer_id': 22176, 'author': 'Thomas Owens', 'author_id': 572, 'author_profile': 'https://Stackoverflow.com/users/572', 'pm_score': 2, 'selected': False, 'text': '<p>The GoF Command Pattern supports undoable operations.</p>\n\n<p>I think the same pattern can be used for sequential operations (sequential commands).</p>\n'}, {'answer_id': 22198, 'author': 'Kev', 'author_id': 419, 'author_profile': 'https://Stackoverflow.com/users/419', 'pm_score': 0, 'selected': False, 'text': '<p>You might want to have a look at the Compensating Resource Manager:</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/8xkdw05k(VS.80).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/8xkdw05k(VS.80).aspx</a></p>\n'}, {'answer_id': 22220, 'author': 'vitule', 'author_id': 1287, 'author_profile': 'https://Stackoverflow.com/users/1287', 'pm_score': 3, 'selected': True, 'text': '<p>If your changes are done to the SharePoint object model, you can use the fact that changes are not committed until you call the <code>Update()</code> method of the modified object, such as <code>SPList.Update()</code> or <code>SPWeb.Update()</code>.</p>\n\n<p>Otherwise, I would use the <em>Command</em> Design Pattern. Chapter 6 in <a href="https://rads.stackoverflow.com/amzn/click/com/0596007124" rel="nofollow noreferrer" rel="nofollow noreferrer">Head First Design Patterns</a> even has an example that implements the undo functionality.</p>\n'}, {'answer_id': 22266, 'author': 'On Freund', 'author_id': 2150, 'author_profile': 'https://Stackoverflow.com/users/2150', 'pm_score': 0, 'selected': False, 'text': '<p>If you\'re using C++ (or any other language with deterministic destructor execution when scopes end) you can take a look at <a href="http://www.ddj.com/cpp/184403758" rel="nofollow noreferrer">Scope Guards</a>. This technique can probably also be adapted to .NET by making ScopeGuard implement IDisposable and sprinkling "using" statements as needed.</p>\n'}, {'answer_id': 22287, 'author': 'Huppie', 'author_id': 1830, 'author_profile': 'https://Stackoverflow.com/users/1830', 'pm_score': 1, 'selected': False, 'text': '<p>Next to the GOF <a href="http://en.wikipedia.org/wiki/Command_Pattern" rel="nofollow noreferrer">Command Pattern</a> you might also want to have a look at the <a href="http://martinfowler.com/eaaCatalog/transactionScript.html" rel="nofollow noreferrer">Transaction Script</a> pattern from <a href="http://martinfowler.com/books.html#eaa" rel="nofollow noreferrer">P of EAA</a>.</p>\n<p>You should probably create a Composite Command (or Transaction Script) that executes in sequence.</p>\n'}, {'answer_id': 32657, 'author': 'Cem Catikkas', 'author_id': 3087, 'author_profile': 'https://Stackoverflow.com/users/3087', 'pm_score': 2, 'selected': False, 'text': '<p>Another good way for rollback/undo is the <a href="http://en.wikipedia.org/wiki/Memento_pattern" rel="nofollow noreferrer">Memento Pattern</a>. It\'s usually used to take a snapshot of the object at a given time and let the object state to be reverted to the memento.</p>\n'}]
['https://Stackoverflow.com/questions/22165', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/983/']