Skip to content

Commit c097ad2

Browse files
author
Mohammed Bhatti
committed
Fixed bugs with Excel Commands.
Added Regex Command. Added Get Dictionary from Excel command.
1 parent d96ca54 commit c097ad2

11 files changed

+327
-18
lines changed

taskt/Core/Automation/Commands/AddDataRowCommand.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace taskt.Core.Automation.Commands
1111
{
1212
[Serializable]
13-
[Attributes.ClassAttributes.Group("Misc Commands")]
13+
[Attributes.ClassAttributes.Group("DataTable Commands")]
1414
[Attributes.ClassAttributes.Description("This command allows you to loop through an Excel Dataset")]
1515
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to iterate over a series of Excel cells.")]
1616
[Attributes.ClassAttributes.ImplementationDescription("This command attempts to loop through a known Excel DataSet")]
@@ -23,9 +23,9 @@ public class AddDataRowCommand : ScriptCommand
2323
[Attributes.PropertyAttributes.Remarks("")]
2424
public string v_DataTableName { get; set; }
2525
[XmlAttribute]
26-
[Attributes.PropertyAttributes.PropertyDescription("Please the names of your columns")]
26+
[Attributes.PropertyAttributes.PropertyDescription("Please input the data you want entered.")]
2727
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
28-
[Attributes.PropertyAttributes.InputSpecification("Enter the actual names of your columns.")]
28+
[Attributes.PropertyAttributes.InputSpecification("Enter a string of comma seperated values.")]
2929
[Attributes.PropertyAttributes.SampleUsage("name1,name2,name3,name4")]
3030
[Attributes.PropertyAttributes.Remarks("")]
3131
public string v_InputData { get; set; }

taskt/Core/Automation/Commands/CreateDataTableCommand.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace taskt.Core.Automation.Commands
1010
{
1111
[Serializable]
12-
[Attributes.ClassAttributes.Group("Misc Commands")]
12+
[Attributes.ClassAttributes.Group("DataTable Commands")]
1313
[Attributes.ClassAttributes.Description("This command gets a range of cells and applies them against a dataset")]
1414
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to quickly iterate over Excel as a dataset.")]
1515
[Attributes.ClassAttributes.ImplementationDescription("This command implements 'OLEDB' to achieve automation.")]

taskt/Core/Automation/Commands/ExcelAppendCellCommand.cs

-9
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@
44
using System.Xml.Serialization;
55
using taskt.UI.CustomControls;
66
using taskt.UI.Forms;
7-
using System.Data;
8-
using System;
9-
using System.Linq;
10-
using System.Xml.Serialization;
11-
using System.Data;
12-
using System.Windows.Forms;
13-
using System.Collections.Generic;
14-
using taskt.UI.Forms;
15-
using taskt.UI.CustomControls;
167

178

189
namespace taskt.Core.Automation.Commands

taskt/Core/Automation/Commands/ExcelWriteRangeCommand.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public override void RunCommand(object sender)
6666
int sum = 0;
6767

6868
for (int i = 0; i < targetAddress.Length; i++)
69-
{
69+
{
7070
sum *= 26;
7171
sum += (targetAddress[i] - 'A' + 1);
7272
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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("Misc Commands")]
14+
[Attributes.ClassAttributes.Description("This command allows you to loop through an Excel Dataset")]
15+
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to iterate over a series of Excel cells.")]
16+
[Attributes.ClassAttributes.ImplementationDescription("This command attempts to loop through a known Excel DataSet")]
17+
public class GetDictionaryValueCommand : ScriptCommand
18+
{
19+
[XmlAttribute]
20+
[Attributes.PropertyAttributes.PropertyDescription("Please indicate the output variable")]
21+
[Attributes.PropertyAttributes.InputSpecification("Enter a unique dataset name that will be used later to traverse over the data")]
22+
[Attributes.PropertyAttributes.SampleUsage("**myData**")]
23+
[Attributes.PropertyAttributes.Remarks("")]
24+
public string v_OutputVariable { get; set; }
25+
[XmlAttribute]
26+
[Attributes.PropertyAttributes.PropertyDescription("Please input The Dictionary")]
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+
[XmlAttribute]
33+
[Attributes.PropertyAttributes.PropertyDescription("Please indicate the key")]
34+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
35+
[Attributes.PropertyAttributes.InputSpecification("Enter a string of comma seperated values.")]
36+
[Attributes.PropertyAttributes.SampleUsage("name1,name2,name3,name4")]
37+
[Attributes.PropertyAttributes.Remarks("")]
38+
public string v_Key { get; set; }
39+
40+
public GetDictionaryValueCommand()
41+
{
42+
this.CommandName = "AddDataRowCommand";
43+
this.SelectionName = "Get Value From Dictionary";
44+
this.CommandEnabled = true;
45+
this.CustomRendering = true;
46+
}
47+
48+
public override void RunCommand(object sender)
49+
{
50+
Console.WriteLine("DSAHDUSAIFSA");
51+
var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;
52+
var dataSetVariable = LookupVariable(engine);
53+
Dictionary<string,string> dict = (Dictionary<string,string>)dataSetVariable.VariableValue;
54+
Script.ScriptVariable Output = new Script.ScriptVariable
55+
{
56+
VariableName = v_OutputVariable,
57+
VariableValue = dict[v_Key]
58+
};
59+
60+
engine.VariableList.Add(Output);
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_InputData).FirstOrDefault();
66+
67+
//if variable was not found but it starts with variable naming pattern
68+
if ((requiredVariable == null) && (v_InputData.StartsWith(sendingInstance.engineSettings.VariableStartMarker)) && (v_InputData.EndsWith(sendingInstance.engineSettings.VariableEndMarker)))
69+
{
70+
//reformat and attempt
71+
var reformattedVariable = v_InputData.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_OutputVariable", this, editor));
82+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InputData", this, editor));
83+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_Key", this, editor));
84+
85+
86+
87+
return RenderedControls;
88+
}
89+
90+
public override string GetDisplayValue()
91+
{
92+
return base.GetDisplayValue();
93+
}
94+
}
95+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
using System.Text.RegularExpressions;
10+
11+
namespace taskt.Core.Automation.Commands
12+
{
13+
[Serializable]
14+
[Attributes.ClassAttributes.Group("Regex Commands")]
15+
[Attributes.ClassAttributes.Description("This command allows you to loop through an Excel Dataset")]
16+
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to iterate over a series of Excel cells.")]
17+
[Attributes.ClassAttributes.ImplementationDescription("This command attempts to loop through a known Excel DataSet")]
18+
public class GetRegexMatchesCommand : ScriptCommand
19+
{
20+
[XmlAttribute]
21+
[Attributes.PropertyAttributes.PropertyDescription("Enter Regex Expressions.")]
22+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
23+
[Attributes.PropertyAttributes.InputSpecification("Enter a string of comma seperated values.")]
24+
[Attributes.PropertyAttributes.SampleUsage("name1,name2,name3,name4")]
25+
[Attributes.PropertyAttributes.Remarks("")]
26+
public string v_Regex { get; set; }
27+
[XmlAttribute]
28+
[Attributes.PropertyAttributes.PropertyDescription("Please input the data you want to perform regex on.")]
29+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
30+
[Attributes.PropertyAttributes.InputSpecification("Enter a string of comma seperated values.")]
31+
[Attributes.PropertyAttributes.SampleUsage("name1,name2,name3,name4")]
32+
[Attributes.PropertyAttributes.Remarks("")]
33+
public string v_InputData { get; set; }
34+
[XmlAttribute]
35+
[Attributes.PropertyAttributes.PropertyDescription("Please input a variable name.")]
36+
[Attributes.PropertyAttributes.InputSpecification("Enter a string of comma seperated values.")]
37+
[Attributes.PropertyAttributes.SampleUsage("name1,name2,name3,name4")]
38+
[Attributes.PropertyAttributes.Remarks("")]
39+
public string v_OutputVariable { get; set; }
40+
41+
public GetRegexMatchesCommand()
42+
{
43+
this.CommandName = "GetRegexMatchesCommand";
44+
this.SelectionName = "Get Regex Matches";
45+
this.CommandEnabled = true;
46+
this.CustomRendering = true;
47+
}
48+
49+
public override void RunCommand(object sender)
50+
{
51+
var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;
52+
var vInputData = v_InputData.ConvertToUserVariable(engine);
53+
string vRegex = v_Regex.ConvertToUserVariable(engine);
54+
Match[] matches = Regex.Matches(vInputData, vRegex)
55+
.Cast<Match>()
56+
.ToArray();
57+
var arr = string.Join(",", matches.AsEnumerable());
58+
59+
Script.ScriptVariable outputMatches = new Script.ScriptVariable
60+
{
61+
VariableName = v_OutputVariable,
62+
VariableValue = arr
63+
};
64+
65+
engine.VariableList.Add(outputMatches);
66+
67+
68+
}
69+
public override List<Control> Render(frmCommandEditor editor)
70+
{
71+
base.Render(editor);
72+
73+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_Regex", this, editor));
74+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InputData", this, editor));
75+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_OutputVariable", this, editor));
76+
77+
78+
79+
return RenderedControls;
80+
}
81+
82+
public override string GetDisplayValue()
83+
{
84+
return base.GetDisplayValue();
85+
}
86+
}
87+
}

taskt/Core/Automation/Commands/HTMLInputCommand.cs

+1-1
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data;
4+
using System.Linq;
5+
using System.Windows.Forms;
6+
using System.Xml.Serialization;
7+
using taskt.UI.CustomControls;
8+
using taskt.UI.Forms;
9+
10+
namespace taskt.Core.Automation.Commands
11+
{
12+
[Serializable]
13+
[Attributes.ClassAttributes.Group("Excel Commands")]
14+
[Attributes.ClassAttributes.Description("This command opens an Excel Workbook.")]
15+
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to open an existing Excel Workbook.")]
16+
[Attributes.ClassAttributes.ImplementationDescription("This command implements Excel Interop to achieve automation.")]
17+
public class LoadDictionaryCommand : ScriptCommand
18+
{
19+
[XmlAttribute]
20+
[Attributes.PropertyAttributes.PropertyDescription("Please Enter the Dictionary Name")]
21+
[Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")]
22+
[Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")]
23+
[Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")]
24+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
25+
public string v_DictionaryName { get; set; }
26+
27+
[XmlAttribute]
28+
[Attributes.PropertyAttributes.PropertyDescription("Please indicate the workbook file path")]
29+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFileSelectionHelper)]
30+
[Attributes.PropertyAttributes.InputSpecification("Enter or Select the path to the applicable file that should be opened by Excel.")]
31+
[Attributes.PropertyAttributes.SampleUsage(@"C:\temp\myfile.xlsx or [vFilePath]")]
32+
[Attributes.PropertyAttributes.Remarks("")]
33+
public string v_FilePath { get; set; }
34+
[XmlAttribute]
35+
[Attributes.PropertyAttributes.PropertyDescription("Please indicate the Sheet Name")]
36+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFileSelectionHelper)]
37+
[Attributes.PropertyAttributes.InputSpecification("Enter or Select the path to the applicable file that should be opened by Excel.")]
38+
[Attributes.PropertyAttributes.SampleUsage(@"C:\temp\myfile.xlsx or [vFilePath]")]
39+
[Attributes.PropertyAttributes.Remarks("")]
40+
public string v_SheetName { get; set; }
41+
[XmlAttribute]
42+
[Attributes.PropertyAttributes.PropertyDescription("Please indicate the Key column")]
43+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFileSelectionHelper)]
44+
[Attributes.PropertyAttributes.InputSpecification("Enter or Select the path to the applicable file that should be opened by Excel.")]
45+
[Attributes.PropertyAttributes.SampleUsage(@"C:\temp\myfile.xlsx or [vFilePath]")]
46+
[Attributes.PropertyAttributes.Remarks("")]
47+
public string v_KeyColumn { get; set; }
48+
[XmlAttribute]
49+
[Attributes.PropertyAttributes.PropertyDescription("Please indicate the Value Column")]
50+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFileSelectionHelper)]
51+
[Attributes.PropertyAttributes.InputSpecification("Enter or Select the path to the applicable file that should be opened by Excel.")]
52+
[Attributes.PropertyAttributes.SampleUsage(@"C:\temp\myfile.xlsx or [vFilePath]")]
53+
[Attributes.PropertyAttributes.Remarks("")]
54+
public string v_ValueColumn { get; set; }
55+
public LoadDictionaryCommand()
56+
{
57+
this.CommandName = "ExcelOpenWorkbookCommand";
58+
this.SelectionName = "Load Dictionary";
59+
this.CommandEnabled = true;
60+
this.CustomRendering = true;
61+
}
62+
public override void RunCommand(object sender)
63+
{
64+
var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;
65+
var vInstance = "Test";
66+
var vFilePath = v_FilePath.ConvertToUserVariable(sender);
67+
68+
var newExcelSession = new Microsoft.Office.Interop.Excel.Application
69+
{
70+
Visible = true
71+
};
72+
73+
engine.AddAppInstance("Test", newExcelSession);
74+
75+
76+
var excelObject = engine.GetAppInstance(vInstance);
77+
Microsoft.Office.Interop.Excel.Application excelInstance = (Microsoft.Office.Interop.Excel.Application)excelObject;
78+
//excelInstance.Workbooks.Open(vFilePath);
79+
80+
DatasetCommands dataSetCommand = new DatasetCommands();
81+
DataTable requiredData = dataSetCommand.CreateDataTable(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + v_FilePath + @";Extended Properties=""Excel 12.0;HDR=YES;IMEX=1""", "Select "+v_KeyColumn+ ","+ v_ValueColumn + " From [" + v_SheetName + "$]");
82+
//Console.WriteLine(requiredData.Columns[0].ColumnName);
83+
84+
// requiredData.Columns[requiredData.Columns[0].ToString()].ColumnName = v_KeyColumn;
85+
//requiredData.Columns[requiredData.Columns[1].ToString()].ColumnName = v_ValueColumn;
86+
var dictlist = requiredData.AsEnumerable().Select(x => new
87+
{
88+
keys = (string)x[v_KeyColumn],
89+
values = (string)x[v_ValueColumn]
90+
}).ToList();
91+
Dictionary<string, string> outputDictionary = new Dictionary<string, string>();
92+
foreach (var dict in dictlist)
93+
{
94+
outputDictionary.Add(dict.keys, dict.values);
95+
}
96+
97+
98+
Script.ScriptVariable newDictionary = new Script.ScriptVariable
99+
{
100+
VariableName = v_DictionaryName,
101+
VariableValue = outputDictionary
102+
};
103+
//close excel
104+
excelInstance.Quit();
105+
106+
//remove instance
107+
engine.RemoveAppInstance(vInstance);
108+
engine.VariableList.Add(newDictionary);
109+
}
110+
public override List<Control> Render(frmCommandEditor editor)
111+
{
112+
base.Render(editor);
113+
114+
//create standard group controls
115+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_FilePath", this, editor));
116+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DictionaryName", this, editor));
117+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_SheetName", this, editor));
118+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_KeyColumn", this, editor));
119+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_ValueColumn", this, editor));
120+
121+
122+
return RenderedControls;
123+
124+
}
125+
public override string GetDisplayValue()
126+
{
127+
return base.GetDisplayValue() + " [Open from '" + v_FilePath + "', Instance Name: '" + "']";
128+
}
129+
}
130+
}

taskt/Core/Automation/Commands/RemoveDataRowCommand.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace taskt.Core.Automation.Commands
1111
{
1212
[Serializable]
13-
[Attributes.ClassAttributes.Group("Misc Commands")]
13+
[Attributes.ClassAttributes.Group("DataTable Commands")]
1414
[Attributes.ClassAttributes.Description("This command allows you to loop through an Excel Dataset")]
1515
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to iterate over a series of Excel cells.")]
1616
[Attributes.ClassAttributes.ImplementationDescription("This command attempts to loop through a known Excel DataSet")]

taskt/Core/Automation/Commands/ScriptCommand.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ namespace taskt.Core.Automation.Commands
1111
[XmlInclude(typeof(SendAdvancedKeyStrokesCommand))]
1212
[XmlInclude(typeof(SendMouseMoveCommand))]
1313
[XmlInclude(typeof(PauseCommand))]
14-
[XmlInclude(typeof(ActivateWindowCommand))]
14+
[XmlInclude(typeof(ActivateWindowCommand))]
15+
[XmlInclude(typeof(GetRegexMatchesCommand))]
1516
[XmlInclude(typeof(MoveWindowCommand))]
1617
[XmlInclude(typeof(CommentCommand))]
17-
[XmlInclude(typeof(CreateDataTableCommand))]
18+
[XmlInclude(typeof(CreateDataTableCommand))]
19+
[XmlInclude(typeof(GetDictionaryValueCommand))]
20+
[XmlInclude(typeof(LoadDictionaryCommand))]
1821
[XmlInclude(typeof(AddDataRowCommand))]
1922
[XmlInclude(typeof(RemoveDataRowCommand))]
2023
[XmlInclude(typeof(ThickAppClickItemCommand))]

0 commit comments

Comments
 (0)