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
+ namespace taskt . Core . Automation . Commands
9
+ {
10
+ [ Serializable ]
11
+ [ Attributes . ClassAttributes . Group ( "Data Commands" ) ]
12
+ [ Attributes . ClassAttributes . Description ( "This command allows you to trim a string" ) ]
13
+ [ Attributes . ClassAttributes . UsesDescription ( "Use this command when you want to select a subset of text or variable" ) ]
14
+ [ Attributes . ClassAttributes . ImplementationDescription ( "This command uses the String.Substring method to achieve automation." ) ]
15
+ public class ModifyVariableCommand : ScriptCommand
16
+ {
17
+ [ XmlAttribute ]
18
+ [ Attributes . PropertyAttributes . PropertyDescription ( "Please select a variable or text to modify" ) ]
19
+ [ Attributes . PropertyAttributes . InputSpecification ( "Select or provide a variable from the variable list" ) ]
20
+ [ Attributes . PropertyAttributes . SampleUsage ( "**vSomeVariable**" ) ]
21
+ [ Attributes . PropertyAttributes . Remarks ( "" ) ]
22
+ public string v_userVariableName { get ; set ; }
23
+
24
+ [ XmlAttribute ]
25
+ [ Attributes . PropertyAttributes . PropertyDescription ( "Select the case type" ) ]
26
+ [ Attributes . PropertyAttributes . InputSpecification ( "Indicate if only so many characters should be kept" ) ]
27
+ [ Attributes . PropertyAttributes . SampleUsage ( "-1 to keep remainder, 1 for 1 position after start index, etc." ) ]
28
+ [ Attributes . PropertyAttributes . Remarks ( "" ) ]
29
+ [ Attributes . PropertyAttributes . PropertyUISelectionOption ( "To Upper Case" ) ]
30
+ [ Attributes . PropertyAttributes . PropertyUISelectionOption ( "To Lower Case" ) ]
31
+ [ Attributes . PropertyAttributes . PropertyUISelectionOption ( "To Base64 String" ) ]
32
+ [ Attributes . PropertyAttributes . PropertyUISelectionOption ( "From Base64 String" ) ]
33
+ public string v_ConvertType { get ; set ; }
34
+
35
+ [ XmlAttribute ]
36
+ [ Attributes . PropertyAttributes . PropertyDescription ( "Please select the variable to receive the changes" ) ]
37
+ [ Attributes . PropertyAttributes . InputSpecification ( "Select or provide a variable from the variable list" ) ]
38
+ [ Attributes . PropertyAttributes . SampleUsage ( "**vSomeVariable**" ) ]
39
+ [ 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." ) ]
40
+ public string v_applyToVariableName { get ; set ; }
41
+ public ModifyVariableCommand ( )
42
+ {
43
+ this . CommandName = "ModifyVariableCommand" ;
44
+ this . SelectionName = "Modify Variable" ;
45
+ this . CommandEnabled = true ;
46
+ this . CustomRendering = true ;
47
+ ;
48
+ }
49
+ public override void RunCommand ( object sender )
50
+ {
51
+
52
+
53
+ var stringValue = v_userVariableName . ConvertToUserVariable ( sender ) ;
54
+
55
+ var caseType = v_ConvertType . ConvertToUserVariable ( sender ) ;
56
+
57
+ switch ( caseType )
58
+ {
59
+ case "To Upper Case" :
60
+ stringValue = stringValue . ToUpper ( ) ;
61
+ break ;
62
+ case "To Lower Case" :
63
+ stringValue = stringValue . ToLower ( ) ;
64
+ break ;
65
+ case "To Base64 String" :
66
+ byte [ ] textAsBytes = System . Text . Encoding . ASCII . GetBytes ( stringValue ) ;
67
+ stringValue = Convert . ToBase64String ( textAsBytes ) ;
68
+ break ;
69
+ case "From Base64 String" :
70
+ byte [ ] encodedDataAsBytes = System . Convert . FromBase64String ( stringValue ) ;
71
+ stringValue = System . Text . ASCIIEncoding . ASCII . GetString ( encodedDataAsBytes ) ;
72
+ break ;
73
+ default :
74
+ throw new NotImplementedException ( "Conversion Type '" + caseType + "' not implemented!" ) ;
75
+ }
76
+
77
+ stringValue . StoreInUserVariable ( sender , v_applyToVariableName ) ;
78
+ }
79
+ public override List < Control > Render ( frmCommandEditor editor )
80
+ {
81
+ base . Render ( editor ) ;
82
+
83
+ RenderedControls . Add ( CommandControls . CreateDefaultLabelFor ( "v_userVariableName" , this ) ) ;
84
+ var userVariableName = CommandControls . CreateStandardComboboxFor ( "v_userVariableName" , this ) . AddVariableNames ( editor ) ;
85
+ RenderedControls . AddRange ( CommandControls . CreateUIHelpersFor ( "v_userVariableName" , this , new Control [ ] { userVariableName } , editor ) ) ;
86
+ RenderedControls . Add ( userVariableName ) ;
87
+
88
+ //create standard group controls
89
+ RenderedControls . AddRange ( CommandControls . CreateDefaultDropdownGroupFor ( "v_ConvertType" , this , editor ) ) ;
90
+
91
+
92
+ RenderedControls . Add ( CommandControls . CreateDefaultLabelFor ( "v_applyToVariableName" , this ) ) ;
93
+ var VariableNameControl = CommandControls . CreateStandardComboboxFor ( "v_applyToVariableName" , this ) . AddVariableNames ( editor ) ;
94
+ RenderedControls . AddRange ( CommandControls . CreateUIHelpersFor ( "v_applyToVariableName" , this , new Control [ ] { VariableNameControl } , editor ) ) ;
95
+ RenderedControls . Add ( VariableNameControl ) ;
96
+
97
+ return RenderedControls ;
98
+
99
+ }
100
+ public override string GetDisplayValue ( )
101
+ {
102
+ return base . GetDisplayValue ( ) + " [Convert '" + v_userVariableName + "' " + v_ConvertType + "']" ;
103
+ }
104
+ }
105
+ }
0 commit comments