public static async Task<HashPartitionResolver> InitializeHashResolver(string partitionKeyPropertyName, DocumentClient client, Database database, string[] collectionNames)
{
// Set local to input.
string[] CollectionNames = collectionNames;
int numCollectionNames = CollectionNames.Length;
// Create array of DocumentCollections.
DocumentCollection[] collections = new DocumentCollection[numCollectionNames];
// Create string array of Self Links to Collections.
string[] selfLinks = new string[numCollectionNames];
//Create some collections to partition data.
for (int i = 0; i < numCollectionNames; i++)
{
collections[i] = await DocumentClientHelper.GetCollectionAsync(client, database, CollectionNames[i]);
selfLinks[i] = collections[i].SelfLink;
}
// Join Self Link Array into a comma separated string.
string selfLinkString = String.Join(", ", selfLinks);
//Initialize a partition resolver that users hashing, and register with DocumentClient.
//Uses User Id for PartitionKeyPropertyName, could also be TenantId, or any other variable.
HashPartitionResolver hashResolver = new HashPartitionResolver(partitionKeyPropertyName, new[] { selfLinkString });
client.PartitionResolvers[database.SelfLink] = hashResolver;
return hashResolver;
}