Skip to content

Commit e56e038

Browse files
author
Mohammed Bhatti
committed
Added Add Dictionary and Create Dictionary Commands
1 parent 7605f30 commit e56e038

File tree

4 files changed

+216
-1
lines changed

4 files changed

+216
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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+
using System.Drawing;
9+
using System.Linq;
10+
11+
namespace taskt.Core.Automation.Commands
12+
{
13+
[Serializable]
14+
[Attributes.ClassAttributes.Group("Dictionary Commands")]
15+
[Attributes.ClassAttributes.Description("This command created a DataTable with the column names provided")]
16+
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to create a new DataTable")]
17+
[Attributes.ClassAttributes.ImplementationDescription("")]
18+
public class AddDictionaryCommand : ScriptCommand
19+
{
20+
[XmlAttribute]
21+
[Attributes.PropertyAttributes.PropertyDescription("Please Indicate Dictionary Name")]
22+
[Attributes.PropertyAttributes.InputSpecification("Indicate a unique reference name for later use")]
23+
[Attributes.PropertyAttributes.SampleUsage("vMyDictionary")]
24+
[Attributes.PropertyAttributes.Remarks("")]
25+
public string v_DictionaryName { get; set; }
26+
27+
[XmlElement]
28+
[Attributes.PropertyAttributes.PropertyDescription("Define Keys and Values")]
29+
[Attributes.PropertyAttributes.InputSpecification("Enter the Keys and Values required for your dictionary")]
30+
[Attributes.PropertyAttributes.SampleUsage("")]
31+
[Attributes.PropertyAttributes.Remarks("")]
32+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
33+
public DataTable v_ColumnNameDataTable { get; set; }
34+
35+
36+
public AddDictionaryCommand()
37+
{
38+
this.CommandName = "CreateDictionaryCommand";
39+
this.SelectionName = "Add Dictionary";
40+
this.CommandEnabled = true;
41+
this.CustomRendering = true;
42+
43+
//initialize Datatable
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("Keys");
50+
this.v_ColumnNameDataTable.Columns.Add("Values");
51+
52+
53+
54+
}
55+
56+
public override void RunCommand(object sender)
57+
{
58+
var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;
59+
var dictionaryName = v_DictionaryName.ConvertToUserVariable(sender);
60+
var dataSetVariable = LookupVariable(engine);
61+
62+
63+
Dictionary<string, string> outputDictionary = (Dictionary<string, string>)dataSetVariable.VariableValue;
64+
65+
foreach (DataRow rwColumnName in v_ColumnNameDataTable.Rows)
66+
{
67+
outputDictionary.Add(rwColumnName.Field<string>("Keys"), rwColumnName.Field<string>("Values"));
68+
}
69+
dataSetVariable.VariableValue = outputDictionary;
70+
71+
72+
}
73+
private Script.ScriptVariable LookupVariable(Core.Automation.Engine.AutomationEngineInstance sendingInstance)
74+
{
75+
//search for the variable
76+
var requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == v_DictionaryName).FirstOrDefault();
77+
78+
//if variable was not found but it starts with variable naming pattern
79+
if ((requiredVariable == null) && (v_DictionaryName.StartsWith(sendingInstance.engineSettings.VariableStartMarker)) && (v_DictionaryName.EndsWith(sendingInstance.engineSettings.VariableEndMarker)))
80+
{
81+
//reformat and attempt
82+
var reformattedVariable = v_DictionaryName.Replace(sendingInstance.engineSettings.VariableStartMarker, "").Replace(sendingInstance.engineSettings.VariableEndMarker, "");
83+
requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == reformattedVariable).FirstOrDefault();
84+
}
85+
86+
return requiredVariable;
87+
}
88+
public override List<Control> Render(frmCommandEditor editor)
89+
{
90+
base.Render(editor);
91+
92+
//create standard group controls
93+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DictionaryName", this, editor));
94+
RenderedControls.AddRange(CommandControls.CreateDataGridViewGroupFor("v_ColumnNameDataTable", this, editor));
95+
return RenderedControls;
96+
97+
}
98+
99+
public override string GetDisplayValue()
100+
{
101+
return base.GetDisplayValue() + $" [Name: '{v_DictionaryName}' with {v_ColumnNameDataTable.Rows.Count} Entries]";
102+
}
103+
}
104+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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+
using System.Drawing;
9+
using System.Linq;
10+
11+
namespace taskt.Core.Automation.Commands
12+
{
13+
[Serializable]
14+
[Attributes.ClassAttributes.Group("Dictionary Commands")]
15+
[Attributes.ClassAttributes.Description("This command created a DataTable with the column names provided")]
16+
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to create a new DataTable")]
17+
[Attributes.ClassAttributes.ImplementationDescription("")]
18+
public class CreateDictionaryCommand : ScriptCommand
19+
{
20+
[XmlAttribute]
21+
[Attributes.PropertyAttributes.PropertyDescription("Please Indicate Dictionary Name")]
22+
[Attributes.PropertyAttributes.InputSpecification("Indicate a unique reference name for later use")]
23+
[Attributes.PropertyAttributes.SampleUsage("vMyDictionary")]
24+
[Attributes.PropertyAttributes.Remarks("")]
25+
public string v_DictionaryName { get; set; }
26+
27+
[XmlElement]
28+
[Attributes.PropertyAttributes.PropertyDescription("Define Keys and Values")]
29+
[Attributes.PropertyAttributes.InputSpecification("Enter the Keys and Values required for your dictionary")]
30+
[Attributes.PropertyAttributes.SampleUsage("")]
31+
[Attributes.PropertyAttributes.Remarks("")]
32+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
33+
public DataTable v_ColumnNameDataTable { get; set; }
34+
35+
36+
public CreateDictionaryCommand()
37+
{
38+
this.CommandName = "CreateDictionaryCommand";
39+
this.SelectionName = "Create Dictionary";
40+
this.CommandEnabled = true;
41+
this.CustomRendering = true;
42+
43+
//initialize Datatable
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("Keys");
50+
this.v_ColumnNameDataTable.Columns.Add("Values");
51+
52+
53+
54+
}
55+
56+
public override void RunCommand(object sender)
57+
{
58+
var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;
59+
var dictionaryName = v_DictionaryName.ConvertToUserVariable(sender);
60+
61+
Dictionary<string, string> outputDictionary = new Dictionary<string, string>();
62+
63+
foreach (DataRow rwColumnName in v_ColumnNameDataTable.Rows)
64+
{
65+
outputDictionary.Add(rwColumnName.Field<string>("Keys"), rwColumnName.Field<string>("Values"));
66+
}
67+
68+
69+
70+
71+
//add or override existing variable
72+
if (engine.VariableList.Any(f => f.VariableName == dictionaryName))
73+
{
74+
var selectedVariable = engine.VariableList.Where(f => f.VariableName == dictionaryName).FirstOrDefault();
75+
selectedVariable.VariableValue = outputDictionary;
76+
}
77+
else
78+
{
79+
Script.ScriptVariable newDictionary = new Script.ScriptVariable
80+
{
81+
VariableName = dictionaryName,
82+
VariableValue = outputDictionary
83+
};
84+
85+
engine.VariableList.Add(newDictionary);
86+
}
87+
88+
89+
90+
}
91+
public override List<Control> Render(frmCommandEditor editor)
92+
{
93+
base.Render(editor);
94+
95+
//create standard group controls
96+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DictionaryName", this, editor));
97+
RenderedControls.AddRange(CommandControls.CreateDataGridViewGroupFor("v_ColumnNameDataTable", this, editor));
98+
return RenderedControls;
99+
100+
}
101+
102+
public override string GetDisplayValue()
103+
{
104+
return base.GetDisplayValue() + $" [Name: '{v_DictionaryName}' with {v_ColumnNameDataTable.Rows.Count} Entries]";
105+
}
106+
}
107+
}

taskt/Core/Automation/Commands/ScriptCommand.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ namespace taskt.Core.Automation.Commands
88
{
99
[Serializable]
1010
[XmlInclude(typeof(SendKeysCommand))]
11-
[XmlInclude(typeof(SendAdvancedKeyStrokesCommand))]
11+
[XmlInclude(typeof(SendAdvancedKeyStrokesCommand))]
12+
[XmlInclude(typeof(CreateDictionaryCommand))]
1213
[XmlInclude(typeof(SendMouseMoveCommand))]
1314
[XmlInclude(typeof(PauseCommand))]
15+
[XmlInclude(typeof(AddDictionaryCommand))]
1416
[XmlInclude(typeof(OutlookEmailCommand))]
1517
[XmlInclude(typeof(ActivateWindowCommand))]
1618
[XmlInclude(typeof(GetRegexMatchesCommand))]

taskt/taskt.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@
164164
<ItemGroup>
165165
<Compile Include="Core\ApplicationUpdate.cs" />
166166
<Compile Include="Core\ApplicationSettings.cs" />
167+
<Compile Include="Core\Automation\Commands\AddDictionaryCommand.cs" />
168+
<Compile Include="Core\Automation\Commands\CreateDictionaryCommand.cs" />
167169
<Compile Include="Core\Automation\Commands\OutlookEmailCommand.cs" />
168170
<Compile Include="Core\Automation\Commands\GetRegexMatchesCommand.cs" />
169171
<Compile Include="Core\Automation\Commands\GetDictionaryValueCommand.cs" />

0 commit comments

Comments
 (0)