Skip to content

Commit fbf5a24

Browse files
authored
Merge pull request #1 from saucepleez/development-branch
Update fork to origin
2 parents eb0b2e9 + c3e7173 commit fbf5a24

31 files changed

+1307
-193
lines changed

taskt/Core/ApplicationSettings.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public class EngineSettings
122122
public bool OverrideExistingAppInstances { get; set; }
123123
public bool AutoCloseMessagesOnServerExecution { get; set; }
124124
public bool AutoCloseDebugWindowOnServerExecution { get; set; }
125-
125+
public bool AutoCalcVariables { get; set; }
126126
public EngineSettings()
127127
{
128128
ShowDebugWindow = true;
@@ -131,13 +131,14 @@ public EngineSettings()
131131
ShowAdvancedDebugOutput = false;
132132
CreateMissingVariablesDuringExecution = true;
133133
TrackExecutionMetrics = true;
134-
VariableStartMarker = "[";
135-
VariableEndMarker = "]";
134+
VariableStartMarker = "{";
135+
VariableEndMarker = "}";
136136
CancellationKey = System.Windows.Forms.Keys.Pause;
137137
DelayBetweenCommands = 250;
138138
OverrideExistingAppInstances = false;
139139
AutoCloseMessagesOnServerExecution = true;
140140
AutoCloseDebugWindowOnServerExecution = true;
141+
AutoCalcVariables = true;
141142
}
142143
}
143144
/// <summary>

taskt/Core/Automation/Commands/AddDataRowCommand.cs

+71-18
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,55 @@ public class AddDataRowCommand : ScriptCommand
2222
[Attributes.PropertyAttributes.SampleUsage("**myData**")]
2323
[Attributes.PropertyAttributes.Remarks("")]
2424
public string v_DataTableName { get; set; }
25-
[XmlAttribute]
26-
[Attributes.PropertyAttributes.PropertyDescription("Please input the data you want entered.")]
27-
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
28-
[Attributes.PropertyAttributes.InputSpecification("Enter a string of comma seperated values.")]
29-
[Attributes.PropertyAttributes.SampleUsage("name1,name2,name3,name4")]
25+
26+
[XmlElement]
27+
[Attributes.PropertyAttributes.PropertyDescription("Define Data")]
28+
[Attributes.PropertyAttributes.InputSpecification("Enter the Column Names required for each column of data")]
29+
[Attributes.PropertyAttributes.SampleUsage("")]
3030
[Attributes.PropertyAttributes.Remarks("")]
31-
public string v_InputData { get; set; }
31+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
32+
public DataTable v_AddDataDataTable { get; set; }
33+
34+
35+
[XmlIgnore]
36+
[NonSerialized]
37+
private List<CreateDataTableCommand> DataTableCreationCommands;
3238

3339
public AddDataRowCommand()
3440
{
3541
this.CommandName = "AddDataRowCommand";
3642
this.SelectionName = "Add DataRow";
3743
this.CommandEnabled = true;
3844
this.CustomRendering = true;
45+
46+
//initialize data table
47+
this.v_AddDataDataTable = new System.Data.DataTable
48+
{
49+
TableName = "AddDataDataTable" + DateTime.Now.ToString("MMddyy.hhmmss")
50+
};
51+
52+
this.v_AddDataDataTable.Columns.Add("Column Name");
53+
this.v_AddDataDataTable.Columns.Add("Data");
54+
3955
}
4056

4157
public override void RunCommand(object sender)
4258
{
4359
var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;
4460
var dataSetVariable = LookupVariable(engine);
45-
var vInputData = v_InputData.ConvertToUserVariable(engine);
61+
4662
DataTable Dt = (DataTable)dataSetVariable.VariableValue;
47-
vInputData = vInputData.Trim('\\', '"', '/');
48-
var splittext = vInputData.Split(',');
63+
var newRow = Dt.NewRow();
4964

50-
int i = 0;
51-
foreach (string str in splittext)
65+
foreach (DataRow rw in v_AddDataDataTable.Rows)
5266
{
53-
splittext[i] = str.Trim('\\', '"', '[', ']');
54-
if (splittext[i] == null)
55-
splittext[i] = string.Empty;
56-
i++;
67+
var columnName = rw.Field<string>("Column Name").ConvertToUserVariable(sender);
68+
var data = rw.Field<string>("Data").ConvertToUserVariable(sender);
69+
newRow.SetField(columnName, data);
5770
}
5871

59-
Dt.Rows.Add(splittext.ToArray());
72+
Dt.Rows.Add(newRow);
73+
6074
dataSetVariable.VariableValue = Dt;
6175
}
6276
private Script.ScriptVariable LookupVariable(Core.Automation.Engine.AutomationEngineInstance sendingInstance)
@@ -79,15 +93,54 @@ public override List<Control> Render(frmCommandEditor editor)
7993
base.Render(editor);
8094

8195
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DataTableName", this, editor));
82-
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InputData", this, editor));
96+
97+
98+
RenderedControls.AddRange(CommandControls.CreateDataGridViewGroupFor("v_AddDataDataTable", this, editor));
99+
100+
taskt.UI.CustomControls.CommandItemControl loadSchemaControl = new taskt.UI.CustomControls.CommandItemControl();
101+
loadSchemaControl.ForeColor = System.Drawing.Color.White;
102+
loadSchemaControl.CommandDisplay = "Load Column Names From Existing Table";
103+
loadSchemaControl.Click += LoadSchemaControl_Click;
104+
RenderedControls.Add(loadSchemaControl);
105+
106+
DataTableCreationCommands = editor.configuredCommands.Where(f => f is CreateDataTableCommand).Select(f => (CreateDataTableCommand)f).ToList();
107+
108+
83109

84110

85111
return RenderedControls;
86112
}
87113

114+
private void LoadSchemaControl_Click(object sender, EventArgs e)
115+
{
116+
UI.Forms.Supplemental.frmItemSelector selectionForm = new UI.Forms.Supplemental.frmItemSelector();
117+
selectionForm.Text = "Load Schema";
118+
selectionForm.lblHeader.Text = "Select a table from the list";
119+
foreach (var item in DataTableCreationCommands)
120+
{
121+
selectionForm.lstVariables.Items.Add(item.v_DataTableName);
122+
}
123+
124+
var result = selectionForm.ShowDialog();
125+
126+
if (result == DialogResult.OK)
127+
{
128+
var tableName = selectionForm.lstVariables.SelectedItem.ToString();
129+
var schema = DataTableCreationCommands.Where(f => f.v_DataTableName == tableName).FirstOrDefault();
130+
131+
v_AddDataDataTable.Rows.Clear();
132+
133+
foreach (DataRow rw in schema.v_ColumnNameDataTable.Rows)
134+
{
135+
v_AddDataDataTable.Rows.Add(rw.Field<string>("Column Name"), "");
136+
}
137+
138+
}
139+
}
140+
88141
public override string GetDisplayValue()
89142
{
90-
return base.GetDisplayValue() + " [Add Datarow: " + v_InputData + " to DataTable: " + v_DataTableName + " ]";
143+
return base.GetDisplayValue() + $" [{v_AddDataDataTable.Rows.Count} Fields, apply to '{v_DataTableName}']";
91144
}
92145
}
93146
}

taskt/Core/Automation/Commands/CreateDataTableCommand.cs

+45-19
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using System.Windows.Forms;
66
using taskt.UI.Forms;
77
using taskt.UI.CustomControls;
8+
using System.Drawing;
9+
using System.Linq;
810

911
namespace taskt.Core.Automation.Commands
1012
{
@@ -16,64 +18,88 @@ namespace taskt.Core.Automation.Commands
1618
public class CreateDataTableCommand : ScriptCommand
1719
{
1820
[XmlAttribute]
19-
[Attributes.PropertyAttributes.PropertyDescription("Please create a DataTable name")]
21+
[Attributes.PropertyAttributes.PropertyDescription("Please Indicate DataTable Name")]
2022
[Attributes.PropertyAttributes.InputSpecification("Indicate a unique reference name for later use")]
2123
[Attributes.PropertyAttributes.SampleUsage("vMyDatatable")]
2224
[Attributes.PropertyAttributes.Remarks("")]
2325
public string v_DataTableName { get; set; }
2426

25-
[XmlAttribute]
26-
[Attributes.PropertyAttributes.PropertyDescription("Please indicate the names of your columns")]
27-
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
28-
[Attributes.PropertyAttributes.InputSpecification("Enter the actual names of your columns.")]
29-
[Attributes.PropertyAttributes.SampleUsage("name1,name2,name3,name4")]
27+
[XmlElement]
28+
[Attributes.PropertyAttributes.PropertyDescription("Define Column Names")]
29+
[Attributes.PropertyAttributes.InputSpecification("Enter the Column Names required for each column of data")]
30+
[Attributes.PropertyAttributes.SampleUsage("")]
3031
[Attributes.PropertyAttributes.Remarks("")]
31-
public string v_DataTableColumnNames { get; set; }
32+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
33+
public DataTable v_ColumnNameDataTable { get; set; }
34+
3235

3336
public CreateDataTableCommand()
3437
{
3538
this.CommandName = "CreateDataTableCommand";
3639
this.SelectionName = "Create DataTable";
3740
this.CommandEnabled = true;
3841
this.CustomRendering = true;
42+
43+
//initialize data table
44+
this.v_ColumnNameDataTable = new System.Data.DataTable
45+
{
46+
TableName = "ColumnNamesDataTable" + DateTime.Now.ToString("MMddyy.hhmmss")
47+
};
48+
49+
this.v_ColumnNameDataTable.Columns.Add("Column Name");
50+
51+
3952
}
4053

4154
public override void RunCommand(object sender)
4255
{
4356
var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;
44-
var vDataTableColumnNames = v_DataTableColumnNames.ConvertToUserVariable(sender);
57+
var dataTableName = v_DataTableName.ConvertToUserVariable(sender);
4558

46-
var splittext = vDataTableColumnNames.Split(',');
4759
DataTable Dt = new DataTable();
4860

49-
foreach(var item in splittext)
61+
foreach(DataRow rwColumnName in v_ColumnNameDataTable.Rows)
5062
{
51-
Dt.Columns.Add(item);
63+
Dt.Columns.Add(rwColumnName.Field<string>("Column Name"));
5264
}
5365

54-
Script.ScriptVariable newDataTable = new Script.ScriptVariable
66+
67+
68+
69+
//add or override existing variable
70+
if (engine.VariableList.Any(f => f.VariableName == dataTableName))
5571
{
56-
VariableName = v_DataTableName,
57-
VariableValue = Dt
58-
};
72+
var selectedVariable = engine.VariableList.Where(f => f.VariableName == dataTableName).FirstOrDefault();
73+
selectedVariable.VariableValue = Dt;
74+
}
75+
else
76+
{
77+
Script.ScriptVariable newDataTable = new Script.ScriptVariable
78+
{
79+
VariableName = dataTableName,
80+
VariableValue = Dt
81+
};
5982

60-
engine.VariableList.Add(newDataTable);
83+
engine.VariableList.Add(newDataTable);
84+
}
85+
86+
87+
6188
}
6289
public override List<Control> Render(frmCommandEditor editor)
6390
{
6491
base.Render(editor);
6592

6693
//create standard group controls
6794
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DataTableName", this, editor));
68-
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DataTableColumnNames", this, editor));
69-
95+
RenderedControls.AddRange(CommandControls.CreateDataGridViewGroupFor("v_ColumnNameDataTable", this, editor));
7096
return RenderedControls;
7197

7298
}
7399

74100
public override string GetDisplayValue()
75101
{
76-
return base.GetDisplayValue()+ "[Create DataTable with name: "+ v_DataTableName +"]";
102+
return base.GetDisplayValue() + $" [Name: '{v_DataTableName}' with {v_ColumnNameDataTable.Rows.Count} Columns]";
77103
}
78104
}
79105
}

0 commit comments

Comments
 (0)