Skip to content

Commit

Permalink
Added GetDataRowCountCommand, fixed RunTask bug
Browse files Browse the repository at this point in the history
  • Loading branch information
openbots-ff committed Mar 25, 2020
1 parent 7ff1808 commit b50ea1e
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 5 deletions.
2 changes: 1 addition & 1 deletion taskt/Core/Automation/Commands/GetDataRowCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
89 changes: 89 additions & 0 deletions taskt/Core/Automation/Commands/GetDataRowCountCommand.cs
Original file line number Diff line number Diff line change
@@ -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<Control> 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}']";
}
}
}
2 changes: 1 addition & 1 deletion taskt/Core/Automation/Commands/GetDataRowValueCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 28 additions & 3 deletions taskt/Core/Automation/Commands/RunTaskCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
{
Expand All @@ -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);

Expand All @@ -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<Control> Render(frmCommandEditor editor)
Expand Down
1 change: 1 addition & 0 deletions taskt/Core/Automation/Commands/ScriptCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down
1 change: 1 addition & 0 deletions taskt/UI/CustomControls/CustomControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ public static class Images
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);
Expand Down
1 change: 1 addition & 0 deletions taskt/taskt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
<Compile Include="Core\Automation\Commands\ExcelSplitRangeByColumnCommand.cs" />
<Compile Include="Core\Automation\Commands\ExtractFileCommand.cs" />
<Compile Include="Core\Automation\Commands\GetDataRowCommand.cs" />
<Compile Include="Core\Automation\Commands\GetDataRowCountCommand.cs" />
<Compile Include="Core\Automation\Commands\GetDataRowValueCommand.cs" />
<Compile Include="Core\Automation\Commands\GetFilesCommand.cs" />
<Compile Include="Core\Automation\Commands\GetFoldersCommand.cs" />
Expand Down

0 comments on commit b50ea1e

Please sign in to comment.