1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using System . Xml . Serialization ;
5
+ using System . Data ;
6
+ using System . Windows . Forms ;
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 handles text encryption" ) ]
15
+ [ Attributes . ClassAttributes . UsesDescription ( "Use this command when you want to store some data encrypted" ) ]
16
+ [ Attributes . ClassAttributes . ImplementationDescription ( "" ) ]
17
+ public class EncryptionCommand : ScriptCommand
18
+ {
19
+ [ XmlElement ]
20
+ [ Attributes . PropertyAttributes . PropertyDescription ( "Select Encryption Action" ) ]
21
+ [ Attributes . PropertyAttributes . PropertyUISelectionOption ( "Encrypt" ) ]
22
+ [ Attributes . PropertyAttributes . PropertyUISelectionOption ( "Decrypt" ) ]
23
+ [ Attributes . PropertyAttributes . InputSpecification ( "Select an action to take" ) ]
24
+ [ Attributes . PropertyAttributes . SampleUsage ( "Select from **Encrypt**, **Decrypt**" ) ]
25
+ [ Attributes . PropertyAttributes . Remarks ( "" ) ]
26
+ public string v_EncryptionType { get ; set ; }
27
+
28
+ [ XmlAttribute ]
29
+ [ Attributes . PropertyAttributes . PropertyDescription ( "Supply the data or variable (ex. {someVariable})" ) ]
30
+ [ Attributes . PropertyAttributes . PropertyUIHelper ( Attributes . PropertyAttributes . PropertyUIHelper . UIAdditionalHelperType . ShowVariableHelper ) ]
31
+ [ Attributes . PropertyAttributes . InputSpecification ( "Select or provide a variable or json array value" ) ]
32
+ [ Attributes . PropertyAttributes . SampleUsage ( "**Test** or **{var}**" ) ]
33
+ [ Attributes . PropertyAttributes . Remarks ( "" ) ]
34
+ public string v_InputValue { get ; set ; }
35
+
36
+ [ XmlAttribute ]
37
+ [ Attributes . PropertyAttributes . PropertyDescription ( "Provide a Pass Phrase" ) ]
38
+ [ Attributes . PropertyAttributes . PropertyUIHelper ( Attributes . PropertyAttributes . PropertyUIHelper . UIAdditionalHelperType . ShowVariableHelper ) ]
39
+ [ Attributes . PropertyAttributes . InputSpecification ( "Select or provide a variable or json array value" ) ]
40
+ [ Attributes . PropertyAttributes . SampleUsage ( "**Test** or **{var}**" ) ]
41
+ [ Attributes . PropertyAttributes . Remarks ( "" ) ]
42
+ public string v_PassPhrase { get ; set ; }
43
+
44
+ [ XmlAttribute ]
45
+ [ Attributes . PropertyAttributes . PropertyDescription ( "Please select the variable to receive the encrypted data" ) ]
46
+ [ Attributes . PropertyAttributes . PropertyUIHelper ( Attributes . PropertyAttributes . PropertyUIHelper . UIAdditionalHelperType . ShowVariableHelper ) ]
47
+ [ Attributes . PropertyAttributes . InputSpecification ( "Select or provide a variable from the variable list" ) ]
48
+ [ Attributes . PropertyAttributes . SampleUsage ( "**vSomeVariable**" ) ]
49
+ [ Attributes . PropertyAttributes . Remarks ( "If you have enabled the setting **Create Missing Variables at Runtime** then you are not required to pre-define your variables, however, it is highly recommended." ) ]
50
+ public string v_applyToVariableName { get ; set ; }
51
+
52
+ public EncryptionCommand ( )
53
+ {
54
+ this . CommandName = "EncryptionCommand" ;
55
+ this . SelectionName = "Encryption Command" ;
56
+ this . CommandEnabled = true ;
57
+ this . CustomRendering = true ;
58
+ this . v_EncryptionType = "Encrypt" ;
59
+ this . v_PassPhrase = "TASKT" ;
60
+
61
+
62
+ }
63
+
64
+ public override void RunCommand ( object sender )
65
+ {
66
+ var engine = ( Core . Automation . Engine . AutomationEngineInstance ) sender ;
67
+
68
+ //get variablized input
69
+ var variableInput = v_InputValue . ConvertToUserVariable ( sender ) ;
70
+ var passphrase = v_PassPhrase . ConvertToUserVariable ( sender ) ;
71
+
72
+ string resultData = "" ;
73
+ if ( v_EncryptionType . ConvertToUserVariable ( sender ) == "Encrypt" )
74
+ {
75
+ //encrypt data
76
+ resultData = Core . EncryptionServices . EncryptString ( variableInput , passphrase ) ;
77
+ }
78
+ else if ( v_EncryptionType . ConvertToUserVariable ( sender ) == "Decrypt" )
79
+ {
80
+ //encrypt data
81
+ resultData = Core . EncryptionServices . DecryptString ( variableInput , passphrase ) ;
82
+ }
83
+ else
84
+ {
85
+ throw new NotImplementedException ( $ "Encryption Service Requested '{ v_EncryptionType . ConvertToUserVariable ( sender ) } ' has not been implemented") ;
86
+ }
87
+
88
+ //get variable
89
+ var requiredComplexVariable = engine . VariableList . Where ( x => x . VariableName == v_applyToVariableName ) . FirstOrDefault ( ) ;
90
+
91
+ //create if var does not exist
92
+ if ( requiredComplexVariable == null )
93
+ {
94
+ engine . VariableList . Add ( new Script . ScriptVariable ( ) { VariableName = v_applyToVariableName , CurrentPosition = 0 } ) ;
95
+ requiredComplexVariable = engine . VariableList . Where ( x => x . VariableName == v_applyToVariableName ) . FirstOrDefault ( ) ;
96
+ }
97
+
98
+ //assign value to variable
99
+ requiredComplexVariable . VariableValue = resultData ;
100
+
101
+ }
102
+ public override List < Control > Render ( frmCommandEditor editor )
103
+ {
104
+ base . Render ( editor ) ;
105
+
106
+ //create standard group controls
107
+ RenderedControls . AddRange ( CommandControls . CreateDefaultDropdownGroupFor ( "v_EncryptionType" , this , editor ) ) ;
108
+ RenderedControls . AddRange ( CommandControls . CreateDefaultInputGroupFor ( "v_InputValue" , this , editor ) ) ;
109
+ RenderedControls . AddRange ( CommandControls . CreateDefaultInputGroupFor ( "v_PassPhrase" , this , editor ) ) ;
110
+
111
+ RenderedControls . Add ( CommandControls . CreateDefaultLabelFor ( "v_applyToVariableName" , this ) ) ;
112
+ var VariableNameControl = CommandControls . CreateStandardComboboxFor ( "v_applyToVariableName" , this ) . AddVariableNames ( editor ) ;
113
+ RenderedControls . AddRange ( CommandControls . CreateUIHelpersFor ( "v_applyToVariableName" , this , new Control [ ] { VariableNameControl } , editor ) ) ;
114
+ RenderedControls . Add ( VariableNameControl ) ;
115
+
116
+ return RenderedControls ;
117
+
118
+ }
119
+
120
+
121
+
122
+ public override string GetDisplayValue ( )
123
+ {
124
+ return base . GetDisplayValue ( ) + $ " [{ v_EncryptionType } Data, apply to '{ v_applyToVariableName } ']";
125
+ }
126
+ }
127
+ }
0 commit comments