forked from saucepleez/taskt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Try/Catch/Finally/End Try Commands saucepleez#138
- Loading branch information
1 parent
6679cc8
commit f6dce5e
Showing
14 changed files
with
423 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Windows.Forms; | ||
using taskt.UI.CustomControls; | ||
using taskt.UI.Forms; | ||
|
||
namespace taskt.Core.Automation.Commands | ||
{ | ||
[Serializable] | ||
[Attributes.ClassAttributes.Group("Error Handling Commands")] | ||
[Attributes.ClassAttributes.Description("This command allows you to define actions that should occur after encountering an error.")] | ||
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to define how your script should behave when an error is encountered.")] | ||
[Attributes.ClassAttributes.ImplementationDescription("")] | ||
public class CatchExceptionCommand : ScriptCommand | ||
{ | ||
public string ErrorMessage { get; set; } | ||
public string StackTrace { get; set; } | ||
|
||
public CatchExceptionCommand() | ||
{ | ||
this.CommandName = "CatchExceptionCommand"; | ||
this.SelectionName = "Catch Exception"; | ||
this.CommandEnabled = true; | ||
this.CustomRendering = true; | ||
} | ||
public override void RunCommand(object sender) | ||
{ | ||
//no execution required, used as a marker by the Automation Engine | ||
} | ||
public override List<Control> Render(frmCommandEditor editor) | ||
{ | ||
base.Render(editor); | ||
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_Comment", this, editor)); | ||
return RenderedControls; | ||
} | ||
public override string GetDisplayValue() | ||
{ | ||
return base.GetDisplayValue(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Windows.Forms; | ||
using System.Xml.Serialization; | ||
using taskt.UI.CustomControls; | ||
using taskt.UI.Forms; | ||
|
||
namespace taskt.Core.Automation.Commands | ||
{ | ||
[Serializable] | ||
[Attributes.ClassAttributes.Group("Error Handling Commands")] | ||
[Attributes.ClassAttributes.Description("This command specifies the end of a try/catch block.")] | ||
[Attributes.ClassAttributes.UsesDescription("Use this command to enclose your try/catch block.")] | ||
[Attributes.ClassAttributes.ImplementationDescription("")] | ||
public class EndTryCommand : ScriptCommand | ||
{ | ||
public EndTryCommand() | ||
{ | ||
this.CommandName = "EndTryCommand"; | ||
this.SelectionName = "End Try"; | ||
this.CommandEnabled = true; | ||
this.CustomRendering = true; | ||
} | ||
public override void RunCommand(object sender) | ||
{ | ||
//no execution required, used as a marker by the Automation Engine | ||
} | ||
public override List<Control> Render(frmCommandEditor editor) | ||
{ | ||
base.Render(editor); | ||
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_Comment", this, editor)); | ||
return RenderedControls; | ||
} | ||
public override string GetDisplayValue() | ||
{ | ||
return base.GetDisplayValue(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Windows.Forms; | ||
using System.Xml.Serialization; | ||
using taskt.Core.Automation.Engine; | ||
using taskt.UI.CustomControls; | ||
using taskt.UI.Forms; | ||
|
||
namespace taskt.Core.Automation.Commands | ||
{ | ||
[Serializable] | ||
[Attributes.ClassAttributes.Group("Error Handling Commands")] | ||
[Attributes.ClassAttributes.Description("This command specifies execution that should occur whether or not an error occured")] | ||
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to always execute a specific command before leaving the try/catch block")] | ||
[Attributes.ClassAttributes.ImplementationDescription("")] | ||
public class FinallyCommand : ScriptCommand | ||
{ | ||
public FinallyCommand() | ||
{ | ||
this.CommandName = "FinallyCommand"; | ||
this.SelectionName = "Finally"; | ||
this.CommandEnabled = true; | ||
this.CustomRendering = true; | ||
} | ||
public override void RunCommand(object sender, Script.ScriptAction parentCommand) | ||
{ | ||
//no execution required, used as a marker by the Automation Engine | ||
} | ||
public override List<Control> Render(frmCommandEditor editor) | ||
{ | ||
base.Render(editor); | ||
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_Comment", this, editor)); | ||
return RenderedControls; | ||
} | ||
public override string GetDisplayValue() | ||
{ | ||
return base.GetDisplayValue(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Windows.Forms; | ||
using System.Xml.Serialization; | ||
using taskt.Core.Automation.Engine; | ||
using taskt.UI.CustomControls; | ||
using taskt.UI.Forms; | ||
|
||
namespace taskt.Core.Automation.Commands | ||
{ | ||
[Serializable] | ||
[Attributes.ClassAttributes.Group("Error Handling Commands")] | ||
[Attributes.ClassAttributes.Description("This command allows embedding commands and will automatically move to the 'catch' handler")] | ||
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to handle potential errors that could occur.")] | ||
[Attributes.ClassAttributes.ImplementationDescription("")] | ||
public class TryCommand : ScriptCommand | ||
{ | ||
public TryCommand() | ||
{ | ||
this.CommandName = "TryCommand"; | ||
this.SelectionName = "Try"; | ||
this.CommandEnabled = true; | ||
this.CustomRendering = true; | ||
} | ||
|
||
public override void RunCommand(object sender, Script.ScriptAction parentCommand) | ||
{ | ||
//get engine | ||
var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; | ||
|
||
//get indexes of commands | ||
var startIndex = 0; | ||
var catchIndex = parentCommand.AdditionalScriptCommands.FindIndex(a => a.ScriptCommand is CatchExceptionCommand); | ||
var finallyIndex = parentCommand.AdditionalScriptCommands.FindIndex(a => a.ScriptCommand is FinallyCommand); | ||
var endTryIndex = parentCommand.AdditionalScriptCommands.FindIndex(a => a.ScriptCommand is EndTryCommand); | ||
|
||
var lineNumber = 0; | ||
for (int i = startIndex; i < catchIndex; i++) | ||
{ | ||
if ((engine.IsCancellationPending) || (engine.CurrentLoopCancelled)) | ||
return; | ||
try | ||
{ | ||
Script.ScriptAction cmd = parentCommand.AdditionalScriptCommands[i]; | ||
lineNumber = cmd.ScriptCommand.LineNumber; | ||
engine.ExecuteCommand(cmd); | ||
} | ||
catch (Exception ex) | ||
{ | ||
//error occured so start processing from catch index onwards | ||
var catchCommandItem = parentCommand.AdditionalScriptCommands[catchIndex]; | ||
var catchCommand = (CatchExceptionCommand)catchCommandItem.ScriptCommand; | ||
|
||
catchCommand.StackTrace = ex.ToString(); | ||
catchCommand.ErrorMessage = ex.Message; | ||
engine.AddVariable("Catch:StackTrace", catchCommand.StackTrace); | ||
engine.AddVariable("Catch:ErrorMessage", catchCommand.ErrorMessage); | ||
|
||
//assify = (input >= 0) ? "nonnegative" : "negative"; | ||
var endCatch = (finallyIndex != -1) ? finallyIndex : endTryIndex; | ||
|
||
for (int j = catchIndex; j < endCatch; j++) | ||
{ | ||
engine.ExecuteCommand(parentCommand.AdditionalScriptCommands[j]); | ||
} | ||
|
||
} | ||
|
||
} | ||
//handle finally block if exists | ||
if (finallyIndex != -1) | ||
{ | ||
for (int k = finallyIndex; k < endTryIndex; k++) | ||
{ | ||
engine.ExecuteCommand(parentCommand.AdditionalScriptCommands[k]); | ||
} | ||
} | ||
} | ||
public override List<Control> Render(frmCommandEditor editor) | ||
{ | ||
base.Render(editor); | ||
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_Comment", this, editor)); | ||
return RenderedControls; | ||
} | ||
public override string GetDisplayValue() | ||
{ | ||
return base.GetDisplayValue(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.