-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update EventGrid SDK to T2 #18
base: main
Are you sure you want to change the base?
Changes from 5 commits
e5d016d
f0ba3f0
8dd6d1a
27d3dbe
2355dc5
c2b5bda
7fbb390
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
|
||
namespace Blazor.EventGridViewer.Core.Models | ||
{ | ||
|
@@ -21,7 +22,7 @@ public class CloudEvent | |
public string Id { get; set; } | ||
|
||
[JsonProperty("time")] | ||
public string Time { get; set; } | ||
public DateTimeOffset Time { get; set; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we just use the CloudEvent type from Azure.Core - https://docs.microsoft.com/en-us/dotnet/api/azure.messaging.cloudevent?view=azure-dotnet |
||
|
||
[JsonProperty("data")] | ||
public object Data { get; set; } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,10 @@ | |
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Azure.EventGrid; | ||
using Microsoft.Azure.EventGrid.Models; | ||
using Newtonsoft.Json.Linq; | ||
using Azure.Messaging.EventGrid; | ||
using Azure.Messaging.EventGrid.Models; | ||
using Azure.Messaging.EventGrid.SystemEvents; | ||
|
||
namespace Blazor.EventGridViewer.ServerApp.Controllers | ||
{ | ||
|
@@ -57,10 +58,11 @@ public async Task<IActionResult> Post() | |
|
||
foreach (EventGridEventModel model in eventGridEventModels) | ||
{ | ||
EventGridEvent eventGrid = new EventGridEvent(model.Subject, model.EventType, model.DataVersion, model.EventData); | ||
// EventGrid validation message | ||
if (model.EventType == EventTypes.EventGridSubscriptionValidationEvent) | ||
if (eventGrid.TryGetSystemEventData(out object systemEvent)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The systemEvent we get back would still need to be checked to make sure it is the correct type, i.e. SubscriptionValidationEventData. Or we can continue checking the event type, and then do eventGrid.Data.ToObjectFromJson(). |
||
{ | ||
var eventData = ((JObject)(model.EventData)).ToObject<SubscriptionValidationEventData>(); | ||
var eventData = ((JObject)systemEvent).ToObject<SubscriptionValidationEventData>(); | ||
var responseData = new SubscriptionValidationResponse() | ||
{ | ||
ValidationResponse = eventData.ValidationCode | ||
|
@@ -73,7 +75,7 @@ public async Task<IActionResult> Post() | |
} | ||
} | ||
} | ||
catch (Exception ex) | ||
catch (Exception) | ||
{ | ||
result = new StatusCodeResult(StatusCodes.Status500InternalServerError); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
using Blazor.EventGridViewer.Core; | ||
using Blazor.EventGridViewer.Core.Models; | ||
using Blazor.EventGridViewer.Services.Interfaces; | ||
using Microsoft.Azure.EventGrid.Models; | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using Azure.Messaging.EventGrid; | ||
|
||
namespace Blazor.EventGridViewer.Services.Adapters | ||
{ | ||
|
@@ -56,7 +56,7 @@ private List<EventGridEventModel> AdaptCloudEvent(string t) | |
EventType = cloudEvent.Type, | ||
Subject = string.IsNullOrEmpty(cloudEvent.Subject) ? cloudEvent.Type : cloudEvent.Subject, | ||
Data = json, | ||
EventData = cloudEvent.Data, | ||
EventData = new BinaryData(cloudEvent.Data), | ||
EventTime = cloudEvent.Time | ||
}; | ||
models.Add(model); | ||
|
@@ -72,7 +72,7 @@ private List<EventGridEventModel> AdaptCloudEvent(string t) | |
private List<EventGridEventModel> AdaptEventGridEvent(string t) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need EventGridEventModel - can we just use EventGridEvent? |
||
{ | ||
List<EventGridEventModel> models = new List<EventGridEventModel>(); | ||
var eventGridEvents = JsonConvert.DeserializeObject<List<EventGridEvent>>(t); | ||
var eventGridEvents = EventGridEvent.ParseMany(new BinaryData(t)); | ||
|
||
foreach (var eventGridEvent in eventGridEvents) | ||
{ | ||
|
@@ -84,7 +84,7 @@ private List<EventGridEventModel> AdaptEventGridEvent(string t) | |
Subject = string.IsNullOrEmpty(eventGridEvent.Subject) ? eventGridEvent.EventType : eventGridEvent.Subject, | ||
Data = json, | ||
EventData = eventGridEvent.Data, | ||
EventTime = eventGridEvent.EventTime.ToString("o") // https://docs.microsoft.com/en-us/dotnet/api/system.datetime.tostring?view=netcore-3.1 | ||
EventTime = eventGridEvent.EventTime // https://docs.microsoft.com/en-us/dotnet/api/system.datetime.tostring?view=netcore-3.1 | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we remove this? |
||
models.Add(model); | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||
<Project Sdk="Microsoft.NET.Sdk"> | ||||||
<Project Sdk="Microsoft.NET.Sdk"> | ||||||
|
||||||
<PropertyGroup> | ||||||
<TargetFramework>net5.0</TargetFramework> | ||||||
|
@@ -9,7 +9,7 @@ | |||||
</ItemGroup> | ||||||
|
||||||
<ItemGroup> | ||||||
<PackageReference Include="Microsoft.Azure.EventGrid" Version="3.2.0" /> | ||||||
<PackageReference Include="Azure.Messaging.EventGrid" Version="4.10.0" /> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
</ItemGroup> | ||||||
|
||||||
</Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This package will get pulled in by Azure.Messaging.EventGrid. Unless we need 6.0.0, I'd just remove this.