public TriggeredFunctionData GetTriggerFunctionData()
        {
            if (Messages.Length > 0)
            {
                Message message = Messages[0];
                if (IsSingleDispatch)
                {
                    Guid?parentId = ServiceBusCausalityHelper.GetOwner(message);
                    return(new TriggeredFunctionData()
                    {
                        ParentId = parentId,
                        TriggerValue = this,
                        TriggerDetails = new Dictionary <string, string>()
                        {
                            { "MessageId", message.MessageId },
                            { "DeliveryCount", message.SystemProperties.DeliveryCount.ToString() },
                            { "EnqueuedTimeUtc", message.SystemProperties.EnqueuedTimeUtc.ToString() },
                            { "LockedUntilUtc", message.SystemProperties.LockedUntilUtc.ToString() },
                            { "SessionId", message.SessionId }
                        }
                    });
                }
                else
                {
                    Guid?parentId = ServiceBusCausalityHelper.GetOwner(message);

                    int        length         = Messages.Length;
                    string[]   messageIds     = new string[length];
                    int[]      deliveryCounts = new int[length];
                    DateTime[] enqueuedTimes  = new DateTime[length];
                    DateTime[] lockedUntils   = new DateTime[length];
                    string     sessionId      = string.Empty;

                    sessionId = Messages[0].SystemProperties.LockedUntilUtc.ToString();
                    for (int i = 0; i < Messages.Length; i++)
                    {
                        messageIds[i]     = Messages[i].MessageId;
                        deliveryCounts[i] = Messages[i].SystemProperties.DeliveryCount;
                        enqueuedTimes[i]  = Messages[i].SystemProperties.EnqueuedTimeUtc;
                        lockedUntils[i]   = Messages[i].SystemProperties.LockedUntilUtc;
                    }

                    return(new TriggeredFunctionData()
                    {
                        ParentId = parentId,
                        TriggerValue = this,
                        TriggerDetails = new Dictionary <string, string>()
                        {
                            { "MessageIdArray", string.Join(",", messageIds) },
                            { "DeliveryCountArray", string.Join(",", deliveryCounts) },
                            { "EnqueuedTimeUtcArray", string.Join(",", enqueuedTimes) },
                            { "LockedUntilArray", string.Join(",", lockedUntils) },
                            { "SessionId", sessionId }
                        }
                    });
                }
            }
            return(null);
        }
        public TriggeredFunctionData GetTriggerFunctionData()
        {
            if (Messages.Length > 0)
            {
                ServiceBusReceivedMessage message = Messages[0];
                if (IsSingleDispatch)
                {
                    Guid?parentId = ServiceBusCausalityHelper.GetOwner(message);
                    return(new TriggeredFunctionData()
                    {
                        ParentId = parentId,
                        TriggerValue = this,
                        TriggerDetails = new Dictionary <string, string>()
                        {
                            { "MessageId", message.MessageId },
                            { "SequenceNumber", message.SequenceNumber.ToString(CultureInfo.InvariantCulture) },
                            { "DeliveryCount", message.DeliveryCount.ToString(CultureInfo.InvariantCulture) },
                            { "EnqueuedTimeUtc", message.EnqueuedTime.ToUniversalTime().ToString("o") },
                            { "LockedUntilUtc", message.LockedUntil.ToUniversalTime().ToString("o") },
                            { "SessionId", message.SessionId }
                        }
                    });
                }
                else
                {
                    Guid?parentId = ServiceBusCausalityHelper.GetOwner(message);

                    int      length          = Messages.Length;
                    string[] messageIds      = new string[length];
                    int[]    deliveryCounts  = new int[length];
                    long[]   sequenceNumbers = new long[length];
                    string[] enqueuedTimes   = new string[length];
                    string[] lockedUntils    = new string[length];
                    string   sessionId       = Messages[0].SessionId;

                    for (int i = 0; i < Messages.Length; i++)
                    {
                        messageIds[i]      = Messages[i].MessageId;
                        sequenceNumbers[i] = Messages[i].SequenceNumber;
                        deliveryCounts[i]  = Messages[i].DeliveryCount;
                        enqueuedTimes[i]   = Messages[i].EnqueuedTime.ToUniversalTime().ToString("o");
                        lockedUntils[i]    = Messages[i].LockedUntil.ToUniversalTime().ToString("o");
                    }

                    return(new TriggeredFunctionData()
                    {
                        ParentId = parentId,
                        TriggerValue = this,
                        TriggerDetails = new Dictionary <string, string>()
                        {
                            { "MessageIdArray", string.Join(",", messageIds) },
                            { "SequenceNumberArray", string.Join(",", sequenceNumbers) },
                            { "DeliveryCountArray", string.Join(",", deliveryCounts) },
                            { "EnqueuedTimeUtcArray", string.Join(",", enqueuedTimes) },
                            { "LockedUntilArray", string.Join(",", lockedUntils) },
                            { "SessionId", sessionId }
                        }
                    });
                }
            }
            return(null);
        }