From d342736c29fd8ecbfb2ef9694e5ef9eb1481949b Mon Sep 17 00:00:00 2001 From: sjuarezgx Date: Wed, 19 Oct 2022 09:49:23 -0300 Subject: [PATCH] RawData parameters in Azure Functions --- .../QueueHandler/QueueTriggerHandler.cs | 13 ++- .../ServiceBusTriggerHandler.cs | 81 +++++++++++++------ 2 files changed, 69 insertions(+), 25 deletions(-) diff --git a/dotnet/src/extensions/Azure/Handlers/QueueHandler/QueueTriggerHandler.cs b/dotnet/src/extensions/Azure/Handlers/QueueHandler/QueueTriggerHandler.cs index 382049f71..6551de9ac 100644 --- a/dotnet/src/extensions/Azure/Handlers/QueueHandler/QueueTriggerHandler.cs +++ b/dotnet/src/extensions/Azure/Handlers/QueueHandler/QueueTriggerHandler.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Reflection; +using System.Runtime.Serialization; using System.Text; using GeneXus.Application; using GeneXus.Deploy.AzureFunctions.Handlers.Helpers; @@ -226,17 +227,27 @@ private GxUserType CreateCustomPayloadItem(Type customPayloadItemType, string pr return CustomPayloadItem; } + [DataContract] internal class QueueMessage { public QueueMessage() { } + [DataMember] + public List MessageProperties; - public List MessageProperties; + [DataMember] public string Id { get; set; } + + [DataMember] public string Body { get; set; } + + [DataContract] internal class MessageProperty { + [DataMember] public string key { get; set; } + + [DataMember] public string value { get; set; } public MessageProperty() { } diff --git a/dotnet/src/extensions/Azure/Handlers/ServiceBusHandler/ServiceBusTriggerHandler.cs b/dotnet/src/extensions/Azure/Handlers/ServiceBusHandler/ServiceBusTriggerHandler.cs index 42102fc41..3d3b4fcfa 100644 --- a/dotnet/src/extensions/Azure/Handlers/ServiceBusHandler/ServiceBusTriggerHandler.cs +++ b/dotnet/src/extensions/Azure/Handlers/ServiceBusHandler/ServiceBusTriggerHandler.cs @@ -1,16 +1,17 @@ using System; +using System.Collections; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Reflection; +using System.Runtime.Serialization; using System.Text; -using Microsoft.Azure.Functions.Worker; -using Microsoft.Extensions.Logging; using GeneXus.Application; using GeneXus.Deploy.AzureFunctions.Handlers.Helpers; -using GeneXus.Utils; using GeneXus.Metadata; -using System.Collections; -using System.Linq; +using GeneXus.Utils; +using Microsoft.Azure.Functions.Worker; +using Microsoft.Extensions.Logging; //https://github.com/Azure/azure-functions-dotnet-worker/issues/384 @@ -223,31 +224,30 @@ private void ProcessMessage(FunctionContext context, ILogger log, Message messag //List of Events EventMessage.Add(EventMessageItem); parametersdata = new object[] { EventMessages, null }; - - try - { - method.Invoke(objgxproc, parametersdata); - GxUserType EventMessageResponse = parametersdata[1] as GxUserType;//SdtEventMessageResponse + } + try + { + method.Invoke(objgxproc, parametersdata); + GxUserType EventMessageResponse = parametersdata[1] as GxUserType;//SdtEventMessageResponse - //Error handling + //Error handling - if ((bool)ClassLoader.GetPropValue(EventMessageResponse, "gxTpr_Handled") == false) //Must retry - { - exMessage = string.Format("{0} {1}", FunctionExceptionType.AppError, ClassLoader.GetPropValue(EventMessageResponse, "gxTpr_Errormessage")); - throw new Exception(exMessage); - } - else - { - log.LogInformation("(GX function handler) Function finished execution."); - } + if ((bool)ClassLoader.GetPropValue(EventMessageResponse, "gxTpr_Handled") == false) //Must retry + { + exMessage = string.Format("{0} {1}", FunctionExceptionType.AppError, ClassLoader.GetPropValue(EventMessageResponse, "gxTpr_Errormessage")); + throw new Exception(exMessage); } - catch (Exception) + else { - exMessage = string.Format("{0} Error invoking the GX procedure for Message Id {1}.", FunctionExceptionType.SysRuntimeError, message.MessageId); - log.LogError(exMessage); - throw; //Throw the exception so the runtime can Retry the operation. + log.LogInformation("(GX function handler) Function finished execution."); } } + catch (Exception) + { + exMessage = string.Format("{0} Error invoking the GX procedure for Message Id {1}.", FunctionExceptionType.SysRuntimeError, message.MessageId); + log.LogError(exMessage); + throw; //Throw the exception so the runtime can Retry the operation. + } } } else @@ -268,32 +268,65 @@ private void ProcessMessage(FunctionContext context, ILogger log, Message messag throw new Exception(exMessage); } } + [DataContract] internal class Message { public Message() { } + [DataMember] public string MessageId; + + [DataMember] public IDictionary UserProperties { get; set; } + + [DataMember] public SystemPropertiesCollection SystemProperties { get; set; } + + [DataMember] public string Body { get; set; } + [DataMember] public List MessageProperties; + + [DataContract] internal class SystemPropertiesCollection { + [DataMember] public bool IsLockTokenSet { get; } + + [DataMember] public string LockToken { get; } + + [DataMember] public bool IsReceived { get; } + + [DataMember] public int DeliveryCount { get; } + + [DataMember] public DateTime LockedUntilUtc { get; } + + [DataMember] public long SequenceNumber { get; } + + [DataMember] public string DeadLetterSource { get; } + + [DataMember] public long EnqueuedSequenceNumber { get; } + + [DataMember] public DateTime EnqueuedTimeUtc { get; } } + + [DataContract] internal class MessageProperty { + [DataMember] public string key { get; set; } + + [DataMember] public string value { get; set; } public MessageProperty() { }