forked from saucepleez/taskt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create, Delete, Move/Copy Folder commands completed
- Loading branch information
Francesca Faerman
committed
Mar 7, 2020
1 parent
a126fed
commit c9f45ac
Showing
8 changed files
with
351 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 +"']"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + "']"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + "']"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters