From b50ea1e59299fde9d8462a3a442079effcf5b002 Mon Sep 17 00:00:00 2001 From: Francesca Faerman Date: Wed, 25 Mar 2020 13:48:42 -0400 Subject: [PATCH] Added GetDataRowCountCommand, fixed RunTask bug --- .../Automation/Commands/GetDataRowCommand.cs | 2 +- .../Commands/GetDataRowCountCommand.cs | 89 +++++++++++++++++++ .../Commands/GetDataRowValueCommand.cs | 2 +- .../Automation/Commands/RunTaskCommand.cs | 31 ++++++- .../Core/Automation/Commands/ScriptCommand.cs | 1 + taskt/UI/CustomControls/CustomControls.cs | 1 + taskt/taskt.csproj | 1 + 7 files changed, 122 insertions(+), 5 deletions(-) create mode 100644 taskt/Core/Automation/Commands/GetDataRowCountCommand.cs diff --git a/taskt/Core/Automation/Commands/GetDataRowCommand.cs b/taskt/Core/Automation/Commands/GetDataRowCommand.cs index b56d2576e..8eb96a081 100644 --- a/taskt/Core/Automation/Commands/GetDataRowCommand.cs +++ b/taskt/Core/Automation/Commands/GetDataRowCommand.cs @@ -11,7 +11,7 @@ namespace taskt.Core.Automation.Commands { [Serializable] [Attributes.ClassAttributes.Group("DataTable Commands")] - [Attributes.ClassAttributes.Description("This command allows you to add a datarow to a DataTable")] + [Attributes.ClassAttributes.Description("This command allows you to get the DataRow count from a DataTable")] [Attributes.ClassAttributes.UsesDescription("Use this command when you want to add a datarow to a DataTable.")] [Attributes.ClassAttributes.ImplementationDescription("")] public class GetDataRowCommand : ScriptCommand diff --git a/taskt/Core/Automation/Commands/GetDataRowCountCommand.cs b/taskt/Core/Automation/Commands/GetDataRowCountCommand.cs new file mode 100644 index 000000000..d765fabb1 --- /dev/null +++ b/taskt/Core/Automation/Commands/GetDataRowCountCommand.cs @@ -0,0 +1,89 @@ +using System; +using System.Linq; +using System.Xml.Serialization; +using System.Data; +using System.Windows.Forms; +using System.Collections.Generic; +using taskt.UI.Forms; +using taskt.UI.CustomControls; + +namespace taskt.Core.Automation.Commands +{ + [Serializable] + [Attributes.ClassAttributes.Group("DataTable Commands")] + [Attributes.ClassAttributes.Description("This command allows you to add a datarow to a DataTable")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to add a datarow to a DataTable.")] + [Attributes.ClassAttributes.ImplementationDescription("")] + public class GetDataRowCountCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please indicate the DataTable Name")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter a existing DataTable to add rows to.")] + [Attributes.PropertyAttributes.SampleUsage("**myData**")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_DataTableName { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Assign to Variable")] + [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_UserVariableName { get; set; } + + public GetDataRowCountCommand() + { + this.CommandName = "GetDataRowCountCommand"; + this.SelectionName = "Get DataRow Count"; + this.CommandEnabled = true; + this.CustomRendering = true; + + } + + public override void RunCommand(object sender) + { + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + var dataSetVariable = LookupVariable(engine); + DataTable dataTable = (DataTable)dataSetVariable.VariableValue; + + var count = dataTable.Rows.Count.ToString(); + + count.StoreInUserVariable(sender, v_UserVariableName); + + } + private Script.ScriptVariable LookupVariable(Core.Automation.Engine.AutomationEngineInstance sendingInstance) + { + //search for the variable + var requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == v_DataTableName).FirstOrDefault(); + + //if variable was not found but it starts with variable naming pattern + if ((requiredVariable == null) && (v_DataTableName.StartsWith(sendingInstance.engineSettings.VariableStartMarker)) && (v_DataTableName.EndsWith(sendingInstance.engineSettings.VariableEndMarker))) + { + //reformat and attempt + var reformattedVariable = v_DataTableName.Replace(sendingInstance.engineSettings.VariableStartMarker, "").Replace(sendingInstance.engineSettings.VariableEndMarker, ""); + requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == reformattedVariable).FirstOrDefault(); + } + + return requiredVariable; + } + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DataTableName", this, editor)); + RenderedControls.Add(CommandControls.CreateDefaultLabelFor("v_UserVariableName", this)); + var VariableNameControl = CommandControls.CreateStandardComboboxFor("v_UserVariableName", this).AddVariableNames(editor); + RenderedControls.AddRange(CommandControls.CreateUIHelpersFor("v_UserVariableName", this, new Control[] { VariableNameControl }, editor)); + RenderedControls.Add(VariableNameControl); + + return RenderedControls; + } + + + + public override string GetDisplayValue() + { + return base.GetDisplayValue() + $" [From '{v_DataTableName}', Store In: '{v_UserVariableName}']"; + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/GetDataRowValueCommand.cs b/taskt/Core/Automation/Commands/GetDataRowValueCommand.cs index e98aba085..4deef8099 100644 --- a/taskt/Core/Automation/Commands/GetDataRowValueCommand.cs +++ b/taskt/Core/Automation/Commands/GetDataRowValueCommand.cs @@ -11,7 +11,7 @@ namespace taskt.Core.Automation.Commands { [Serializable] [Attributes.ClassAttributes.Group("DataTable Commands")] - [Attributes.ClassAttributes.Description("This command allows you to add a datarow to a DataTable")] + [Attributes.ClassAttributes.Description("This command allows you to get a DataRow Value from a DataTable")] [Attributes.ClassAttributes.UsesDescription("Use this command when you want to add a datarow to a DataTable.")] [Attributes.ClassAttributes.ImplementationDescription("")] public class GetDataRowValueCommand : ScriptCommand diff --git a/taskt/Core/Automation/Commands/RunTaskCommand.cs b/taskt/Core/Automation/Commands/RunTaskCommand.cs index e0a5c8950..235d6a68e 100644 --- a/taskt/Core/Automation/Commands/RunTaskCommand.cs +++ b/taskt/Core/Automation/Commands/RunTaskCommand.cs @@ -72,6 +72,7 @@ public RunTaskCommand() public override void RunCommand(object sender) { + Core.Automation.Engine.AutomationEngineInstance currentScriptEngine = (Core.Automation.Engine.AutomationEngineInstance)sender; var startFile = v_taskPath.ConvertToUserVariable(sender); //create variable list @@ -80,8 +81,16 @@ public override void RunCommand(object sender) foreach (DataRow rw in v_VariableAssignments.Rows) { - var variableName = (string)rw.ItemArray[0]; - var variableValue = ((string)rw.ItemArray[1]).ConvertToUserVariable(sender); + var variableName = (string)rw.ItemArray[0]; + object variableValue; + try + { + variableValue = LookupVariable(currentScriptEngine, (string)rw.ItemArray[1]).VariableValue; + } + catch(Exception ex) + { + variableValue = ((string)rw.ItemArray[1]).ConvertToUserVariable(sender); + } var variableReturn = (string)rw.ItemArray[2]; variableList.Add(new Script.ScriptVariable { @@ -101,7 +110,7 @@ public override void RunCommand(object sender) UI.Forms.frmScriptEngine newEngine = new UI.Forms.frmScriptEngine(startFile, null, variableList, true); - Core.Automation.Engine.AutomationEngineInstance currentScriptEngine = (Core.Automation.Engine.AutomationEngineInstance) sender; + //Core.Automation.Engine.AutomationEngineInstance currentScriptEngine = (Core.Automation.Engine.AutomationEngineInstance) sender; currentScriptEngine.tasktEngineUI.Invoke((Action)delegate () { currentScriptEngine.tasktEngineUI.TopMost = false; }); Application.Run(newEngine); @@ -128,6 +137,22 @@ public override void RunCommand(object sender) //currentScriptEngine.tasktEngineUI.TopMost = false; currentScriptEngine.tasktEngineUI.Invoke((Action)delegate () { currentScriptEngine.tasktEngineUI.TopMost = true; }); + } + + private Script.ScriptVariable LookupVariable(Core.Automation.Engine.AutomationEngineInstance sendingInstance, string lookupVariable ) + { + //search for the variable + var requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == lookupVariable).FirstOrDefault(); + + //if variable was not found but it starts with variable naming pattern + if ((requiredVariable == null) && (lookupVariable.StartsWith(sendingInstance.engineSettings.VariableStartMarker)) && (lookupVariable.EndsWith(sendingInstance.engineSettings.VariableEndMarker))) + { + //reformat and attempt + var reformattedVariable = lookupVariable.Replace(sendingInstance.engineSettings.VariableStartMarker, "").Replace(sendingInstance.engineSettings.VariableEndMarker, ""); + requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == reformattedVariable).FirstOrDefault(); + } + + return requiredVariable; } public override List Render(frmCommandEditor editor) diff --git a/taskt/Core/Automation/Commands/ScriptCommand.cs b/taskt/Core/Automation/Commands/ScriptCommand.cs index c704bd7a2..7f181de73 100644 --- a/taskt/Core/Automation/Commands/ScriptCommand.cs +++ b/taskt/Core/Automation/Commands/ScriptCommand.cs @@ -30,6 +30,7 @@ namespace taskt.Core.Automation.Commands [XmlInclude(typeof(AddDataRowCommand))] [XmlInclude(typeof(GetDataRowCommand))] [XmlInclude(typeof(GetDataRowValueCommand))] + [XmlInclude(typeof(GetDataRowCountCommand))] [XmlInclude(typeof(RemoveDataRowCommand))] [XmlInclude(typeof(ThickAppClickItemCommand))] [XmlInclude(typeof(ThickAppGetTextCommand))] diff --git a/taskt/UI/CustomControls/CustomControls.cs b/taskt/UI/CustomControls/CustomControls.cs index 3821472af..ac95a2049 100644 --- a/taskt/UI/CustomControls/CustomControls.cs +++ b/taskt/UI/CustomControls/CustomControls.cs @@ -489,6 +489,7 @@ public static Dictionary UIImageDictionary() uiImages.Add("AddDataRowCommand", taskt.Properties.Resources.command_spreadsheet); uiImages.Add("GetDataRowCommand", taskt.Properties.Resources.command_spreadsheet); uiImages.Add("GetDataRowValueCommand", taskt.Properties.Resources.command_spreadsheet); + uiImages.Add("GetDataRowCountCommand", taskt.Properties.Resources.command_spreadsheet); uiImages.Add("CreateDataTableCommand", taskt.Properties.Resources.command_spreadsheet); uiImages.Add("FilterDataTableCommand", taskt.Properties.Resources.command_spreadsheet); uiImages.Add("RemoveDataRowCommand", taskt.Properties.Resources.command_spreadsheet); diff --git a/taskt/taskt.csproj b/taskt/taskt.csproj index e104856c1..52f9cea27 100644 --- a/taskt/taskt.csproj +++ b/taskt/taskt.csproj @@ -177,6 +177,7 @@ +