Skip to content

Commit c7f83f8

Browse files
committed
Outlook Get, Move, Copy and Delete commands
1 parent e19461c commit c7f83f8

11 files changed

+539
-18
lines changed

taskt/Core/Automation/Commands/CreateFolderCommand.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,18 @@ public override void RunCommand(object sender)
5656
var destinationDirectory = v_DestinationDirectory.ConvertToUserVariable(sender);
5757
var newFolder = v_NewFolderName.ConvertToUserVariable(sender);
5858

59+
60+
var finalPath = System.IO.Path.Combine(destinationDirectory, newFolder);
5961
//delete folder if it exists AND the delete option is selected
6062
if (v_DeleteExisting == "Yes" && System.IO.Directory.Exists(destinationDirectory + "\\" + newFolder))
6163
{
62-
System.IO.Directory.Delete(destinationDirectory + "\\" + newFolder, true);
64+
System.IO.Directory.Delete(finalPath, true);
6365
}
6466

6567
//create folder if it doesn't exist
66-
if (!System.IO.Directory.Exists(destinationDirectory + "\\" + newFolder))
68+
if (!System.IO.Directory.Exists(finalPath))
6769
{
68-
System.IO.Directory.CreateDirectory(destinationDirectory + "\\" + newFolder);
70+
System.IO.Directory.CreateDirectory(finalPath);
6971
}
7072

7173
}
@@ -82,7 +84,7 @@ public override List<Control> Render(frmCommandEditor editor)
8284

8385
public override string GetDisplayValue()
8486
{
85-
return base.GetDisplayValue() + " [create " + v_DestinationDirectory + "\\" + v_NewFolderName +"']";
87+
return base.GetDisplayValue() + "[create " + v_DestinationDirectory + "\\" + v_NewFolderName +"']";
8688
}
8789
}
8890
}

taskt/Core/Automation/Commands/DeleteFolderCommand.cs

-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ namespace taskt.Core.Automation.Commands
1515
[Attributes.ClassAttributes.ImplementationDescription("This command implements '' to achieve automation.")]
1616
public class DeleteFolderCommand : ScriptCommand
1717
{
18-
1918
[XmlAttribute]
2019
[Attributes.PropertyAttributes.PropertyDescription("Please indicate the path to the source folder")]
2120
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
@@ -25,8 +24,6 @@ public class DeleteFolderCommand : ScriptCommand
2524
[Attributes.PropertyAttributes.Remarks("")]
2625
public string v_SourceFolderPath { get; set; }
2726

28-
29-
3027
public DeleteFolderCommand()
3128
{
3229
this.CommandName = "DeleteFolderCommand";
@@ -53,9 +50,6 @@ public override List<Control> Render(frmCommandEditor editor)
5350

5451
return RenderedControls;
5552
}
56-
57-
58-
5953
public override string GetDisplayValue()
6054
{
6155
return base.GetDisplayValue() + " [delete " + v_SourceFolderPath + "']";

taskt/Core/Automation/Commands/MoveFolderCommand.cs

+2-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class MoveFolderCommand : ScriptCommand
1919
[Attributes.PropertyAttributes.PropertyDescription("Indicate whether to move or copy the folder")]
2020
[Attributes.PropertyAttributes.PropertyUISelectionOption("Move Folder")]
2121
[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 file from the original path while Copying will not.")]
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.")]
2323
[Attributes.PropertyAttributes.SampleUsage("Select either **Move Folder** or **Copy Folder**")]
2424
[Attributes.PropertyAttributes.Remarks("")]
2525
public string v_OperationType { get; set; }
@@ -60,7 +60,6 @@ public class MoveFolderCommand : ScriptCommand
6060
[Attributes.PropertyAttributes.Remarks("")]
6161
public string v_DeleteExisting { get; set; }
6262

63-
6463
public MoveFolderCommand()
6564
{
6665
this.CommandName = "MoveFolderCommand";
@@ -71,7 +70,6 @@ public MoveFolderCommand()
7170

7271
public override void RunCommand(object sender)
7372
{
74-
7573
//apply variable logic
7674
var sourceFolder = v_SourceFolderPath.ConvertToUserVariable(sender);
7775
var destinationFolder = v_DestinationDirectory.ConvertToUserVariable(sender);
@@ -105,8 +103,7 @@ public override void RunCommand(object sender)
105103
}
106104

107105
}
108-
109-
private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
106+
private void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
110107
{
111108
// Get the subdirectories for the specified directory.
112109
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
using System;
2+
using System.Linq;
3+
using System.Xml.Serialization;
4+
using System.Data;
5+
using System.Windows.Forms;
6+
using System.Collections.Generic;
7+
using taskt.UI.Forms;
8+
using taskt.UI.CustomControls;
9+
using Microsoft.Office.Interop.Outlook;
10+
using Application = Microsoft.Office.Interop.Outlook.Application;
11+
12+
namespace taskt.Core.Automation.Commands
13+
{
14+
[Serializable]
15+
[Attributes.ClassAttributes.Group("Outlook Commands")]
16+
[Attributes.ClassAttributes.Description("This command allows you to manipulate emails with outlook")]
17+
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to manipulate emails with your currenty logged in outlook account")]
18+
[Attributes.ClassAttributes.ImplementationDescription("")]
19+
20+
public class OutlookDeleteEmailsCommand : ScriptCommand
21+
{
22+
[XmlAttribute]
23+
[Attributes.PropertyAttributes.PropertyDescription("Provide the source mail folder name")]
24+
[Attributes.PropertyAttributes.InputSpecification("Enter the mail folder you want your emails to come from")]
25+
[Attributes.PropertyAttributes.SampleUsage("**myData**")]
26+
[Attributes.PropertyAttributes.Remarks("")]
27+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
28+
public string v_SourceFolder { get; set; }
29+
30+
[XmlAttribute]
31+
[Attributes.PropertyAttributes.PropertyDescription("Provide a filter (Optional)")]
32+
[Attributes.PropertyAttributes.InputSpecification("Enter an outlook filter string")]
33+
[Attributes.PropertyAttributes.SampleUsage("[Subject] = 'Hello'")]
34+
[Attributes.PropertyAttributes.Remarks("")]
35+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
36+
public string v_Filter { get; set; }
37+
38+
[XmlAttribute]
39+
[Attributes.PropertyAttributes.PropertyDescription("Delete read emails only")]
40+
[Attributes.PropertyAttributes.PropertyUISelectionOption("Yes")]
41+
[Attributes.PropertyAttributes.PropertyUISelectionOption("No")]
42+
[Attributes.PropertyAttributes.InputSpecification("Specify whether to delete read email messages only")]
43+
[Attributes.PropertyAttributes.SampleUsage("Select **Yes** or **No**")]
44+
[Attributes.PropertyAttributes.Remarks("")]
45+
public string v_DeleteReadOnly { get; set; }
46+
47+
public OutlookDeleteEmailsCommand()
48+
{
49+
this.CommandName = "OutlookDeleteEmailsCommand";
50+
this.SelectionName = "Delete Outlook Emails";
51+
this.CommandEnabled = true;
52+
this.CustomRendering = true;
53+
}
54+
public override void RunCommand(object sender)
55+
{
56+
var engine = (Engine.AutomationEngineInstance)sender;
57+
var vSourceFolder = v_SourceFolder.ConvertToUserVariable(sender);
58+
var vFilter = v_Filter.ConvertToUserVariable(sender);
59+
60+
Application outlookApp = new Application();
61+
AddressEntry currentUser = outlookApp.Session.CurrentUser.AddressEntry;
62+
NameSpace test = outlookApp.GetNamespace("MAPI");
63+
64+
if (currentUser.Type == "EX")
65+
{
66+
MAPIFolder inboxFolder = test.GetDefaultFolder(OlDefaultFolders.olFolderInbox).Parent;
67+
MAPIFolder sourceFolder = inboxFolder.Folders[vSourceFolder];
68+
Items filteredItems = null;
69+
70+
if (vFilter != "")
71+
{
72+
filteredItems = sourceFolder.Items.Restrict(vFilter);
73+
}
74+
else
75+
{
76+
filteredItems = sourceFolder.Items;
77+
}
78+
79+
List<MailItem> tempItems = new List<MailItem>();
80+
foreach (object _obj in filteredItems)
81+
{
82+
if (_obj is MailItem)
83+
{
84+
MailItem tempMail = (MailItem)_obj;
85+
86+
if (v_DeleteReadOnly == "Yes")
87+
{
88+
if (tempMail.UnRead == false)
89+
{
90+
tempItems.Add(tempMail);
91+
}
92+
}
93+
else
94+
{
95+
tempItems.Add(tempMail);
96+
}
97+
}
98+
}
99+
int count = tempItems.Count;
100+
for (int i = 0; i < count; i++)
101+
{
102+
tempItems[i].Delete();
103+
}
104+
}
105+
}
106+
107+
public override List<Control> Render(frmCommandEditor editor)
108+
{
109+
base.Render(editor);
110+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_SourceFolder", this, editor));
111+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_Filter", this, editor));
112+
RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_DeleteReadOnly", this, editor));
113+
return RenderedControls;
114+
}
115+
116+
public override string GetDisplayValue()
117+
{
118+
return base.GetDisplayValue() + $" [From: {v_SourceFolder}]";
119+
}
120+
}
121+
}

taskt/Core/Automation/Commands/OutlookEmailCommand.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ namespace taskt.Core.Automation.Commands
1010
{
1111
[Serializable]
1212
[Attributes.ClassAttributes.Group("Outlook Commands")]
13-
[Attributes.ClassAttributes.Description("This command allows you to send an email with outlook")]
14-
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to send an email with your currenty logged in outlook account")]
13+
[Attributes.ClassAttributes.Description("This command allows you to manipulate emails with outlook")]
14+
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to manipulate emails with your currenty logged in outlook account")]
1515
[Attributes.ClassAttributes.ImplementationDescription("")]
1616
public class OutlookEmailCommand : ScriptCommand
1717
{
@@ -24,11 +24,12 @@ public class OutlookEmailCommand : ScriptCommand
2424
public string v_Recipients { get; set; }
2525

2626
[XmlAttribute]
27-
[Attributes.PropertyAttributes.PropertyDescription("Optional - Attachment File Path")]
27+
[Attributes.PropertyAttributes.PropertyDescription("Attachment File Path (Optional)")]
2828
[Attributes.PropertyAttributes.InputSpecification("Enter the Filepath of the file you want attached.")]
2929
[Attributes.PropertyAttributes.SampleUsage("c:sales reports\fy06q4.xlsx")]
3030
[Attributes.PropertyAttributes.Remarks("")]
3131
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
32+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFileSelectionHelper)]
3233
public string v_Attachment { get; set; }
3334

3435
[XmlAttribute]

0 commit comments

Comments
 (0)