Skip to content

Commit 3744451

Browse files
committed
Added GetFIlesCommand and GetFoldersCommand
1 parent 290aa85 commit 3744451

File tree

5 files changed

+176
-0
lines changed

5 files changed

+176
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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("File Operation Commands")]
14+
[Attributes.ClassAttributes.Description("This command returns a list of file paths from a specified destination")]
15+
[Attributes.ClassAttributes.UsesDescription("Use this command to return a list of file paths from a specific location.")]
16+
[Attributes.ClassAttributes.ImplementationDescription("This command implements '' to achieve automation.")]
17+
public class GetFilesCommand : 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 GetFilesCommand()
36+
{
37+
this.CommandName = "GetFilesCommand";
38+
this.SelectionName = "Get Files";
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 filesList = System.IO.Directory.GetFiles(sourceFolder).ToList();
52+
53+
Script.ScriptVariable newFilesList = new Script.ScriptVariable
54+
{
55+
VariableName = v_UserVariableName,
56+
VariableValue = filesList
57+
};
58+
//Overwrites variable if it already exists
59+
if (engine.VariableList.Exists(x => x.VariableName == newFilesList.VariableName))
60+
{
61+
Script.ScriptVariable temp = engine.VariableList.Where(x => x.VariableName == newFilesList.VariableName).FirstOrDefault();
62+
engine.VariableList.Remove(temp);
63+
}
64+
engine.VariableList.Add(newFilesList);
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
}

taskt/Core/Automation/Commands/ScriptCommand.cs

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ namespace taskt.Core.Automation.Commands
107107
[XmlInclude(typeof(DeleteFileCommand))]
108108
[XmlInclude(typeof(RenameFileCommand))]
109109
[XmlInclude(typeof(WaitForFileToExistCommand))]
110+
[XmlInclude(typeof(GetFilesCommand))]
111+
[XmlInclude(typeof(GetFoldersCommand))]
110112
[XmlInclude(typeof(CreateFolderCommand))]
111113
[XmlInclude(typeof(DeleteFolderCommand))]
112114
[XmlInclude(typeof(MoveFolderCommand))]

taskt/UI/CustomControls/CustomControls.cs

+2
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,8 @@ public static Dictionary<string, Image> UIImageDictionary()
539539
uiImages.Add("DeleteFileCommand", taskt.Properties.Resources.command_files);
540540
uiImages.Add("RenameFileCommand", taskt.Properties.Resources.command_files);
541541
uiImages.Add("WaitForFileToExistCommand", taskt.Properties.Resources.command_files);
542+
uiImages.Add("GetFilesCommand", taskt.Properties.Resources.command_files);
543+
uiImages.Add("GetFoldersCommand", taskt.Properties.Resources.command_files);
542544
uiImages.Add("CreateFolderCommand", taskt.Properties.Resources.command_files);
543545
uiImages.Add("DeleteFolderCommand", taskt.Properties.Resources.command_files);
544546
uiImages.Add("MoveFolderCommand", taskt.Properties.Resources.command_files);

taskt/taskt.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@
175175
<Compile Include="Core\Automation\Commands\DeleteFolderCommand.cs" />
176176
<Compile Include="Core\Automation\Commands\ExcelSplitRangeByColumnCommand.cs" />
177177
<Compile Include="Core\Automation\Commands\ExtractFileCommand.cs" />
178+
<Compile Include="Core\Automation\Commands\GetFilesCommand.cs" />
179+
<Compile Include="Core\Automation\Commands\GetFoldersCommand.cs" />
178180
<Compile Include="Core\Automation\Commands\MoveFolderCommand.cs" />
179181
<Compile Include="Core\Automation\Commands\NextLoopCommand.cs" />
180182
<Compile Include="Core\Automation\Commands\OutlookDeleteEmailsCommand.cs" />

0 commit comments

Comments
 (0)