Esempio n. 1
0
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default)
        {
            string topicKey      = TopicKey.GetValue(dc.State);
            string endpoint      = TopicEndpoint.GetValue(dc.State);
            string topicHostname = new Uri(endpoint).DnsSafeHost;
            string eventType     = EventType.GetValue(dc.State);
            object eventData     = EventData.GetValue(dc.State);
            string eventSubject  = Subject.GetValue(dc.State);

            TopicCredentials topicCredentials = new TopicCredentials(topicKey);
            EventGridClient  client           = new EventGridClient(topicCredentials);

            var events = new List <EventGridEvent>()
            {
                new EventGridEvent()
                {
                    Id          = Guid.NewGuid().ToString(),
                    EventType   = eventType,
                    Data        = eventData,
                    EventTime   = DateTime.Now,
                    Subject     = eventSubject,
                    DataVersion = "2.0"
                }
            };

            await client.PublishEventsAsync(topicHostname, events, cancellationToken);

            await dc.Context.TraceActivityAsync(nameof(PublishEventGridEvent), label : "Event Grid events published",
                                                value : new
            {
                TopicHostname = topicHostname,
                Endpoint      = endpoint,
                Events        = events,
            });

            return(await dc.EndDialogAsync(cancellationToken : cancellationToken));
        }