-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathCreateFolder.cs
More file actions
83 lines (75 loc) · 3.05 KB
/
Copy pathCreateFolder.cs
File metadata and controls
83 lines (75 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System.Threading.Tasks;
using Elsa.Workflows;
using Elsa.Workflows.Attributes;
using Elsa.Workflows.Models;
using Microsoft.Graph;
using Microsoft.Graph.Models;
namespace Elsa.Integrations.OneDrive.Activities;
/// <summary>
/// Creates a new folder in OneDrive.
/// </summary>
[Activity("Elsa", "OneDrive", "Creates a new folder in OneDrive.", Kind = ActivityKind.Task)]
public class CreateFolder : OneDriveActivity<DriveItem>
{
/// <summary>
/// The name of the folder to create.
/// </summary>
[Input(Description = "The name of the folder to create.")]
public Input<string> FolderName { get; set; } = default!;
/// <summary>
/// The ID of the parent folder. If not specified, the folder will be created in the root.
/// </summary>
[Input(Description = "The ID of the parent folder. If not specified, the folder will be created in the root.")]
public Input<string>? ParentFolderId { get; set; }
/// <summary>
/// The ID of the drive. If not specified, the folder will be created in the default drive.
/// </summary>
[Input(Description = "The ID of the drive. If not specified, the folder will be created in the default drive.")]
public Input<string>? DriveId { get; set; }
/// <inheritdoc />
protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
{
var graphClient = GetGraphClient(context);
var folderName = FolderName.Get(context);
var parentFolderId = ParentFolderId?.Get(context);
var driveId = DriveId?.Get(context);
var requestBody = new DriveItem
{
Name = folderName,
Folder = new Folder(),
AdditionalData = new Dictionary<string, object>()
{
{ "@microsoft.graph.conflictBehavior", "rename" }
}
};
DriveItem result;
if (driveId != null)
{
if (parentFolderId != null)
{
// Create folder in a specific parent folder in a specific drive
result = await graphClient.Drives[driveId].Items[parentFolderId].Children.PostAsync(
requestBody, cancellationToken: context.CancellationToken);
}
else
{
// Create folder in the root of a specific drive
result = await graphClient.Drives[driveId].Root.Children.PostAsync(
requestBody, cancellationToken: context.CancellationToken);
}
}
else if (parentFolderId != null)
{
// Create folder in a specific parent folder in the default drive
result = await graphClient.Me.Drive.Items[parentFolderId].Children.PostAsync(
requestBody, cancellationToken: context.CancellationToken);
}
else
{
// Create folder in the root of the default drive
result = await graphClient.Me.Drive.Root.Children.PostAsync(
requestBody, cancellationToken: context.CancellationToken);
}
Result.Set(context, result);
}
}