-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Automatic Calculation Customization Options and Engine Preferen…
…ces #176
- Loading branch information
1 parent
bd1b01d
commit 8994950
Showing
11 changed files
with
302 additions
and
68 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
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,89 @@ | ||
using System; | ||
using System.Xml.Serialization; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
using System.Windows.Forms; | ||
using taskt.UI.Forms; | ||
using taskt.UI.CustomControls; | ||
using System.Data; | ||
|
||
namespace taskt.Core.Automation.Commands | ||
{ | ||
[Serializable] | ||
[Attributes.ClassAttributes.Group("Data Commands")] | ||
[Attributes.ClassAttributes.Description("This command allows you to perform a math calculation and apply it to a variable.")] | ||
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to perform a math calculation.")] | ||
[Attributes.ClassAttributes.ImplementationDescription("")] | ||
public class MathCalculationCommand : ScriptCommand | ||
{ | ||
[XmlAttribute] | ||
[Attributes.PropertyAttributes.PropertyDescription("Please supply the input to be computed (ex. (2 + 1)")] | ||
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] | ||
[Attributes.PropertyAttributes.InputSpecification("Specify either text or a variable that contains valid math.")] | ||
[Attributes.PropertyAttributes.SampleUsage("")] | ||
[Attributes.PropertyAttributes.Remarks("You can use known numbers or variables.")] | ||
public string v_InputValue { get; set; } | ||
|
||
|
||
[XmlAttribute] | ||
[Attributes.PropertyAttributes.PropertyDescription("Please select the variable to receive the math calculation")] | ||
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] | ||
[Attributes.PropertyAttributes.InputSpecification("Select or provide a variable from the variable list")] | ||
[Attributes.PropertyAttributes.SampleUsage("**vSomeVariable**")] | ||
[Attributes.PropertyAttributes.Remarks("If you have enabled the setting **Create Missing Variables at Runtime** then you are not required to pre-define your variables, however, it is highly recommended.")] | ||
public string v_applyToVariableName { get; set; } | ||
|
||
public MathCalculationCommand() | ||
{ | ||
this.CommandName = "MathCalculationCommand"; | ||
this.SelectionName = "Math Calculation"; | ||
this.CommandEnabled = true; | ||
this.CustomRendering = true; | ||
|
||
this.v_InputValue = "(2 + 5) * 3"; | ||
|
||
} | ||
|
||
public override void RunCommand(object sender) | ||
{ | ||
//get variablized string | ||
var variableMath = v_InputValue.ConvertToUserVariable(sender); | ||
|
||
try | ||
{ | ||
//perform compute | ||
DataTable dt = new DataTable(); | ||
var result = dt.Compute(variableMath, ""); | ||
|
||
//store string in variable | ||
result.ToString().StoreInUserVariable(sender, v_applyToVariableName); | ||
} | ||
catch (Exception ex) | ||
{ | ||
//throw exception is math calc failed | ||
throw ex; | ||
} | ||
} | ||
public override List<Control> Render(frmCommandEditor editor) | ||
{ | ||
base.Render(editor); | ||
|
||
//create standard group controls | ||
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InputValue", this, editor)); | ||
|
||
RenderedControls.Add(CommandControls.CreateDefaultLabelFor("v_applyToVariableName", this)); | ||
var VariableNameControl = CommandControls.CreateStandardComboboxFor("v_applyToVariableName", this).AddVariableNames(editor); | ||
RenderedControls.AddRange(CommandControls.CreateUIHelpersFor("v_applyToVariableName", this, new Control[] { VariableNameControl }, editor)); | ||
RenderedControls.Add(VariableNameControl); | ||
|
||
|
||
return RenderedControls; | ||
|
||
} | ||
|
||
public override string GetDisplayValue() | ||
{ | ||
return base.GetDisplayValue() + $" [Apply Calculation Result to '{v_applyToVariableName}']"; | ||
} | ||
} | ||
} |
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
67 changes: 67 additions & 0 deletions
67
taskt/Core/Automation/Commands/SetEnginePreferenceCommand.cs
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,67 @@ | ||
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("Engine Commands")] | ||
[Attributes.ClassAttributes.Description("This command allows you to set preferences for engine behavior.")] | ||
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to change the engine behavior.")] | ||
[Attributes.ClassAttributes.ImplementationDescription("")] | ||
public class SetEnginePreferenceCommand : ScriptCommand | ||
{ | ||
[XmlAttribute] | ||
[Attributes.PropertyAttributes.PropertyDescription("Select Parameter Type")] | ||
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] | ||
[Attributes.PropertyAttributes.PropertyUISelectionOption("Enable Automatic Calculations")] | ||
[Attributes.PropertyAttributes.PropertyUISelectionOption("Disable Automatic Calculations")] | ||
[Attributes.PropertyAttributes.InputSpecification("")] | ||
[Attributes.PropertyAttributes.Remarks("")] | ||
public string v_PreferenceType { get; set; } | ||
|
||
public SetEnginePreferenceCommand() | ||
{ | ||
this.CommandName = "SetEnginePreferenceCommand"; | ||
this.SelectionName = "Set Engine Preference"; | ||
this.CommandEnabled = true; | ||
this.CustomRendering = true; | ||
|
||
} | ||
public override void RunCommand(object sender) | ||
{ | ||
var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; | ||
|
||
var preference = v_PreferenceType.ConvertToUserVariable(sender); | ||
|
||
switch (preference) | ||
{ | ||
case "Enable Automatic Calculations": | ||
engine.AutoCalculateVariables = true; | ||
break; | ||
case "Disable Automatic Calculations": | ||
engine.AutoCalculateVariables = false; | ||
break; | ||
default: | ||
throw new NotImplementedException($"The preference '{preference}' is not implemented."); | ||
} | ||
|
||
|
||
} | ||
public override List<Control> Render(frmCommandEditor editor) | ||
{ | ||
base.Render(editor); | ||
|
||
RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_PreferenceType", this, editor)); | ||
|
||
return RenderedControls; | ||
} | ||
public override string GetDisplayValue() | ||
{ | ||
return base.GetDisplayValue() + $" [{v_PreferenceType}]"; | ||
} | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
taskt/Sample Scripts/3.x Use Case Samples/Automatic Calculation Preference [3.4.0.0].xml
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,42 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Script xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | ||
<Commands> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="CommentCommand" CommandID="552bb9f0-b5a4-415b-8371-7189cf9d37c6" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="1" PauseBeforeExeucution="false" v_Comment="Sample Demonstrates Automatic Calculation Preferences" CommandEnabled="true" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="CommentCommand" CommandID="c19b5da1-a1a8-4383-aa19-5e107ee98b3e" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="2" PauseBeforeExeucution="false" v_Comment="Default Setting comes from: Settings > Engine > Calculate Variables Automatically" CommandEnabled="true" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="CommentCommand" CommandID="6cfd5535-4390-49b1-9f78-f84a7d8b3e77" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="3" PauseBeforeExeucution="false" v_Comment="Override and Enable Automatic Calculations" CommandEnabled="true" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="SetEnginePreferenceCommand" CommandID="d310dc06-8884-422e-a4d1-ff3748fdab2c" CommandName="SetEnginePreferenceCommand" IsCommented="false" SelectionName="Set Engine Preference" DefaultPause="0" LineNumber="4" PauseBeforeExeucution="false" CommandEnabled="true" v_PreferenceType="Enable Automatic Calculations" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="VariableCommand" CommandID="cbc24146-54ae-43e5-b2f7-51045a27773c" CommandName="VariableCommand" IsCommented="false" SelectionName="Set Variable" DefaultPause="0" LineNumber="5" PauseBeforeExeucution="false" CommandEnabled="true" v_userVariableName="vRes" v_Input="2+1" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="CommentCommand" CommandID="bc1375d2-2823-480f-965b-0e473a569287" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="6" PauseBeforeExeucution="false" v_Comment="Should Output 3" CommandEnabled="true" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="MessageBoxCommand" CommandID="f199fa4b-1870-4e9a-9ae9-0c9fd976c348" CommandName="MessageBoxCommand" IsCommented="false" SelectionName="Show Message" DefaultPause="0" LineNumber="7" PauseBeforeExeucution="false" CommandEnabled="true" v_Message="{vRes}" v_AutoCloseAfter="0" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="CommentCommand" CommandID="1a958572-7a5c-4989-af6d-2d94b50dfd6e" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="8" PauseBeforeExeucution="false" v_Comment="Override Disable Automatic Calculations" CommandEnabled="true" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="SetEnginePreferenceCommand" CommandID="cf12d8f8-1373-44fd-8783-f41c107678a1" CommandName="SetEnginePreferenceCommand" IsCommented="false" SelectionName="Set Engine Preference" DefaultPause="0" LineNumber="9" PauseBeforeExeucution="false" CommandEnabled="true" v_PreferenceType="Disable Automatic Calculations" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="VariableCommand" CommandID="53eb918c-7713-4422-ac65-f6d8ca4ab109" CommandName="VariableCommand" IsCommented="false" SelectionName="Set Variable" DefaultPause="0" LineNumber="10" PauseBeforeExeucution="false" CommandEnabled="true" v_userVariableName="vRes" v_Input="2+1" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="CommentCommand" CommandID="45107c6e-ecbd-437d-9a1f-fbb55f88d79a" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="11" PauseBeforeExeucution="false" v_Comment="Should Output '2+1'" CommandEnabled="true" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="MessageBoxCommand" CommandID="127e32e1-a496-4de2-97cd-5ffc2be3595d" CommandName="MessageBoxCommand" IsCommented="false" SelectionName="Show Message" DefaultPause="0" LineNumber="12" PauseBeforeExeucution="false" CommandEnabled="true" v_Message="{vRes}" v_AutoCloseAfter="0" /> | ||
</ScriptAction> | ||
</Commands> | ||
<Variables /> | ||
</Script> |
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
Oops, something went wrong.