public JObject Post([FromBody] object request)
        {
            //Deserializing the request
            var eventGridEvent = JsonConvert.DeserializeObject <EventGridEvent[]>(request.ToString())
                                 .FirstOrDefault();
            var data = eventGridEvent.Data as JObject;

            // Validate whether EventType is of "Microsoft.EventGrid.SubscriptionValidationEvent"
            if (string.Equals(eventGridEvent.EventType, Constants.SubscriptionValidationEvent, StringComparison.OrdinalIgnoreCase))
            {
                var eventData    = data.ToObject <SubscriptionValidationEventData>();
                var responseData = new SubscriptionValidationResponseData
                {
                    ValidationResponse = eventData.ValidationCode
                };

                if (responseData.ValidationResponse != null)
                {
                    return(JObject.FromObject(responseData));
                }
            }
            else
            {
                // Handle your custom event
                var eventData   = data.ToObject <CustomData>();
                var customEvent = CustomEvent <CustomData> .CreateCustomEvent(eventData);

                return(JObject.FromObject(customEvent));
            }

            return(new JObject(new HttpResponseMessage(System.Net.HttpStatusCode.OK)));
        }
Пример #2
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage request, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            var requestMessageContent = await request.Content.ReadAsStringAsync();

            var eventGridEvent = JsonConvert.DeserializeObject <EventGridEvent[]>(requestMessageContent)
                                 .FirstOrDefault();
            var data = eventGridEvent.Data as JObject;

            // Validate whether EventType is of "Microsoft.EventGrid.SubscriptionValidationEvent"
            if (string.Equals(eventGridEvent.EventType, Constants.SubscriptionValidationEvent, StringComparison.OrdinalIgnoreCase))
            {
                var eventData    = data.ToObject <SubscriptionValidationEventData>();
                var responseData = new SubscriptionValidationResponseData
                {
                    ValidationResponse = eventData.ValidationCode
                };

                if (responseData.ValidationResponse != null)
                {
                    return(request.CreateResponse(HttpStatusCode.OK, responseData));
                }
            }
            else
            {
                // Handle your custom event
                var eventData   = data.ToObject <CustomData>();
                var customEvent = CustomEvent <CustomData> .CreateCustomEvent(eventData);

                return(request.CreateResponse(HttpStatusCode.OK, customEvent));
            }

            return(request.CreateResponse(HttpStatusCode.OK));
        }
Пример #3
0
        public async Task <HttpResponseMessage> Post(HttpRequestMessage request)
        {
            var requestMessageContent = await request.Content.ReadAsStringAsync();

            var eventGridEvent = JsonConvert.DeserializeObject <EventGridEvent[]>(requestMessageContent)
                                 .FirstOrDefault();
            var data = eventGridEvent.Data as JObject;

            // Validate whether EventType is of "Microsoft.EventGrid.SubscriptionValidationEvent"
            if (string.Equals(eventGridEvent.EventType, Constants.SubscriptionValidationEvent, StringComparison.OrdinalIgnoreCase))
            {
                var eventData    = data.ToObject <SubscriptionValidationEventData>();
                var responseData = new SubscriptionValidationResponseData
                {
                    ValidationResponse = eventData.ValidationCode
                };

                if (responseData.ValidationResponse != null)
                {
                    return(request.CreateResponse(HttpStatusCode.OK, responseData));
                }
            }
            else
            {
                // Handle your custom event
                var eventData   = data.ToObject <CustomData>();
                var customEvent = CustomEvent <CustomData> .CreateCustomEvent(eventData);

                return(request.CreateResponse(HttpStatusCode.OK, customEvent));
            }

            return(request.CreateResponse(HttpStatusCode.OK));
        }
Пример #4
0
        private static async Task <HttpResponseMessage> PublishEventGridEvent()
        {
            var eventTopicEndpoint = "{event topic endpoint to be taken from Azure Portal}";
            var httpClient         = new HttpClient();

            httpClient.DefaultRequestHeaders.Add("aeg-sas-key", "sas key for event grid topic");
            var customData = new CustomData()
            {
                Name = "John Doe", Age = 32, Height = 176, Weight = 76
            };
            var customEventData = CustomEvent <CustomData> .CreateCustomEvent(customData);

            var jsonContent        = JsonConvert.SerializeObject(customEventData);
            var httpRequestContent = new StringContent("[" + jsonContent + "]", Encoding.UTF8, "application/json");

            return(await httpClient.PostAsync(eventTopicEndpoint, httpRequestContent));
        }
 public static void Run([EventGridTrigger] Microsoft.Azure.EventGrid.Models.EventGridEvent eventGridEvent, TraceWriter log)
 {
     log.Info(eventGridEvent.Data.ToString());
     var eventData   = eventGridEvent.Data as CustomData;
     var customEvent = CustomEvent <CustomData> .CreateCustomEvent(eventData);
 }