EventHubListenerLib.EventHubListenerOptions.DistributeOverServicePartitions C# (CSharp) Метод

DistributeOverServicePartitions() приватный Метод

private DistributeOverServicePartitions ( string orderEventHubPartition ) : string[]
orderEventHubPartition string
Результат string[]
        private string[] DistributeOverServicePartitions(string[] orderEventHubPartition)
        {
            // service partitions are greater or equal
            // in this case each service partition gets an event hub partitions
            // the reminder partitions will just not gonna work on anything. 
            if (OrderedServicePartitionIds.Length >= orderEventHubPartition.Length)
            {
                int servicePartitionRank = Array.IndexOf(OrderedServicePartitionIds, CurrentSFPartitionId);

                if(servicePartitionRank < orderEventHubPartition.Length)
                    return new string[] { orderEventHubPartition[servicePartitionRank] };


                return new string[0];
            }
            else
            {
                // service partitions are less than event hub partitins, distribute.. 
                // service partitions can be odd or even. 

                int reminder = orderEventHubPartition.Length % OrderedServicePartitionIds.Length;
                int HubPartitionsPerServicePartitions = orderEventHubPartition.Length / OrderedServicePartitionIds.Length;
                int servicePartitionRank = Array.IndexOf(OrderedServicePartitionIds, CurrentSFPartitionId);

                List<string> assignedIds = new List<string>();
                for (int i = 0; i < HubPartitionsPerServicePartitions; i++)
                {
                    assignedIds.Add(orderEventHubPartition[(servicePartitionRank * HubPartitionsPerServicePartitions) + i]);
                }

                // last service partition gets the reminder
                if (servicePartitionRank == (OrderedServicePartitionIds.Length - 1))
                {
                    for (int i = reminder; i > 0; i--)
                    {
                        assignedIds.Add(orderEventHubPartition[orderEventHubPartition.Length - i]);
                    }
                }

                return assignedIds.ToArray();
            }
        }