Skip to content

Commit 74ceb51

Browse files
committed
Complete fields of Event representation.
Add AD Authentication.
1 parent 3b8aa35 commit 74ceb51

File tree

5 files changed

+63
-13
lines changed

5 files changed

+63
-13
lines changed

dotnet/src/dotnetcore/Providers/Messaging/GXAzureEventGrid/AzureEventGrid.cs

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Net;
43
using System.Runtime.Serialization;
54
using System.Text.Json;
65
using System.Threading.Tasks;
76
using Azure;
7+
using Azure.Identity;
88
using Azure.Messaging;
99
using Azure.Messaging.EventGrid;
1010
using GeneXus.Messaging.Common;
@@ -31,9 +31,23 @@ private void Initialize(GXService providerService)
3131
ServiceSettings serviceSettings = new(PropertyConstants.EVENT_ROUTER, Name, providerService);
3232
_endpoint = serviceSettings.GetEncryptedPropertyValue(PropertyConstants.URI_ENDPOINT);
3333
_accessKey = serviceSettings.GetEncryptedPropertyValue(PropertyConstants.ACCESS_KEY);
34-
_client = new EventGridPublisherClient(
35-
new Uri(_endpoint),
36-
new AzureKeyCredential(_accessKey));
34+
35+
if (!string.IsNullOrEmpty(_endpoint)) {
36+
if (string.IsNullOrEmpty(_accessKey))
37+
38+
//Try using Active Directory authentication
39+
_client = new EventGridPublisherClient(
40+
new Uri(_endpoint),
41+
new DefaultAzureCredential());
42+
43+
else
44+
45+
_client = new EventGridPublisherClient(
46+
new Uri(_endpoint),
47+
new AzureKeyCredential(_accessKey));
48+
}
49+
else
50+
throw new Exception("Endpoint URI must be set.");
3751
}
3852
public override string GetName()
3953
{
@@ -54,7 +68,7 @@ public bool SendEvent(GXCloudEvent gxCloudEvent, bool binaryData)
5468
}
5569
else
5670
{
57-
throw new Exception("SendEvent: There was an error at the Event Grid initialization.");
71+
throw new Exception("There was an error at the Event Grid initialization.");
5872
}
5973
}
6074
catch (AggregateException ae)
@@ -80,7 +94,7 @@ public bool SendEvents(IList<GXCloudEvent> gxCloudEvents, bool binaryData)
8094
}
8195
else
8296
{
83-
throw new Exception("SendEvents: There was an error at the Event Grid initialization.");
97+
throw new Exception("There was an error at the Event Grid initialization.");
8498
}
8599
}
86100
catch (AggregateException ae)
@@ -232,7 +246,7 @@ public bool GetMessageFromException(Exception ex, SdtMessages_Message msg)
232246
{
233247
try
234248
{
235-
HttpListenerException az_ex = (HttpListenerException)ex;
249+
RequestFailedException az_ex = (RequestFailedException)ex;
236250
msg.gxTpr_Id = az_ex.ErrorCode.ToString();
237251
msg.gxTpr_Description = az_ex.Message;
238252
return true;
@@ -255,7 +269,9 @@ private EventGridEvent ToEventGridSchema(GXEventGridSchema gxEventGridSchema, bo
255269
evt.Id = gxEventGridSchema.id;
256270
if (!string.IsNullOrEmpty(gxEventGridSchema.topic))
257271
evt.Topic = gxEventGridSchema.topic;
258-
272+
if (gxEventGridSchema.eventtime != DateTime.MinValue)
273+
evt.EventTime = gxEventGridSchema.eventtime;
274+
259275
return evt;
260276
}
261277
private CloudEvent ToCloudEvent(GXCloudEvent gxCloudEvent, bool isBinaryData)
@@ -264,9 +280,13 @@ private CloudEvent ToCloudEvent(GXCloudEvent gxCloudEvent, bool isBinaryData)
264280
if (string.IsNullOrEmpty(gxCloudEvent.data))
265281
evt = new CloudEvent(gxCloudEvent.source, gxCloudEvent.type, null);
266282
else
267-
{
283+
{
268284
if (!isBinaryData)
269-
evt = new CloudEvent(gxCloudEvent.source, gxCloudEvent.type, gxCloudEvent.data);
285+
{
286+
if (string.IsNullOrEmpty(gxCloudEvent.datacontenttype))
287+
gxCloudEvent.datacontenttype = "application/json";
288+
evt = new CloudEvent(gxCloudEvent.source, gxCloudEvent.type, BinaryData.FromString(gxCloudEvent.data),gxCloudEvent.datacontenttype,CloudEventDataFormat.Json);
289+
}
270290
else
271291
{
272292
if (string.IsNullOrEmpty(gxCloudEvent.datacontenttype))
@@ -280,6 +300,8 @@ private CloudEvent ToCloudEvent(GXCloudEvent gxCloudEvent, bool isBinaryData)
280300
evt.DataSchema = gxCloudEvent.dataschema;
281301
if (!string.IsNullOrEmpty(gxCloudEvent.subject))
282302
evt.Subject = gxCloudEvent.subject;
303+
if (gxCloudEvent.time != DateTime.MinValue)
304+
evt.Time = gxCloudEvent.time;
283305
return evt;
284306
}
285307
#endregion
@@ -301,5 +323,12 @@ public class GXEventGridSchema
301323
[DataMember]
302324
public string dataversion { get; set; }
303325

326+
[DataMember]
327+
public DateTime eventtime { get; set; }
328+
329+
[DataMember]
330+
public string metadataversion { get; set; }
331+
332+
304333
}
305334
}

dotnet/src/dotnetcore/Providers/Messaging/GXAzureEventGrid/EventGridRouterProvider.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
namespace GeneXus.Messaging.GXAzureEventGrid
55
{
6+
/// <summary>
7+
/// Implementation of EventGridRouterProvider External Object.
8+
/// </summary>
69
public class EventGridRouterProvider
710
{
811
public EventRouterProviderBase Connect(string endpoint, string accesskey, out GXBaseCollection<SdtMessages_Message> errorMessages, out bool success)
@@ -14,6 +17,19 @@ public EventRouterProviderBase Connect(string endpoint, string accesskey, out GX
1417
{ PropertyConstants.EVENTROUTER_AZUREEG_ACCESS_KEY, accesskey }
1518
};
1619

20+
EventRouterProviderBase evtRouterProvider = eventRouterProvider.Connect(PropertyConstants.AZUREEVENTGRID, properties, out GXBaseCollection<SdtMessages_Message> errorMessagesConnect, out bool successConnect);
21+
errorMessages = errorMessagesConnect;
22+
success = successConnect;
23+
return evtRouterProvider;
24+
}
25+
public EventRouterProviderBase Connect(string endpoint, out GXBaseCollection<SdtMessages_Message> errorMessages, out bool success)
26+
{
27+
EventRouterProvider eventRouterProvider = new EventRouterProvider();
28+
GXProperties properties = new GXProperties
29+
{
30+
{ PropertyConstants.EVENTROUTER_AZUREEG_ENDPOINT, endpoint },
31+
};
32+
1733
EventRouterProviderBase evtRouterProvider = eventRouterProvider.Connect(PropertyConstants.AZUREEVENTGRID, properties, out GXBaseCollection<SdtMessages_Message> errorMessagesConnect, out bool successConnect);
1834
errorMessages = errorMessagesConnect;
1935
success = successConnect;

dotnet/src/dotnetcore/Providers/Messaging/GXAzureEventGrid/GXAzureEventGrid.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10+
<PackageReference Include="Azure.Identity" Version="1.9.0" />
1011
<PackageReference Include="Azure.Messaging.EventGrid" Version="4.17.0" />
1112
</ItemGroup>
1213

dotnet/src/dotnetcore/Providers/Messaging/GXEventRouter/EventRouter.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using GeneXus.Utils;
2-
using System.Collections.Generic;
31
using System;
2+
using System.Collections.Generic;
3+
using GeneXus.Utils;
44

55
namespace GeneXus.Messaging.Common
66
{
@@ -20,6 +20,8 @@ public class GXCloudEvent : GxUserType
2020
public string id { get; set; }
2121
public string dataschema { get; set; }
2222
public string subject { get; set; }
23+
public string data_base64 { get; set; }
24+
public DateTime time { get; set; }
2325
}
2426

2527
}

dotnet/src/dotnetcore/Providers/Messaging/GXEventRouter/EventRouterProviderBase.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ private GXCloudEvent ToGXCloudEvent(GxUserType evt)
177177
gxCloudEvent.id = evt.GetPropertyValue<string>("Id");
178178
gxCloudEvent.subject = evt.GetPropertyValue<string>("Subject");
179179
gxCloudEvent.dataschema = evt.GetPropertyValue<string>("Dataschema");
180+
gxCloudEvent.data_base64 = evt.GetPropertyValue<string>("Data_base64");
181+
gxCloudEvent.time = evt.GetPropertyValue<DateTime>("Time");
180182
return gxCloudEvent;
181183
}
182184
return null;
@@ -187,7 +189,7 @@ private GXCloudEvent ToGXCloudEvent(GxUserType evt)
187189
internal class ServiceFactory
188190
{
189191
private static IEventRouter eventRouter;
190-
private static readonly ILog log = log4net.LogManager.GetLogger(typeof(GeneXus.Services.ServiceFactory));
192+
private static readonly ILog log = LogManager.GetLogger(typeof(Services.ServiceFactory));
191193

192194
public static GXServices GetGXServices()
193195
{

0 commit comments

Comments
 (0)