Skip to content

Commit d97363f

Browse files
authored
Merge pull request #175 from mbhatti125/development-branch
New Excel, Dictionary and Datatable commands
2 parents 8994950 + eb0b2e9 commit d97363f

20 files changed

+1493
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using System;
2+
using System.Linq;
3+
using System.Xml.Serialization;
4+
using System.Data;
5+
using System.Windows.Forms;
6+
using System.Collections.Generic;
7+
using taskt.UI.Forms;
8+
using taskt.UI.CustomControls;
9+
10+
namespace taskt.Core.Automation.Commands
11+
{
12+
[Serializable]
13+
[Attributes.ClassAttributes.Group("DataTable Commands")]
14+
[Attributes.ClassAttributes.Description("This command allows you to add a datarow to a DataTable")]
15+
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to add a datarow to a DataTable.")]
16+
[Attributes.ClassAttributes.ImplementationDescription("")]
17+
public class AddDataRowCommand : ScriptCommand
18+
{
19+
[XmlAttribute]
20+
[Attributes.PropertyAttributes.PropertyDescription("Please indicate the DataTable Name")]
21+
[Attributes.PropertyAttributes.InputSpecification("Enter a existing DataTable to add rows to.")]
22+
[Attributes.PropertyAttributes.SampleUsage("**myData**")]
23+
[Attributes.PropertyAttributes.Remarks("")]
24+
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")]
30+
[Attributes.PropertyAttributes.Remarks("")]
31+
public string v_InputData { get; set; }
32+
33+
public AddDataRowCommand()
34+
{
35+
this.CommandName = "AddDataRowCommand";
36+
this.SelectionName = "Add DataRow";
37+
this.CommandEnabled = true;
38+
this.CustomRendering = true;
39+
}
40+
41+
public override void RunCommand(object sender)
42+
{
43+
var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;
44+
var dataSetVariable = LookupVariable(engine);
45+
var vInputData = v_InputData.ConvertToUserVariable(engine);
46+
DataTable Dt = (DataTable)dataSetVariable.VariableValue;
47+
vInputData = vInputData.Trim('\\', '"', '/');
48+
var splittext = vInputData.Split(',');
49+
50+
int i = 0;
51+
foreach (string str in splittext)
52+
{
53+
splittext[i] = str.Trim('\\', '"', '[', ']');
54+
if (splittext[i] == null)
55+
splittext[i] = string.Empty;
56+
i++;
57+
}
58+
59+
Dt.Rows.Add(splittext.ToArray());
60+
dataSetVariable.VariableValue = Dt;
61+
}
62+
private Script.ScriptVariable LookupVariable(Core.Automation.Engine.AutomationEngineInstance sendingInstance)
63+
{
64+
//search for the variable
65+
var requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == v_DataTableName).FirstOrDefault();
66+
67+
//if variable was not found but it starts with variable naming pattern
68+
if ((requiredVariable == null) && (v_DataTableName.StartsWith(sendingInstance.engineSettings.VariableStartMarker)) && (v_DataTableName.EndsWith(sendingInstance.engineSettings.VariableEndMarker)))
69+
{
70+
//reformat and attempt
71+
var reformattedVariable = v_DataTableName.Replace(sendingInstance.engineSettings.VariableStartMarker, "").Replace(sendingInstance.engineSettings.VariableEndMarker, "");
72+
requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == reformattedVariable).FirstOrDefault();
73+
}
74+
75+
return requiredVariable;
76+
}
77+
public override List<Control> Render(frmCommandEditor editor)
78+
{
79+
base.Render(editor);
80+
81+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DataTableName", this, editor));
82+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InputData", this, editor));
83+
84+
85+
return RenderedControls;
86+
}
87+
88+
public override string GetDisplayValue()
89+
{
90+
return base.GetDisplayValue() + " [Add Datarow: " + v_InputData + " to DataTable: " + v_DataTableName + " ]";
91+
}
92+
}
93+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System;
2+
using System.Xml.Serialization;
3+
using System.Data;
4+
using System.Collections.Generic;
5+
using System.Windows.Forms;
6+
using taskt.UI.Forms;
7+
using taskt.UI.CustomControls;
8+
9+
namespace taskt.Core.Automation.Commands
10+
{
11+
[Serializable]
12+
[Attributes.ClassAttributes.Group("DataTable Commands")]
13+
[Attributes.ClassAttributes.Description("This command created a DataTable with the column names provided")]
14+
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to create a new DataTable")]
15+
[Attributes.ClassAttributes.ImplementationDescription("")]
16+
public class CreateDataTableCommand : ScriptCommand
17+
{
18+
[XmlAttribute]
19+
[Attributes.PropertyAttributes.PropertyDescription("Please create a DataTable name")]
20+
[Attributes.PropertyAttributes.InputSpecification("Indicate a unique reference name for later use")]
21+
[Attributes.PropertyAttributes.SampleUsage("vMyDatatable")]
22+
[Attributes.PropertyAttributes.Remarks("")]
23+
public string v_DataTableName { get; set; }
24+
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")]
30+
[Attributes.PropertyAttributes.Remarks("")]
31+
public string v_DataTableColumnNames { get; set; }
32+
33+
public CreateDataTableCommand()
34+
{
35+
this.CommandName = "CreateDataTableCommand";
36+
this.SelectionName = "Create DataTable";
37+
this.CommandEnabled = true;
38+
this.CustomRendering = true;
39+
}
40+
41+
public override void RunCommand(object sender)
42+
{
43+
var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;
44+
var vDataTableColumnNames = v_DataTableColumnNames.ConvertToUserVariable(sender);
45+
46+
var splittext = vDataTableColumnNames.Split(',');
47+
DataTable Dt = new DataTable();
48+
49+
foreach(var item in splittext)
50+
{
51+
Dt.Columns.Add(item);
52+
}
53+
54+
Script.ScriptVariable newDataTable = new Script.ScriptVariable
55+
{
56+
VariableName = v_DataTableName,
57+
VariableValue = Dt
58+
};
59+
60+
engine.VariableList.Add(newDataTable);
61+
}
62+
public override List<Control> Render(frmCommandEditor editor)
63+
{
64+
base.Render(editor);
65+
66+
//create standard group controls
67+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DataTableName", this, editor));
68+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DataTableColumnNames", this, editor));
69+
70+
return RenderedControls;
71+
72+
}
73+
74+
public override string GetDisplayValue()
75+
{
76+
return base.GetDisplayValue()+ "[Create DataTable with name: "+ v_DataTableName +"]";
77+
}
78+
}
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Windows.Forms;
4+
using System.Xml.Serialization;
5+
using taskt.UI.CustomControls;
6+
using taskt.UI.Forms;
7+
8+
9+
namespace taskt.Core.Automation.Commands
10+
{
11+
[Serializable]
12+
[Attributes.ClassAttributes.Group("Excel Commands")]
13+
[Attributes.ClassAttributes.Description("Append input to last row of sheet into the first cell.")]
14+
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to set a value to the last cell.")]
15+
[Attributes.ClassAttributes.ImplementationDescription("")]
16+
public class ExcelAppendCellCommand : ScriptCommand
17+
{
18+
[XmlAttribute]
19+
[Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")]
20+
[Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")]
21+
[Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")]
22+
[Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")]
23+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
24+
public string v_InstanceName { get; set; }
25+
[XmlAttribute]
26+
[Attributes.PropertyAttributes.PropertyDescription("Please Enter text to set")]
27+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
28+
[Attributes.PropertyAttributes.InputSpecification("Enter the text value that will be set.")]
29+
[Attributes.PropertyAttributes.SampleUsage("Hello World or [vText]")]
30+
[Attributes.PropertyAttributes.Remarks("")]
31+
public string v_TextToSet { get; set; }
32+
33+
public ExcelAppendCellCommand()
34+
{
35+
this.CommandName = "ExcelAppendCellCommand";
36+
this.SelectionName = "Append Cell";
37+
this.CommandEnabled = true;
38+
this.CustomRendering = true;
39+
}
40+
public override void RunCommand(object sender)
41+
{
42+
43+
44+
var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;
45+
var vInstance = v_InstanceName.ConvertToUserVariable(engine);
46+
47+
var excelObject = engine.GetAppInstance(vInstance);
48+
49+
50+
Microsoft.Office.Interop.Excel.Application excelInstance = (Microsoft.Office.Interop.Excel.Application)excelObject;
51+
Microsoft.Office.Interop.Excel.Worksheet excelSheet = excelInstance.ActiveSheet;
52+
int test = 0;
53+
test = excelSheet.Columns.Count;
54+
var lastUsedRow = excelSheet.Cells.Find("*", System.Reflection.Missing.Value,
55+
System.Reflection.Missing.Value, System.Reflection.Missing.Value,
56+
Microsoft.Office.Interop.Excel.XlSearchOrder.xlByRows, Microsoft.Office.Interop.Excel.XlSearchDirection.xlPrevious,
57+
false, System.Reflection.Missing.Value, System.Reflection.Missing.Value).Row;
58+
var targetAddress = "A" + (lastUsedRow + 1);
59+
var targetText = v_TextToSet.ConvertToUserVariable(sender);
60+
excelSheet.Range[targetAddress].Value = targetText;
61+
62+
}
63+
public override List<Control> Render(frmCommandEditor editor)
64+
{
65+
base.Render(editor);
66+
67+
//create standard group controls
68+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InstanceName", this, editor));
69+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_TextToSet", this, editor));
70+
71+
return RenderedControls;
72+
73+
}
74+
public override string GetDisplayValue()
75+
{
76+
return base.GetDisplayValue() + " [Append last cell to: " + v_TextToSet +"]";
77+
}
78+
}
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Windows.Forms;
4+
using System.Xml.Serialization;
5+
using taskt.UI.CustomControls;
6+
using taskt.UI.Forms;
7+
8+
9+
namespace taskt.Core.Automation.Commands
10+
{
11+
[Serializable]
12+
[Attributes.ClassAttributes.Group("Excel Commands")]
13+
[Attributes.ClassAttributes.Description("Append to last row of sheet.")]
14+
[Attributes.ClassAttributes.UsesDescription("Use this command will take in a comma seprerated value and append it to the end of an excel sheet.")]
15+
[Attributes.ClassAttributes.ImplementationDescription("This command implements Excel Interop to achieve automations.")]
16+
public class ExcelAppendRowCommand : ScriptCommand
17+
{
18+
[XmlAttribute]
19+
[Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")]
20+
[Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")]
21+
[Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")]
22+
[Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")]
23+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
24+
public string v_InstanceName { get; set; }
25+
[XmlAttribute]
26+
[Attributes.PropertyAttributes.PropertyDescription("Please Enter text to set")]
27+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
28+
[Attributes.PropertyAttributes.InputSpecification("Enter the text value that will be set (This could be a DataRow).")]
29+
[Attributes.PropertyAttributes.SampleUsage("Hello,world or [vText]")]
30+
[Attributes.PropertyAttributes.Remarks("")]
31+
public string v_TextToSet { get; set; }
32+
33+
public ExcelAppendRowCommand()
34+
{
35+
this.CommandName = "ExcelAppendRowCommand";
36+
this.SelectionName = "Append Row";
37+
this.CommandEnabled = true;
38+
this.CustomRendering = true;
39+
}
40+
public override void RunCommand(object sender)
41+
{
42+
var splittext = v_TextToSet.Split(',');
43+
var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;
44+
var vInstance = v_InstanceName.ConvertToUserVariable(engine);
45+
var excelObject = engine.GetAppInstance(vInstance);
46+
int i = 1;
47+
48+
Microsoft.Office.Interop.Excel.Application excelInstance = (Microsoft.Office.Interop.Excel.Application)excelObject;
49+
Microsoft.Office.Interop.Excel.Worksheet excelSheet = excelInstance.ActiveSheet;
50+
var lastUsedRow = excelSheet.Cells.Find("*", System.Reflection.Missing.Value,
51+
System.Reflection.Missing.Value, System.Reflection.Missing.Value,
52+
Microsoft.Office.Interop.Excel.XlSearchOrder.xlByRows, Microsoft.Office.Interop.Excel.XlSearchDirection.xlPrevious,
53+
false, System.Reflection.Missing.Value, System.Reflection.Missing.Value).Row;
54+
var targetText = v_TextToSet.ConvertToUserVariable(sender);
55+
splittext = targetText.Split(',');
56+
57+
foreach (var item in splittext)
58+
{
59+
string output = item;
60+
if (item.Contains("[") || item.Contains("]"))
61+
output = item.Trim('[', ']');
62+
output = output.Trim('"');
63+
if (output=="null")
64+
{
65+
output = string.Empty;
66+
}
67+
excelSheet.Cells[lastUsedRow + 1, i] = output;
68+
i++;
69+
}
70+
71+
72+
}
73+
public override List<Control> Render(frmCommandEditor editor)
74+
{
75+
base.Render(editor);
76+
77+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InstanceName", this, editor));
78+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_TextToSet", this, editor));
79+
80+
return RenderedControls;
81+
82+
}
83+
public override string GetDisplayValue()
84+
{
85+
return base.GetDisplayValue() + " [Append Row '" +v_TextToSet+ " to last row" + "of workboook with Instance Name: '" + v_InstanceName + "']";
86+
}
87+
}
88+
}

0 commit comments

Comments
 (0)