forked from pnp/powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetWebhookSubscription.cs
48 lines (45 loc) · 1.8 KB
/
GetWebhookSubscription.cs
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
using Microsoft.SharePoint.Client;
using PnP.Framework.Entities;
using PnP.PowerShell.Commands.Base.Completers;
using PnP.PowerShell.Commands.Base.PipeBinds;
using System.Management.Automation;
using Resources = PnP.PowerShell.Commands.Properties.Resources;
namespace PnP.PowerShell.Commands.Webhooks
{
[Alias("Get-PnPWebhookSubscriptions")]
[Cmdlet(VerbsCommon.Get, "PnPWebhookSubscription")]
[OutputType(typeof(WebhookSubscription))]
public class GetWebhookSubscription : PnPWebCmdlet
{
[Parameter(Mandatory = false, ValueFromPipeline = true)]
[ArgumentCompleter(typeof(ListNameCompleter))]
public ListPipeBind List;
protected override void ExecuteCmdlet()
{
// NOTE: Currently only supports List Webhooks
if (ParameterSpecified(nameof(List)))
{
// Ensure we didn't get piped in a null, i.e. when running Get-PnPList -Identity "ThisListDoesNotExist" | Get-PnPWebhookSubscriptions
if(List == null)
{
throw new PSArgumentNullException(nameof(List));
}
// Get the list from the currently selected web
List list = List.GetList(CurrentWeb);
if (list != null)
{
// Get all the webhook subscriptions for the specified list
WriteObject(list.GetWebhookSubscriptions(), true);
}
else
{
throw new PSArgumentOutOfRangeException(nameof(List), List.ToString(), string.Format(Resources.ListNotFound, List.ToString()));
}
}
else
{
throw new PSNotImplementedException(Resources.WebhooksOnlySupportsLists);
}
}
}
}