Skip to content
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

Azure functions Global changes #1070

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dotnet/DotNetStandardClasses.sln
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LogTest", "test\benchmarks\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AccessTokenController_Test", "test\NativeAccessControllerTest\AccessTokenController_Test.csproj", "{A5589382-DB6F-4450-AE2B-6C6AA1643EF1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Functions", "Functions", "{E59B3248-4C26-4DB0-96CB-67437319E22B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -767,6 +769,7 @@ Global
{46DAAFD1-FAF5-4904-8EC5-406BE04E5538} = {1D6F1776-FF4B-46C2-9B3D-BC46CCF049DC}
{A1DBDCE0-4F09-445F-A202-9B260CDD46CF} = {46DAAFD1-FAF5-4904-8EC5-406BE04E5538}
{A5589382-DB6F-4450-AE2B-6C6AA1643EF1} = {1D6F1776-FF4B-46C2-9B3D-BC46CCF049DC}
{E59B3248-4C26-4DB0-96CB-67437319E22B} = {41E1D031-799F-484F-85DE-7A30AF1A6FBA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E18684C9-7D76-45CD-BF24-E3944B7F174C}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.Core" Version="1.36.0" />
<PackageReference Include="Azure.Core" Version="1.42.0" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.36.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public BlobTriggerHandler(ICallMappings callMappings)
{
_callmappings = callMappings;
}
public void Run(string myTriggerItem, FunctionContext context)
public void Run(Stream blobItem, FunctionContext context)
{
var logger = context.GetLogger("BlobTriggerHandler");
string functionName = context.FunctionDefinition.Name;
Expand All @@ -31,20 +31,28 @@ public void Run(string myTriggerItem, FunctionContext context)

try
{
ProcessMessage(context, logger, myTriggerItem, messageId.ToString());
ProcessMessage(context, logger, blobItem, messageId.ToString());
}
catch (Exception ex) //Catch System exception and retry
{
logger.LogError(ex.ToString());
throw;
}
}
private void ProcessMessage(FunctionContext context, ILogger log, string myTriggerItem, string messageId)
private void ProcessMessage(FunctionContext context, ILogger log, Stream blobItem, string messageId)
{
CallMappings callmap = (CallMappings)_callmappings;
string envVar = $"GX_AZURE_{context.FunctionDefinition.Name.ToUpper()}_CLASS";
string envVarValue = Environment.GetEnvironmentVariable(envVar);
string gxProcedure = string.Empty;
if (!string.IsNullOrEmpty(envVarValue))
gxProcedure = envVarValue;
else
{
CallMappings callmap = (CallMappings)_callmappings;
GxAzMappings map = callmap != null && callmap.mappings is object ? callmap.mappings.SingleOrDefault(m => m.FunctionName == context.FunctionDefinition.Name) : null;
gxProcedure = map is object ? map.GXEntrypoint : string.Empty;
}

GxAzMappings map = callmap.mappings is object ? callmap.mappings.First(m => m.FunctionName == context.FunctionDefinition.Name) : null;
string gxProcedure = (map != null && map is object) ? map.GXEntrypoint : string.Empty;
string exMessage;

if (!string.IsNullOrEmpty(gxProcedure))
Expand Down Expand Up @@ -86,9 +94,13 @@ private void ProcessMessage(FunctionContext context, ILogger log, string myTrigg
Object[] parametersdata;
parametersdata = new object[] { null };


if (parameters[0].ParameterType == typeof(string))
parametersdata = new object[] { myTriggerItem, null };

if (context.BindingContext.BindingData.TryGetValue("Uri", out object urivalue))
parametersdata = new object[] { urivalue, null };
else
parametersdata = new object[] { string.Empty, null };

else
{
//Initialization
Expand All @@ -104,9 +116,9 @@ private void ProcessMessage(FunctionContext context, ILogger log, string myTrigg
IList eventMessageProperties = (IList)ClassLoader.GetPropValue(eventMessageItem, "gxTpr_Eventmessageproperties");//instance of GXBaseCollection<GeneXus.Programs.genexusserverlessapi.SdtEventMessageProperty>
Type eventMessPropsItemType = eventMessageProperties.GetType().GetGenericArguments()[0];//SdtEventMessageProperty

if (context.BindingContext.BindingData.TryGetValue("Uri", out object urivalue))
if (context.BindingContext.BindingData.TryGetValue("Uri", out object urivalue2))
{
GxUserType eventMessageProperty = EventMessagePropertyMapping.CreateEventMessageProperty(eventMessPropsItemType, "Uri", urivalue.ToString(), gxcontext);
GxUserType eventMessageProperty = EventMessagePropertyMapping.CreateEventMessageProperty(eventMessPropsItemType, "Uri", urivalue2.ToString(), gxcontext);
eventMessageProperties.Add(eventMessageProperty);
}

Expand All @@ -118,7 +130,7 @@ private void ProcessMessage(FunctionContext context, ILogger log, string myTrigg

if (context.BindingContext.BindingData.TryGetValue("Metadata", out object metadatavalue))
{
GxUserType eventMessageProperty = EventMessagePropertyMapping.CreateEventMessageProperty(eventMessPropsItemType, "Metadata", namevalue.ToString(), gxcontext);
GxUserType eventMessageProperty = EventMessagePropertyMapping.CreateEventMessageProperty(eventMessPropsItemType, "Metadata", metadatavalue.ToString(), gxcontext);
eventMessageProperties.Add(eventMessageProperty);
}

Expand All @@ -138,11 +150,14 @@ private void ProcessMessage(FunctionContext context, ILogger log, string myTrigg

//Event

ClassLoader.SetPropValue(eventMessageItem, "gxTpr_Eventmessageid", messageId.ToString());
ClassLoader.SetPropValue(eventMessageItem, "gxTpr_Eventmessageid", messageId);
ClassLoader.SetPropValue(eventMessageItem, "gxTpr_Eventmessagesourcetype", EventSourceType.Blob);
ClassLoader.SetPropValue(eventMessageItem, "gxTpr_Eventmessagedata", myTriggerItem);

string data = urivalue2 != null ? urivalue2.ToString() : string.Empty;
ClassLoader.SetPropValue(eventMessageItem, "gxTpr_Eventmessagedata", data);

ClassLoader.SetPropValue(eventMessageItem, "gxTpr_Eventmessagedate", DateTime.UtcNow);
ClassLoader.SetPropValue(eventMessageItem, "gxTpr_Eventmessageversion", string.Empty);
ClassLoader.SetPropValue(eventMessageItem, "gxTpr_Eventmessageversion", "1.0.0");
ClassLoader.SetPropValue(eventMessageItem, "gxTpr_Eventmessageproperties", eventMessageProperties);

//List of Events
Expand Down
22 changes: 0 additions & 22 deletions dotnet/src/extensions/Azure/Handlers/Dummies/BlobTriggerDummy.cs

This file was deleted.

This file was deleted.

This file was deleted.

25 changes: 0 additions & 25 deletions dotnet/src/extensions/Azure/Handlers/Dummies/HttpTriggerDummy.cs

This file was deleted.

19 changes: 0 additions & 19 deletions dotnet/src/extensions/Azure/Handlers/Dummies/QueueTriggerDummy.cs

This file was deleted.

This file was deleted.

17 changes: 0 additions & 17 deletions dotnet/src/extensions/Azure/Handlers/Dummies/TimerTriggerDummy.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.Json;
using Azure.Messaging;
using Azure.Messaging.EventGrid;
using GeneXus.Application;
using GeneXus.Deploy.AzureFunctions.Handlers.Helpers;
Expand All @@ -26,7 +23,7 @@ public EventGridTriggerHandlerAzure(ICallMappings callMappings)
{
_callmappings = callMappings;
}
public void Run(EventGridEvent input, FunctionContext context)
public void Run(EventGridEvent[] events, FunctionContext context)
{
var logger = context.GetLogger("EventGridTriggerHandler");
string functionName = context.FunctionDefinition.Name;
Expand All @@ -35,20 +32,28 @@ public void Run(EventGridEvent input, FunctionContext context)

try
{
ProcessEvent(context, logger, input, eventId.ToString());
ProcessEvent(context, logger, events, eventId.ToString());
}
catch (Exception ex) //Catch System exception and retry
{
logger.LogError(ex.ToString());
throw;
}
}
private void ProcessEvent(FunctionContext context, ILogger log, EventGridEvent input, string eventId)
private void ProcessEvent(FunctionContext context, ILogger log, EventGridEvent[] events, string eventId)
{
CallMappings callmap = (CallMappings)_callmappings;

GxAzMappings map = callmap.mappings is object ? callmap.mappings.First(m => m.FunctionName == context.FunctionDefinition.Name) : null;
string gxProcedure = (map != null && map is object) ? map.GXEntrypoint : string.Empty;
string envVar = $"GX_AZURE_{context.FunctionDefinition.Name.ToUpper()}_CLASS";
string envVarValue = Environment.GetEnvironmentVariable(envVar);
string gxProcedure = string.Empty;
if (!string.IsNullOrEmpty(envVarValue))
gxProcedure = envVarValue;
else
{
CallMappings callmap = (CallMappings)_callmappings;
GxAzMappings map = callmap != null && callmap.mappings is object ? callmap.mappings.SingleOrDefault(m => m.FunctionName == context.FunctionDefinition.Name) : null;
gxProcedure = map is object ? map.GXEntrypoint : string.Empty;
}
string exMessage;

if (!string.IsNullOrEmpty(gxProcedure))
Expand Down Expand Up @@ -92,7 +97,7 @@ private void ProcessEvent(FunctionContext context, ILogger log, EventGridEvent i
if (parameters[0].ParameterType == typeof(string))
{
string eventMessageSerialized = string.Empty;
eventMessageSerialized = JsonSerializer.Serialize(input);
eventMessageSerialized = JsonSerializer.Serialize(events);
parametersdata = new object[] { eventMessageSerialized, null };
}
else
Expand All @@ -103,6 +108,9 @@ private void ProcessEvent(FunctionContext context, ILogger log, EventGridEvent i
Type eventMessagesType = parameters[0].ParameterType; //SdtEventMessages
GxUserType eventMessages = (GxUserType)Activator.CreateInstance(eventMessagesType, new object[] { gxcontext }); // instance of SdtEventMessages

foreach (EventGridEvent eventGridEvent in events)
{

IList eventMessage = (IList)ClassLoader.GetPropValue(eventMessages, "gxTpr_Eventmessage");//instance of GXBaseCollection<SdtEventMessage>
Type eventMessageItemType = eventMessage.GetType().GetGenericArguments()[0];//SdtEventMessage

Expand All @@ -113,29 +121,31 @@ private void ProcessEvent(FunctionContext context, ILogger log, EventGridEvent i

GxUserType eventMessageProperty;

if (input.Subject != null)
if (eventGridEvent.Subject != null)
{
eventMessageProperty = EventMessagePropertyMapping.CreateEventMessageProperty(eventMessPropsItemType, "Subject", input.Subject, gxcontext);
eventMessageProperty = EventMessagePropertyMapping.CreateEventMessageProperty(eventMessPropsItemType, "Subject", eventGridEvent.Subject, gxcontext);
eventMessageProperties.Add(eventMessageProperty);
}

if (input.Topic != null)
if (eventGridEvent.Topic != null)
{
eventMessageProperty = EventMessagePropertyMapping.CreateEventMessageProperty(eventMessPropsItemType, "Topic", input.Topic, gxcontext);
eventMessageProperty = EventMessagePropertyMapping.CreateEventMessageProperty(eventMessPropsItemType, "Topic", eventGridEvent.Topic, gxcontext);
eventMessageProperties.Add(eventMessageProperty);
}

//Event

ClassLoader.SetPropValue(eventMessageItem, "gxTpr_Eventmessageid", input.Id);
ClassLoader.SetPropValue(eventMessageItem, "gxTpr_Eventmessagesourcetype", input.EventType);
ClassLoader.SetPropValue(eventMessageItem, "gxTpr_Eventmessageversion", input.DataVersion);
ClassLoader.SetPropValue(eventMessageItem, "gxTpr_Eventmessageid", eventGridEvent.Id);
ClassLoader.SetPropValue(eventMessageItem, "gxTpr_Eventmessagesourcetype", eventGridEvent.EventType);
ClassLoader.SetPropValue(eventMessageItem, "gxTpr_Eventmessageversion", eventGridEvent.DataVersion);
ClassLoader.SetPropValue(eventMessageItem, "gxTpr_Eventmessageproperties", eventMessageProperties);
ClassLoader.SetPropValue(eventMessageItem, "gxTpr_Eventmessagedate", input.EventTime.UtcDateTime);
ClassLoader.SetPropValue(eventMessageItem, "gxTpr_Eventmessagedata", input.Data.ToString());
ClassLoader.SetPropValue(eventMessageItem, "gxTpr_Eventmessagedate", eventGridEvent.EventTime.UtcDateTime);
ClassLoader.SetPropValue(eventMessageItem, "gxTpr_Eventmessagedata", eventGridEvent.Data.ToString());

//List of Events
eventMessage.Add(eventMessageItem);
}

parametersdata = new object[] { eventMessages, null };
}

Expand Down
Loading
Loading