Skip to content

Commit b6ab704

Browse files
committed
Merged development to TTB
2 parents 519c7c3 + b0fd1fa commit b6ab704

16 files changed

+1173
-3
lines changed

taskt/Core/Automation/Attributes/Attributes.cs

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public enum UIAdditionalHelperType
107107
{
108108
ShowVariableHelper,
109109
ShowFileSelectionHelper,
110+
ShowFolderSelectionHelper,
110111
ShowImageRecogitionHelper,
111112
ShowCodeBuilder,
112113
ShowMouseCaptureHelper,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
8+
namespace taskt.Core.Automation.Commands
9+
{
10+
11+
[Serializable]
12+
[Attributes.ClassAttributes.Group("Folder Operation Commands")]
13+
[Attributes.ClassAttributes.Description("This command creates a folder in a specified destination")]
14+
[Attributes.ClassAttributes.UsesDescription("Use this command to create a folder in a specific location.")]
15+
[Attributes.ClassAttributes.ImplementationDescription("This command implements '' to achieve automation.")]
16+
public class CreateFolderCommand : ScriptCommand
17+
{
18+
[XmlAttribute]
19+
[Attributes.PropertyAttributes.PropertyDescription("Please indicate the name of the new folder")]
20+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
21+
[Attributes.PropertyAttributes.InputSpecification("Enter the name of the new folder.")]
22+
[Attributes.PropertyAttributes.SampleUsage("myFolderName or [vFolderName]")]
23+
[Attributes.PropertyAttributes.Remarks("")]
24+
public string v_NewFolderName { get; set; }
25+
26+
[XmlAttribute]
27+
[Attributes.PropertyAttributes.PropertyDescription("Please indicate the directory for the new folder")]
28+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
29+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFolderSelectionHelper)]
30+
[Attributes.PropertyAttributes.InputSpecification("Enter or Select the path to the directory.")]
31+
[Attributes.PropertyAttributes.SampleUsage("C:\\temp\\myfolder or [vTextFolderPath]")]
32+
[Attributes.PropertyAttributes.Remarks("")]
33+
public string v_DestinationDirectory { get; set; }
34+
35+
[XmlAttribute]
36+
[Attributes.PropertyAttributes.PropertyDescription("Delete folder if it already exists")]
37+
[Attributes.PropertyAttributes.PropertyUISelectionOption("Yes")]
38+
[Attributes.PropertyAttributes.PropertyUISelectionOption("No")]
39+
[Attributes.PropertyAttributes.InputSpecification("Specify whether the folder should be deleted first if it is already found to exist.")]
40+
[Attributes.PropertyAttributes.SampleUsage("Select **Yes** or **No**")]
41+
[Attributes.PropertyAttributes.Remarks("")]
42+
public string v_DeleteExisting { get; set; }
43+
44+
public CreateFolderCommand()
45+
{
46+
this.CommandName = "CreateFolderCommand";
47+
this.SelectionName = "Create Folder";
48+
this.CommandEnabled = true;
49+
this.CustomRendering = true;
50+
}
51+
52+
public override void RunCommand(object sender)
53+
{
54+
55+
//apply variable logic
56+
var destinationDirectory = v_DestinationDirectory.ConvertToUserVariable(sender);
57+
var newFolder = v_NewFolderName.ConvertToUserVariable(sender);
58+
59+
60+
var finalPath = System.IO.Path.Combine(destinationDirectory, newFolder);
61+
//delete folder if it exists AND the delete option is selected
62+
if (v_DeleteExisting == "Yes" && System.IO.Directory.Exists(destinationDirectory + "\\" + newFolder))
63+
{
64+
System.IO.Directory.Delete(finalPath, true);
65+
}
66+
67+
//create folder if it doesn't exist
68+
if (!System.IO.Directory.Exists(finalPath))
69+
{
70+
System.IO.Directory.CreateDirectory(finalPath);
71+
}
72+
73+
}
74+
public override List<Control> Render(frmCommandEditor editor)
75+
{
76+
base.Render(editor);
77+
78+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DestinationDirectory", this, editor));
79+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_NewFolderName", this, editor));
80+
RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_DeleteExisting", this, editor));
81+
82+
return RenderedControls;
83+
}
84+
85+
public override string GetDisplayValue()
86+
{
87+
return base.GetDisplayValue() + "[create " + v_DestinationDirectory + "\\" + v_NewFolderName +"']";
88+
}
89+
}
90+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
8+
namespace taskt.Core.Automation.Commands
9+
{
10+
11+
[Serializable]
12+
[Attributes.ClassAttributes.Group("Folder Operation Commands")]
13+
[Attributes.ClassAttributes.Description("This command deletes a folder from a specified destination")]
14+
[Attributes.ClassAttributes.UsesDescription("Use this command to delete a folder from a specific location.")]
15+
[Attributes.ClassAttributes.ImplementationDescription("This command implements '' to achieve automation.")]
16+
public class DeleteFolderCommand : ScriptCommand
17+
{
18+
[XmlAttribute]
19+
[Attributes.PropertyAttributes.PropertyDescription("Please indicate the path to the source folder")]
20+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
21+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFolderSelectionHelper)]
22+
[Attributes.PropertyAttributes.InputSpecification("Enter or Select the path to the folder.")]
23+
[Attributes.PropertyAttributes.SampleUsage("C:\\temp\\myfolder or [vTextFolderPath]")]
24+
[Attributes.PropertyAttributes.Remarks("")]
25+
public string v_SourceFolderPath { get; set; }
26+
27+
public DeleteFolderCommand()
28+
{
29+
this.CommandName = "DeleteFolderCommand";
30+
this.SelectionName = "Delete Folder";
31+
this.CommandEnabled = true;
32+
this.CustomRendering = true;
33+
}
34+
35+
public override void RunCommand(object sender)
36+
{
37+
38+
//apply variable logic
39+
var sourceFolder = v_SourceFolderPath.ConvertToUserVariable(sender);
40+
41+
//delete folder
42+
System.IO.Directory.Delete(sourceFolder, true);
43+
44+
}
45+
public override List<Control> Render(frmCommandEditor editor)
46+
{
47+
base.Render(editor);
48+
49+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_SourceFolderPath", this, editor));
50+
51+
return RenderedControls;
52+
}
53+
public override string GetDisplayValue()
54+
{
55+
return base.GetDisplayValue() + " [delete " + v_SourceFolderPath + "']";
56+
}
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
using System;
2+
using System.Xml.Serialization;
3+
using System.IO;
4+
using System.Windows.Forms;
5+
using System.Collections.Generic;
6+
using taskt.UI.Forms;
7+
using taskt.UI.CustomControls;
8+
9+
namespace taskt.Core.Automation.Commands
10+
{
11+
[Serializable]
12+
[Attributes.ClassAttributes.Group("Folder Operation Commands")]
13+
[Attributes.ClassAttributes.Description("This command moves a folder to a specified destination")]
14+
[Attributes.ClassAttributes.UsesDescription("Use this command to move a folder to a new destination.")]
15+
[Attributes.ClassAttributes.ImplementationDescription("This command implements '' to achieve automation.")]
16+
public class MoveFolderCommand : ScriptCommand
17+
{
18+
[XmlAttribute]
19+
[Attributes.PropertyAttributes.PropertyDescription("Indicate whether to move or copy the folder")]
20+
[Attributes.PropertyAttributes.PropertyUISelectionOption("Move Folder")]
21+
[Attributes.PropertyAttributes.PropertyUISelectionOption("Copy Folder")]
22+
[Attributes.PropertyAttributes.InputSpecification("Specify whether you intend to move the folder or copy the folder. Moving will remove the folder from the original path while Copying will not.")]
23+
[Attributes.PropertyAttributes.SampleUsage("Select either **Move Folder** or **Copy Folder**")]
24+
[Attributes.PropertyAttributes.Remarks("")]
25+
public string v_OperationType { get; set; }
26+
27+
[XmlAttribute]
28+
[Attributes.PropertyAttributes.PropertyDescription("Please indicate the path to the source folder")]
29+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
30+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFolderSelectionHelper)]
31+
[Attributes.PropertyAttributes.InputSpecification("Enter or Select the path to the folder.")]
32+
[Attributes.PropertyAttributes.SampleUsage("C:\\temp\\myfolder or [vTextFolderPath]")]
33+
[Attributes.PropertyAttributes.Remarks("")]
34+
public string v_SourceFolderPath { get; set; }
35+
36+
[XmlAttribute]
37+
[Attributes.PropertyAttributes.PropertyDescription("Please indicate the directory to move/copy to")]
38+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
39+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFolderSelectionHelper)]
40+
[Attributes.PropertyAttributes.InputSpecification("Enter or Select the new path to the file.")]
41+
[Attributes.PropertyAttributes.SampleUsage("C:\\temp\\new path or [vTextFolderPath]")]
42+
[Attributes.PropertyAttributes.Remarks("")]
43+
public string v_DestinationDirectory { get; set; }
44+
45+
[XmlAttribute]
46+
[Attributes.PropertyAttributes.PropertyDescription("Create folder if destination does not exist")]
47+
[Attributes.PropertyAttributes.PropertyUISelectionOption("Yes")]
48+
[Attributes.PropertyAttributes.PropertyUISelectionOption("No")]
49+
[Attributes.PropertyAttributes.InputSpecification("Specify whether the directory should be created if it does not already exist.")]
50+
[Attributes.PropertyAttributes.SampleUsage("Select **Yes** or **No**")]
51+
[Attributes.PropertyAttributes.Remarks("")]
52+
public string v_CreateDirectory { get; set; }
53+
54+
[XmlAttribute]
55+
[Attributes.PropertyAttributes.PropertyDescription("Delete folder if it already exists")]
56+
[Attributes.PropertyAttributes.PropertyUISelectionOption("Yes")]
57+
[Attributes.PropertyAttributes.PropertyUISelectionOption("No")]
58+
[Attributes.PropertyAttributes.InputSpecification("Specify whether the folder should be deleted first if it is already found to exist.")]
59+
[Attributes.PropertyAttributes.SampleUsage("Select **Yes** or **No**")]
60+
[Attributes.PropertyAttributes.Remarks("")]
61+
public string v_DeleteExisting { get; set; }
62+
63+
public MoveFolderCommand()
64+
{
65+
this.CommandName = "MoveFolderCommand";
66+
this.SelectionName = "Move/Copy Folder";
67+
this.CommandEnabled = true;
68+
this.CustomRendering = true;
69+
}
70+
71+
public override void RunCommand(object sender)
72+
{
73+
//apply variable logic
74+
var sourceFolder = v_SourceFolderPath.ConvertToUserVariable(sender);
75+
var destinationFolder = v_DestinationDirectory.ConvertToUserVariable(sender);
76+
77+
if ((v_CreateDirectory == "Yes") && (!System.IO.Directory.Exists(destinationFolder)))
78+
{
79+
Directory.CreateDirectory(destinationFolder);
80+
}
81+
82+
//get source folder name and info
83+
DirectoryInfo sourceFolderInfo = new DirectoryInfo(sourceFolder);
84+
85+
//create final path
86+
var finalPath = System.IO.Path.Combine(destinationFolder, sourceFolderInfo.Name);
87+
88+
//delete if it already exists per user
89+
if (v_DeleteExisting == "Yes" && System.IO.Directory.Exists(finalPath))
90+
{
91+
Directory.Delete(finalPath, true);
92+
}
93+
94+
if (v_OperationType == "Move Folder")
95+
{
96+
//move folder
97+
Directory.Move(sourceFolder, finalPath);
98+
}
99+
else if (v_OperationType == "Copy Folder")
100+
{
101+
//copy folder
102+
DirectoryCopy(sourceFolder, finalPath, true);
103+
}
104+
105+
}
106+
private void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
107+
{
108+
// Get the subdirectories for the specified directory.
109+
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
110+
111+
if (!dir.Exists)
112+
{
113+
throw new DirectoryNotFoundException(
114+
"Source directory does not exist or could not be found: "
115+
+ sourceDirName);
116+
}
117+
118+
DirectoryInfo[] dirs = dir.GetDirectories();
119+
// If the destination directory doesn't exist, create it.
120+
Directory.GetParent(destDirName);
121+
if (!Directory.GetParent(destDirName).Exists)
122+
{
123+
throw new DirectoryNotFoundException(
124+
"Destination directory does not exist or could not be found: "
125+
+ Directory.GetParent(destDirName));
126+
}
127+
128+
if (!Directory.Exists(destDirName))
129+
{
130+
Directory.CreateDirectory(destDirName);
131+
}
132+
133+
// Get the files in the directory and copy them to the new location.
134+
FileInfo[] files = dir.GetFiles();
135+
foreach (FileInfo file in files)
136+
{
137+
string temppath = Path.Combine(destDirName, file.Name);
138+
file.CopyTo(temppath, false);
139+
}
140+
141+
// If copying subdirectories, copy them and their contents to new location.
142+
if (copySubDirs)
143+
{
144+
foreach (DirectoryInfo subdir in dirs)
145+
{
146+
string temppath = Path.Combine(destDirName, subdir.Name);
147+
DirectoryCopy(subdir.FullName, temppath, copySubDirs);
148+
}
149+
}
150+
}
151+
public override List<Control> Render(frmCommandEditor editor)
152+
{
153+
base.Render(editor);
154+
155+
RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_OperationType", this, editor));
156+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_SourceFolderPath", this, editor));
157+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DestinationDirectory", this, editor));
158+
RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_CreateDirectory", this, editor));
159+
RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_DeleteExisting", this, editor));
160+
return RenderedControls;
161+
}
162+
163+
public override string GetDisplayValue()
164+
{
165+
return base.GetDisplayValue() + " [" + v_OperationType + " from '" + v_SourceFolderPath + "' to '" + v_DestinationDirectory + "']";
166+
}
167+
}
168+
}

0 commit comments

Comments
 (0)