0

I am performing a series of steps, when I run the console application. Let's say the number of steps are 8, and it fails somewhere at the 4th step.

I wanted to be able to revert the first steps that I did before it failed. How can this be done, if it fails at any of steps?

Cipher
  • 5,894
  • 22
  • 76
  • 112
  • 1
    What are you reverting? Data changes? If so where are the changes? A database? A file? – tsells Apr 23 '12 at 03:38
  • Some of these changes are `tasks` created in task scheduler. Other changes are configurations done in `IIS`? I have to revert all of these. – Cipher Apr 23 '12 at 03:49
  • So are you asking how to unschedule stuff and how to revert IIS configurations? Given that you've asked 150+ questions, you really should have gotten better at it. – Roman Apr 23 '12 at 03:57
  • The question is not actually on how to unschedule or remove IIS config. It's about maintaining some kind of `stack` of these changes done, and revert on failure. The primary catechism is about how to build this stack of completed steps with the associated changes (revert steps). – Cipher Apr 23 '12 at 04:01
  • Then I don't really see the difficulty. Stack is one of the first data structures you learn in programming. I'm assuming you know how to read the state of whatever you're changing through code. The rest is pretty straight forward: Save state -> Make your change -> Put object with old state onto stack -> Done. – Roman Apr 23 '12 at 04:05

1 Answers1

0

If you implement the steps using the command pattern where each step knows how to do itself as well as undo itself. Then you would be able to just loop through the steps that have been done and undo them.

You may also be interested in this question Implementing the command pattern.

Community
  • 1
  • 1
Roman
  • 19,581
  • 6
  • 68
  • 84