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
+ }
0 commit comments