Skip to content

Commit

Permalink
Added GetFIlesCommand and GetFoldersCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
openbots-ff committed Mar 20, 2020
1 parent 290aa85 commit 3744451
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 0 deletions.
85 changes: 85 additions & 0 deletions taskt/Core/Automation/Commands/GetFilesCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Xml.Serialization;
using taskt.UI.CustomControls;
using taskt.UI.Forms;
using System.Linq;

namespace taskt.Core.Automation.Commands
{

[Serializable]
[Attributes.ClassAttributes.Group("File Operation Commands")]
[Attributes.ClassAttributes.Description("This command returns a list of file paths from a specified destination")]
[Attributes.ClassAttributes.UsesDescription("Use this command to return a list of file paths from a specific location.")]
[Attributes.ClassAttributes.ImplementationDescription("This command implements '' to achieve automation.")]
public class GetFilesCommand : ScriptCommand
{
[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Please indicate the path to the source folder")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFolderSelectionHelper)]
[Attributes.PropertyAttributes.InputSpecification("Enter or Select the path to the folder.")]
[Attributes.PropertyAttributes.SampleUsage("C:\\temp\\myfolder or [vTextFolderPath]")]
[Attributes.PropertyAttributes.Remarks("")]
public string v_SourceFolderPath { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Assign to Variable")]
[Attributes.PropertyAttributes.InputSpecification("Select or provide a variable from the variable list")]
[Attributes.PropertyAttributes.SampleUsage("**vSomeVariable**")]
[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.")]
public string v_UserVariableName { get; set; }

public GetFilesCommand()
{
this.CommandName = "GetFilesCommand";
this.SelectionName = "Get Files";
this.CommandEnabled = true;
this.CustomRendering = true;
}

public override void RunCommand(object sender)
{
var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;
//apply variable logic
var sourceFolder = v_SourceFolderPath.ConvertToUserVariable(sender);

//delete folder
//System.IO.Directory.Delete(sourceFolder, true);
var filesList = System.IO.Directory.GetFiles(sourceFolder).ToList();

Script.ScriptVariable newFilesList = new Script.ScriptVariable
{
VariableName = v_UserVariableName,
VariableValue = filesList
};
//Overwrites variable if it already exists
if (engine.VariableList.Exists(x => x.VariableName == newFilesList.VariableName))
{
Script.ScriptVariable temp = engine.VariableList.Where(x => x.VariableName == newFilesList.VariableName).FirstOrDefault();
engine.VariableList.Remove(temp);
}
engine.VariableList.Add(newFilesList);

}
public override List<Control> Render(frmCommandEditor editor)
{
base.Render(editor);

RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_SourceFolderPath", this, editor));

RenderedControls.Add(CommandControls.CreateDefaultLabelFor("v_UserVariableName", this));
var VariableNameControl = CommandControls.CreateStandardComboboxFor("v_UserVariableName", this).AddVariableNames(editor);
RenderedControls.AddRange(CommandControls.CreateUIHelpersFor("v_UserVariableName", this, new Control[] { VariableNameControl }, editor));
RenderedControls.Add(VariableNameControl);

return RenderedControls;
}
public override string GetDisplayValue()
{
return base.GetDisplayValue() + " [From: '" + v_SourceFolderPath + "', Store In: '" + v_UserVariableName + "']";
}
}
}
85 changes: 85 additions & 0 deletions taskt/Core/Automation/Commands/GetFoldersCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Xml.Serialization;
using taskt.UI.CustomControls;
using taskt.UI.Forms;
using System.Linq;

namespace taskt.Core.Automation.Commands
{

[Serializable]
[Attributes.ClassAttributes.Group("Folder Operation Commands")]
[Attributes.ClassAttributes.Description("This command returns a list of folder directories from a specified destination")]
[Attributes.ClassAttributes.UsesDescription("Use this command to return a list of folder directories from a specific location.")]
[Attributes.ClassAttributes.ImplementationDescription("This command implements '' to achieve automation.")]
public class GetFoldersCommand : ScriptCommand
{
[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Please indicate the path to the source folder")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFolderSelectionHelper)]
[Attributes.PropertyAttributes.InputSpecification("Enter or Select the path to the folder.")]
[Attributes.PropertyAttributes.SampleUsage("C:\\temp\\myfolder or [vTextFolderPath]")]
[Attributes.PropertyAttributes.Remarks("")]
public string v_SourceFolderPath { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Assign to Variable")]
[Attributes.PropertyAttributes.InputSpecification("Select or provide a variable from the variable list")]
[Attributes.PropertyAttributes.SampleUsage("**vSomeVariable**")]
[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.")]
public string v_UserVariableName { get; set; }

public GetFoldersCommand()
{
this.CommandName = "GetFoldersCommand";
this.SelectionName = "Get Folders";
this.CommandEnabled = true;
this.CustomRendering = true;
}

public override void RunCommand(object sender)
{
var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;
//apply variable logic
var sourceFolder = v_SourceFolderPath.ConvertToUserVariable(sender);

//delete folder
//System.IO.Directory.Delete(sourceFolder, true);
var directoriesList = System.IO.Directory.GetDirectories(sourceFolder).ToList();

Script.ScriptVariable newDirectoriesList = new Script.ScriptVariable
{
VariableName = v_UserVariableName,
VariableValue = directoriesList
};
//Overwrites variable if it already exists
if (engine.VariableList.Exists(x => x.VariableName == newDirectoriesList.VariableName))
{
Script.ScriptVariable temp = engine.VariableList.Where(x => x.VariableName == newDirectoriesList.VariableName).FirstOrDefault();
engine.VariableList.Remove(temp);
}
engine.VariableList.Add(newDirectoriesList);

}
public override List<Control> Render(frmCommandEditor editor)
{
base.Render(editor);

RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_SourceFolderPath", this, editor));

RenderedControls.Add(CommandControls.CreateDefaultLabelFor("v_UserVariableName", this));
var VariableNameControl = CommandControls.CreateStandardComboboxFor("v_UserVariableName", this).AddVariableNames(editor);
RenderedControls.AddRange(CommandControls.CreateUIHelpersFor("v_UserVariableName", this, new Control[] { VariableNameControl }, editor));
RenderedControls.Add(VariableNameControl);

return RenderedControls;
}
public override string GetDisplayValue()
{
return base.GetDisplayValue() + " [From: '" + v_SourceFolderPath + "', Store In: '"+ v_UserVariableName +"']";
}
}
}
2 changes: 2 additions & 0 deletions taskt/Core/Automation/Commands/ScriptCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ namespace taskt.Core.Automation.Commands
[XmlInclude(typeof(DeleteFileCommand))]
[XmlInclude(typeof(RenameFileCommand))]
[XmlInclude(typeof(WaitForFileToExistCommand))]
[XmlInclude(typeof(GetFilesCommand))]
[XmlInclude(typeof(GetFoldersCommand))]
[XmlInclude(typeof(CreateFolderCommand))]
[XmlInclude(typeof(DeleteFolderCommand))]
[XmlInclude(typeof(MoveFolderCommand))]
Expand Down
2 changes: 2 additions & 0 deletions taskt/UI/CustomControls/CustomControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,8 @@ public static Dictionary<string, Image> UIImageDictionary()
uiImages.Add("DeleteFileCommand", taskt.Properties.Resources.command_files);
uiImages.Add("RenameFileCommand", taskt.Properties.Resources.command_files);
uiImages.Add("WaitForFileToExistCommand", taskt.Properties.Resources.command_files);
uiImages.Add("GetFilesCommand", taskt.Properties.Resources.command_files);
uiImages.Add("GetFoldersCommand", taskt.Properties.Resources.command_files);
uiImages.Add("CreateFolderCommand", taskt.Properties.Resources.command_files);
uiImages.Add("DeleteFolderCommand", taskt.Properties.Resources.command_files);
uiImages.Add("MoveFolderCommand", taskt.Properties.Resources.command_files);
Expand Down
2 changes: 2 additions & 0 deletions taskt/taskt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@
<Compile Include="Core\Automation\Commands\DeleteFolderCommand.cs" />
<Compile Include="Core\Automation\Commands\ExcelSplitRangeByColumnCommand.cs" />
<Compile Include="Core\Automation\Commands\ExtractFileCommand.cs" />
<Compile Include="Core\Automation\Commands\GetFilesCommand.cs" />
<Compile Include="Core\Automation\Commands\GetFoldersCommand.cs" />
<Compile Include="Core\Automation\Commands\MoveFolderCommand.cs" />
<Compile Include="Core\Automation\Commands\NextLoopCommand.cs" />
<Compile Include="Core\Automation\Commands\OutlookDeleteEmailsCommand.cs" />
Expand Down

0 comments on commit 3744451

Please sign in to comment.