AngularAzureSearch.WebAPI.PartitionResolvers.SpilloverPartitionResolver.GetCollections C# (CSharp) Method

GetCollections() private method

Gets or creates the collections for the hash resolver.
private GetCollections ( Microsoft.Azure.Documents.Client.DocumentClient client, Microsoft.Azure.Documents.Database database, string collectionIdPrefix, DocumentCollectionSpec spec ) : List
client Microsoft.Azure.Documents.Client.DocumentClient The DocumentDB client instance.
database Microsoft.Azure.Documents.Database The database to use.
collectionIdPrefix string The prefix to use while creating collections.
spec AngularAzureSearch.WebAPI.Helpers.DocumentCollectionSpec The specification/template to use to create collections.
return List
        private List<string> GetCollections(
            DocumentClient client,
            Database database,
            string collectionIdPrefix,
            DocumentCollectionSpec spec)
        {
            var collections = new Dictionary<int, string>();
            foreach (DocumentCollection collection in client.ReadDocumentCollectionFeedAsync(database.SelfLink).Result)
            {
                if (collection.Id.StartsWith(collectionIdPrefix))
                {
                    int collectionNumber = int.Parse(collection.Id.Replace(collectionIdPrefix, string.Empty));
                    collections[collectionNumber] = collection.SelfLink;
                }
            }
            if (collections.Any())
            {
                NextCollectionNumber = collections.Keys.Max() + 1;
            }
            else
            {
                NextCollectionNumber = 0;
            }
            // Return selflinks in ID order
            return collections.OrderBy(kvp => kvp.Key).Select(kvp => kvp.Value).ToList();
        }