Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AskValues : Action
- {
- public override void DoAction()
- {
- if (String.IsNullOrEmpty(this.VariablesToSet))
- {
- throw new ActionException("No variables listed", this);
- }
- Form form = new Form();
- // add controls to form
- form.FormClosed += delegate
- {
- switch (form.DialogResult)
- {
- case DialogResult.OK:
- // do stuff
- break;
- case DialogResult.Cancel:
- throw new FatalActionException("Cancel Clicked", this);
- }
- };
- MainWindow.Invoke(new Func<Form, DialogResult>(form.ShowDialog), MainWindow);
- }
- class MainWindow : Form
- {
- private RunButton_Clicked(object sender, EventArgs e)
- {
- this.backgroundWorker1.RunWorkerAsync()
- }
- private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
- {
- Core.RunJob();
- }
- public ApplicationCore Core;
- }
- class ApplicationCore
- {
- public void RunJob()
- {
- CurrentAction = Actions.First();
- while (CurrentAction != null)
- {
- if (!RunStep(CurrentAction))
- break;
- CurrentAction = CurrentAction.GetNext();
- }
- }
- private void RunStep(IAction currentAction)
- {
- try
- {
- currentAction.DoAction();
- OnAfterAction(args);
- return true;
- }
- catch (FatalActionException e)
- {
- // handle error
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment