Guest User

Untitled

a guest
Jun 6th, 2013
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 KB | None | 0 0
  1.     class AskValues : Action
  2.     {
  3.         public override void DoAction()
  4.         {
  5.             if (String.IsNullOrEmpty(this.VariablesToSet))
  6.             {
  7.                 throw new ActionException("No variables listed", this);
  8.             }
  9.  
  10.             Form form = new Form();
  11.  
  12.             // add controls to form
  13.  
  14.             form.FormClosed += delegate
  15.                                {
  16.                                    switch (form.DialogResult)
  17.                                    {
  18.                                    case DialogResult.OK:
  19.                                        // do stuff
  20.                                        break;
  21.                                    case DialogResult.Cancel:
  22.                                        throw new FatalActionException("Cancel Clicked", this);
  23.                                    }
  24.                                };
  25.  
  26.             MainWindow.Invoke(new Func<Form, DialogResult>(form.ShowDialog), MainWindow);
  27.         }
  28.  
  29.  
  30.     class MainWindow : Form
  31.     {
  32.         private RunButton_Clicked(object sender, EventArgs e)
  33.         {
  34.             this.backgroundWorker1.RunWorkerAsync()
  35.         }
  36.  
  37.         private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
  38.         {
  39.             Core.RunJob();
  40.         }
  41.  
  42.         public ApplicationCore Core;
  43.  
  44.     }
  45.  
  46.     class ApplicationCore
  47.     {
  48.  
  49.         public void RunJob()
  50.         {
  51.             CurrentAction = Actions.First();
  52.  
  53.             while (CurrentAction != null)
  54.             {
  55.                 if (!RunStep(CurrentAction))
  56.                     break;
  57.                
  58.                CurrentAction = CurrentAction.GetNext();
  59.             }
  60.         }
  61.         private void RunStep(IAction currentAction)
  62.         {
  63.             try
  64.             {
  65.                 currentAction.DoAction();
  66.                 OnAfterAction(args);
  67.    
  68.                 return true;
  69.    
  70.             }
  71.             catch (FatalActionException e)
  72.             {
  73.                 // handle error
  74.                 return false;
  75.             }
  76.         }
  77.     }
Advertisement
Add Comment
Please, Sign In to add comment