Skip to content

Commit

Permalink
Create, Delete, Move/Copy Folder commands completed
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesca Faerman committed Mar 7, 2020
1 parent a126fed commit c9f45ac
Show file tree
Hide file tree
Showing 8 changed files with 351 additions and 0 deletions.
1 change: 1 addition & 0 deletions taskt/Core/Automation/Attributes/Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public enum UIAdditionalHelperType
{
ShowVariableHelper,
ShowFileSelectionHelper,
ShowFolderSelectionHelper, //FF
ShowImageRecogitionHelper,
ShowCodeBuilder,
ShowMouseCaptureHelper,
Expand Down
88 changes: 88 additions & 0 deletions taskt/Core/Automation/Commands/CreateFolderCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Xml.Serialization;
using taskt.UI.CustomControls;
using taskt.UI.Forms;

namespace taskt.Core.Automation.Commands
{

[Serializable]
[Attributes.ClassAttributes.Group("Folder Operation Commands")]
[Attributes.ClassAttributes.Description("This command creates a folder in a specified destination")]
[Attributes.ClassAttributes.UsesDescription("Use this command to create a folder in a specific location.")]
[Attributes.ClassAttributes.ImplementationDescription("This command implements '' to achieve automation.")]
public class CreateFolderCommand : ScriptCommand
{
[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Please indicate the name of the new folder")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
[Attributes.PropertyAttributes.InputSpecification("Enter the name of the new folder.")]
[Attributes.PropertyAttributes.SampleUsage("myFolderName or [vFolderName]")]
[Attributes.PropertyAttributes.Remarks("")]
public string v_NewFolderName { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Please indicate the directory for the new 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 directory.")]
[Attributes.PropertyAttributes.SampleUsage("C:\\temp\\myfolder or [vTextFolderPath]")]
[Attributes.PropertyAttributes.Remarks("")]
public string v_DestinationDirectory { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Delete folder if it already exists")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Yes")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("No")]
[Attributes.PropertyAttributes.InputSpecification("Specify whether the folder should be deleted first if it is already found to exist.")]
[Attributes.PropertyAttributes.SampleUsage("Select **Yes** or **No**")]
[Attributes.PropertyAttributes.Remarks("")]
public string v_DeleteExisting { get; set; }

public CreateFolderCommand()
{
this.CommandName = "CreateFolderCommand";
this.SelectionName = "Create Folder";
this.CommandEnabled = true;
this.CustomRendering = true;
}

public override void RunCommand(object sender)
{

//apply variable logic
var destinationDirectory = v_DestinationDirectory.ConvertToUserVariable(sender);
var newFolder = v_NewFolderName.ConvertToUserVariable(sender);

//delete folder if it exists AND the delete option is selected
if (v_DeleteExisting == "Yes" && System.IO.Directory.Exists(destinationDirectory + "\\" + newFolder))
{
System.IO.Directory.Delete(destinationDirectory + "\\" + newFolder, true);
}

//create folder if it doesn't exist
if (!System.IO.Directory.Exists(destinationDirectory + "\\" + newFolder))
{
System.IO.Directory.CreateDirectory(destinationDirectory + "\\" + newFolder);
}

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

RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DestinationDirectory", this, editor));
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_NewFolderName", this, editor));
RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_DeleteExisting", this, editor));

return RenderedControls;
}

public override string GetDisplayValue()
{
return base.GetDisplayValue() + " [create " + v_DestinationDirectory + "\\" + v_NewFolderName +"']";
}
}
}
64 changes: 64 additions & 0 deletions taskt/Core/Automation/Commands/DeleteFolderCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Xml.Serialization;
using taskt.UI.CustomControls;
using taskt.UI.Forms;

namespace taskt.Core.Automation.Commands
{

[Serializable]
[Attributes.ClassAttributes.Group("Folder Operation Commands")]
[Attributes.ClassAttributes.Description("This command deletes a folder from a specified destination")]
[Attributes.ClassAttributes.UsesDescription("Use this command to delete a folder from a specific location.")]
[Attributes.ClassAttributes.ImplementationDescription("This command implements '' to achieve automation.")]
public class DeleteFolderCommand : 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; }



public DeleteFolderCommand()
{
this.CommandName = "DeleteFolderCommand";
this.SelectionName = "Delete Folder";
this.CommandEnabled = true;
this.CustomRendering = true;
}

public override void RunCommand(object sender)
{

//apply variable logic
var sourceFolder = v_SourceFolderPath.ConvertToUserVariable(sender);

//delete folder
System.IO.Directory.Delete(sourceFolder, true);

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

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

return RenderedControls;
}



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

namespace taskt.Core.Automation.Commands
{
[Serializable]
[Attributes.ClassAttributes.Group("Folder Operation Commands")]
[Attributes.ClassAttributes.Description("This command moves a folder to a specified destination")]
[Attributes.ClassAttributes.UsesDescription("Use this command to move a folder to a new destination.")]
[Attributes.ClassAttributes.ImplementationDescription("This command implements '' to achieve automation.")]
public class MoveFolderCommand : ScriptCommand
{
[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Indicate whether to move or copy the folder")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Move Folder")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Copy Folder")]
[Attributes.PropertyAttributes.InputSpecification("Specify whether you intend to move the folder or copy the folder. Moving will remove the file from the original path while Copying will not.")]
[Attributes.PropertyAttributes.SampleUsage("Select either **Move Folder** or **Copy Folder**")]
[Attributes.PropertyAttributes.Remarks("")]
public string v_OperationType { get; set; }

[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("Please indicate the directory to move/copy to")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFolderSelectionHelper)]
[Attributes.PropertyAttributes.InputSpecification("Enter or Select the new path to the file.")]
[Attributes.PropertyAttributes.SampleUsage("C:\\temp\\new path or [vTextFolderPath]")]
[Attributes.PropertyAttributes.Remarks("")]
public string v_DestinationDirectory { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Create folder if destination does not exist")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Yes")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("No")]
[Attributes.PropertyAttributes.InputSpecification("Specify whether the directory should be created if it does not already exist.")]
[Attributes.PropertyAttributes.SampleUsage("Select **Yes** or **No**")]
[Attributes.PropertyAttributes.Remarks("")]
public string v_CreateDirectory { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Delete folder if it already exists")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Yes")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("No")]
[Attributes.PropertyAttributes.InputSpecification("Specify whether the folder should be deleted first if it is already found to exist.")]
[Attributes.PropertyAttributes.SampleUsage("Select **Yes** or **No**")]
[Attributes.PropertyAttributes.Remarks("")]
public string v_DeleteExisting { get; set; }


public MoveFolderCommand()
{
this.CommandName = "MoveFolderCommand";
this.SelectionName = "Move/Copy Folder";
this.CommandEnabled = true;
this.CustomRendering = true;
}

public override void RunCommand(object sender)
{

//apply variable logic
var sourceFolder = v_SourceFolderPath.ConvertToUserVariable(sender);
var destinationFolder = v_DestinationDirectory.ConvertToUserVariable(sender);

if ((v_CreateDirectory == "Yes") && (!System.IO.Directory.Exists(destinationFolder)))
{
Directory.CreateDirectory(destinationFolder);
}

//get source folder name and info
DirectoryInfo sourceFolderInfo = new DirectoryInfo(sourceFolder);

//create final path
var finalPath = System.IO.Path.Combine(destinationFolder, sourceFolderInfo.Name);

//delete if it already exists per user
if (v_DeleteExisting == "Yes" && System.IO.Directory.Exists(finalPath))
{
Directory.Delete(finalPath, true);
}

if (v_OperationType == "Move Folder")
{
//move folder
Directory.Move(sourceFolder, finalPath);
}
else if (v_OperationType == "Copy Folder")
{
//copy folder
DirectoryCopy(sourceFolder, finalPath, true);
}

}

private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
{
// Get the subdirectories for the specified directory.
DirectoryInfo dir = new DirectoryInfo(sourceDirName);

if (!dir.Exists)
{
throw new DirectoryNotFoundException(
"Source directory does not exist or could not be found: "
+ sourceDirName);
}

DirectoryInfo[] dirs = dir.GetDirectories();
// If the destination directory doesn't exist, create it.
Directory.GetParent(destDirName);
if (!Directory.GetParent(destDirName).Exists)
{
throw new DirectoryNotFoundException(
"Destination directory does not exist or could not be found: "
+ Directory.GetParent(destDirName));
}

if (!Directory.Exists(destDirName))
{
Directory.CreateDirectory(destDirName);
}

// Get the files in the directory and copy them to the new location.
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
string temppath = Path.Combine(destDirName, file.Name);
file.CopyTo(temppath, false);
}

// If copying subdirectories, copy them and their contents to new location.
if (copySubDirs)
{
foreach (DirectoryInfo subdir in dirs)
{
string temppath = Path.Combine(destDirName, subdir.Name);
DirectoryCopy(subdir.FullName, temppath, copySubDirs);
}
}
}
public override List<Control> Render(frmCommandEditor editor)
{
base.Render(editor);

RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_OperationType", this, editor));
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_SourceFolderPath", this, editor));
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DestinationDirectory", this, editor));
RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_CreateDirectory", this, editor));
RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_DeleteExisting", this, editor));
return RenderedControls;
}

public override string GetDisplayValue()
{
return base.GetDisplayValue() + " [" + v_OperationType + " from '" + v_SourceFolderPath + "' to '" + v_DestinationDirectory + "']";
}
}
}
3 changes: 3 additions & 0 deletions taskt/Core/Automation/Commands/ScriptCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ namespace taskt.Core.Automation.Commands
[XmlInclude(typeof(DeleteFileCommand))]
[XmlInclude(typeof(RenameFileCommand))]
[XmlInclude(typeof(WaitForFileToExistCommand))]
[XmlInclude(typeof(CreateFolderCommand))]
[XmlInclude(typeof(DeleteFolderCommand))]
[XmlInclude(typeof(MoveFolderCommand))]
[XmlInclude(typeof(RunCustomCodeCommand))]
[XmlInclude(typeof(DateCalculationCommand))]
[XmlInclude(typeof(RegExExtractorCommand))]
Expand Down
18 changes: 18 additions & 0 deletions taskt/UI/CustomControls/CommandControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ public static List<Control> CreateUIHelpersFor(string parameterName, Core.Automa
helperControl.Click += (sender, e) => ShowFileSelector(sender, e, editor);
break;

case Core.Automation.Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFolderSelectionHelper: //FF
//show file selector
helperControl.CommandImage = UI.Images.GetUIImage("ClipboardGetTextCommand");
helperControl.CommandDisplay = "Select a Folder";
helperControl.Click += (sender, e) => ShowFolderSelector(sender, e, editor);
break;

case Core.Automation.Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowImageRecogitionHelper:
//show file selector
helperControl.CommandImage = UI.Images.GetUIImage("OCRCommand");
Expand Down Expand Up @@ -382,6 +389,17 @@ private static void ShowFileSelector(object sender, EventArgs e, UI.Forms.frmCom
targetTextbox.Text = ofd.FileName;
}
}
private static void ShowFolderSelector(object sender, EventArgs e, UI.Forms.frmCommandEditor editor) //FF
{
FolderBrowserDialog fbd = new FolderBrowserDialog();

if(fbd.ShowDialog() == DialogResult.OK)
{
CustomControls.CommandItemControl inputBox = (CustomControls.CommandItemControl)sender;
TextBox targetTextBox = (TextBox)inputBox.Tag;
targetTextBox.Text = fbd.SelectedPath;
}
}
private static void ShowImageCapture(object sender, EventArgs e)
{

Expand Down
3 changes: 3 additions & 0 deletions taskt/UI/CustomControls/CustomControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,9 @@ 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("CreateFolderCommand", taskt.Properties.Resources.command_files);
uiImages.Add("DeleteFolderCommand", taskt.Properties.Resources.command_files);
uiImages.Add("MoveFolderCommand", taskt.Properties.Resources.command_files);
uiImages.Add("LogDataCommand", taskt.Properties.Resources.command_files);
uiImages.Add("ExecuteDLLCommand", taskt.Properties.Resources.command_run_code);
uiImages.Add("RESTCommand", taskt.Properties.Resources.command_run_code);
Expand Down
3 changes: 3 additions & 0 deletions taskt/taskt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@
<Compile Include="Core\Automation\Commands\AddDictionaryCommand.cs" />
<Compile Include="Core\Automation\Commands\CreateDictionaryCommand.cs" />
<Compile Include="Core\Automation\Commands\BeginMutliIfCommand.cs" />
<Compile Include="Core\Automation\Commands\CreateFolderCommand.cs" />
<Compile Include="Core\Automation\Commands\DeleteFolderCommand.cs" />
<Compile Include="Core\Automation\Commands\ExtractFileCommand.cs" />
<Compile Include="Core\Automation\Commands\MoveFolderCommand.cs" />
<Compile Include="Core\Automation\Commands\NextLoopCommand.cs" />
<Compile Include="Core\Automation\Commands\OutlookEmailCommand.cs" />
<Compile Include="Core\Automation\Commands\GetRegexMatchesCommand.cs" />
Expand Down

0 comments on commit c9f45ac

Please sign in to comment.