| | 1 | | // Copyright (c) Microsoft. All rights reserved. |
| | 2 | | // Licensed under the MIT license. See LICENSE file in the project root for full license information.using System; |
| | 3 | |
|
| | 4 | | namespace Microsoft.Azure.EventHubs.ServiceFabricProcessor |
| | 5 | | { |
| | 6 | | using System; |
| | 7 | | using System.Fabric; |
| | 8 | | using System.Fabric.Query; |
| | 9 | | using System.Threading.Tasks; |
| | 10 | |
|
| | 11 | | class ServiceFabricPartitionLister : IFabricPartitionLister |
| | 12 | | { |
| | 13 | | private ServicePartitionList partitionList = null; |
| | 14 | |
|
| | 15 | | public async Task<int> GetServiceFabricPartitionCount(Uri serviceFabricServiceName) |
| | 16 | | { |
| 0 | 17 | | using (FabricClient fabricClient = new FabricClient()) |
| | 18 | | { |
| 0 | 19 | | this.partitionList = await fabricClient.QueryManager.GetPartitionListAsync(serviceFabricServiceName).Con |
| 0 | 20 | | } |
| 0 | 21 | | return this.partitionList.Count; |
| 0 | 22 | | } |
| | 23 | |
|
| | 24 | | public Task<int> GetServiceFabricPartitionOrdinal(Guid serviceFabricPartitionId) |
| | 25 | | { |
| 0 | 26 | | int ordinal = -1; |
| 0 | 27 | | for (int a = 0; a < partitionList.Count; a++) |
| | 28 | | { |
| 0 | 29 | | if (this.partitionList[a].PartitionInformation.Id == serviceFabricPartitionId) |
| | 30 | | { |
| 0 | 31 | | ordinal = a; |
| 0 | 32 | | break; |
| | 33 | | } |
| | 34 | | } |
| 0 | 35 | | return Task.FromResult<int>(ordinal); |
| | 36 | | } |
| | 37 | | } |
| | 38 | | } |