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
+ using System . Linq ;
8
+
9
+ namespace taskt . Core . Automation . Commands
10
+ {
11
+
12
+ [ Serializable ]
13
+ [ Attributes . ClassAttributes . Group ( "Folder Operation Commands" ) ]
14
+ [ Attributes . ClassAttributes . Description ( "This command returns a list of folder directories from a specified destination" ) ]
15
+ [ Attributes . ClassAttributes . UsesDescription ( "Use this command to return a list of folder directories from a specific location." ) ]
16
+ [ Attributes . ClassAttributes . ImplementationDescription ( "This command implements '' to achieve automation." ) ]
17
+ public class GetFoldersCommand : ScriptCommand
18
+ {
19
+ [ XmlAttribute ]
20
+ [ Attributes . PropertyAttributes . PropertyDescription ( "Please indicate the path to the source folder" ) ]
21
+ [ Attributes . PropertyAttributes . PropertyUIHelper ( Attributes . PropertyAttributes . PropertyUIHelper . UIAdditionalHelperType . ShowVariableHelper ) ]
22
+ [ Attributes . PropertyAttributes . PropertyUIHelper ( Attributes . PropertyAttributes . PropertyUIHelper . UIAdditionalHelperType . ShowFolderSelectionHelper ) ]
23
+ [ Attributes . PropertyAttributes . InputSpecification ( "Enter or Select the path to the folder." ) ]
24
+ [ Attributes . PropertyAttributes . SampleUsage ( "C:\\ temp\\ myfolder or [vTextFolderPath]" ) ]
25
+ [ Attributes . PropertyAttributes . Remarks ( "" ) ]
26
+ public string v_SourceFolderPath { get ; set ; }
27
+
28
+ [ XmlAttribute ]
29
+ [ Attributes . PropertyAttributes . PropertyDescription ( "Assign to Variable" ) ]
30
+ [ Attributes . PropertyAttributes . InputSpecification ( "Select or provide a variable from the variable list" ) ]
31
+ [ Attributes . PropertyAttributes . SampleUsage ( "**vSomeVariable**" ) ]
32
+ [ 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." ) ]
33
+ public string v_UserVariableName { get ; set ; }
34
+
35
+ public GetFoldersCommand ( )
36
+ {
37
+ this . CommandName = "GetFoldersCommand" ;
38
+ this . SelectionName = "Get Folders" ;
39
+ this . CommandEnabled = true ;
40
+ this . CustomRendering = true ;
41
+ }
42
+
43
+ public override void RunCommand ( object sender )
44
+ {
45
+ var engine = ( Core . Automation . Engine . AutomationEngineInstance ) sender ;
46
+ //apply variable logic
47
+ var sourceFolder = v_SourceFolderPath . ConvertToUserVariable ( sender ) ;
48
+
49
+ //delete folder
50
+ //System.IO.Directory.Delete(sourceFolder, true);
51
+ var directoriesList = System . IO . Directory . GetDirectories ( sourceFolder ) . ToList ( ) ;
52
+
53
+ Script . ScriptVariable newDirectoriesList = new Script . ScriptVariable
54
+ {
55
+ VariableName = v_UserVariableName ,
56
+ VariableValue = directoriesList
57
+ } ;
58
+ //Overwrites variable if it already exists
59
+ if ( engine . VariableList . Exists ( x => x . VariableName == newDirectoriesList . VariableName ) )
60
+ {
61
+ Script . ScriptVariable temp = engine . VariableList . Where ( x => x . VariableName == newDirectoriesList . VariableName ) . FirstOrDefault ( ) ;
62
+ engine . VariableList . Remove ( temp ) ;
63
+ }
64
+ engine . VariableList . Add ( newDirectoriesList ) ;
65
+
66
+ }
67
+ public override List < Control > Render ( frmCommandEditor editor )
68
+ {
69
+ base . Render ( editor ) ;
70
+
71
+ RenderedControls . AddRange ( CommandControls . CreateDefaultInputGroupFor ( "v_SourceFolderPath" , this , editor ) ) ;
72
+
73
+ RenderedControls . Add ( CommandControls . CreateDefaultLabelFor ( "v_UserVariableName" , this ) ) ;
74
+ var VariableNameControl = CommandControls . CreateStandardComboboxFor ( "v_UserVariableName" , this ) . AddVariableNames ( editor ) ;
75
+ RenderedControls . AddRange ( CommandControls . CreateUIHelpersFor ( "v_UserVariableName" , this , new Control [ ] { VariableNameControl } , editor ) ) ;
76
+ RenderedControls . Add ( VariableNameControl ) ;
77
+
78
+ return RenderedControls ;
79
+ }
80
+ public override string GetDisplayValue ( )
81
+ {
82
+ return base . GetDisplayValue ( ) + " [From: '" + v_SourceFolderPath + "', Store In: '" + v_UserVariableName + "']" ;
83
+ }
84
+ }
85
+ }
0 commit comments