-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSftpToEventGridQueueWatcherEntity.cs
More file actions
38 lines (34 loc) · 1.44 KB
/
SftpToEventGridQueueWatcherEntity.cs
File metadata and controls
38 lines (34 loc) · 1.44 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
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
using Azure.Messaging.EventGrid;
namespace SftpWatcher
{
// Checks the list of files in an SFTP folder and emits events to Azure Event Grid custom topic
public class SftpToEventGridTopicWatcherEntity: SftpWatcherEntity
{
public SftpToEventGridTopicWatcherEntity(ICollector<EventGridEvent> eventGridCollector)
{
this.eventCollector = eventGridCollector;
}
protected override void EmitEvent(WhatHappenedEnum eventType, string filePath)
{
this.eventCollector.Add(new EventGridEvent(
filePath,
eventType.ToString("g"),
"1.0",
new {
eventType = eventType.ToString("g"),
filePath
}
));
}
private readonly ICollector<EventGridEvent> eventCollector;
// Required boilerplate
[FunctionName(nameof(SftpToEventGridTopicWatcherEntity))]
public static Task Run([EntityTrigger] IDurableEntityContext ctx,
[EventGrid(TopicEndpointUri = "OUTPUT_QUEUE_OR_TOPIC_NAME", TopicKeySetting = "EVENT_GRID_TOPIC_KEY")] ICollector<EventGridEvent> storageQueueCollector
) => ctx.DispatchAsync<SftpToEventGridTopicWatcherEntity>(storageQueueCollector);
}
}