예제 #1
0
        /// <summary>
        /// Initialize a HashPartitionResolver that uses a custom function to extract the partition key.
        /// </summary>
        /// <param name="database">The database to run the samples on.</param>
        /// <returns>The created HashPartitionResolver.</returns>
        private async Task <HashPartitionResolver> InitializeCustomHashResolver(Database database)
        {
            DocumentCollection collection1 = await DocumentClientHelper.GetCollectionAsync(this.client, database, "Collection.HashBucket0");

            DocumentCollection collection2 = await DocumentClientHelper.GetCollectionAsync(this.client, database, "Collection.HashBucket1");

            var hashResolver = new HashPartitionResolver(
                u => ((UserProfile)u).UserId,
                new[] { collection1.SelfLink, collection2.SelfLink });

            this.client.PartitionResolvers[database.SelfLink] = hashResolver;
            return(hashResolver);
        }
예제 #2
0
        /// <summary>
        /// Initialize a HashPartitionResolver.
        /// </summary>
        /// <param name="database">The database to run the samples on.</param>
        /// <returns>The created HashPartitionResolver.</returns>
        private async Task <HashPartitionResolver> InitializeHashResolver(Database database)
        {
            // Create some collections to partition data.
            DocumentCollection collection1 = await DocumentClientHelper.GetCollectionAsync(this.client, database, "Collection.HashBucket0");

            DocumentCollection collection2 = await DocumentClientHelper.GetCollectionAsync(this.client, database, "Collection.HashBucket1");

            // Initialize a partition resolver that users hashing, and register with DocumentClient.
            HashPartitionResolver hashResolver = new HashPartitionResolver("UserId", new[] { collection1.SelfLink, collection2.SelfLink });

            this.client.PartitionResolvers[database.SelfLink] = hashResolver;

            return(hashResolver);
        }
예제 #3
0
        /// <summary>
        /// Initialize a HashPartitionResolver.
        /// </summary>
        /// <param name="database">The database to run the samples on.</param>
        /// <returns>The created HashPartitionResolver.</returns>
        private async Task <RangePartitionResolver <string> > InitializeRangeResolver(Database database)
        {
            // Create some collections to partition data.
            DocumentCollection collection1 = await DocumentClientHelper.GetCollectionAsync(this.client, database, "Collection.A-M");

            DocumentCollection collection2 = await DocumentClientHelper.GetCollectionAsync(this.client, database, "Collection.N-Z");

            // Initialize a partition resolver that assigns users (A-M) -> collection1, and (N-Z) -> collection2
            // and register with DocumentClient.
            // Note: \uffff is the largest UTF8 value, so M\ufff includes all strings that start with M.
            RangePartitionResolver <string> rangeResolver = new RangePartitionResolver <string>(
                "UserId",
                new Dictionary <Range <string>, string>()
            {
                { new Range <string>("A", "M\uffff"), collection1.SelfLink },
                { new Range <string>("N", "Z\uffff"), collection2.SelfLink },
            });

            this.client.PartitionResolvers[database.SelfLink] = rangeResolver;
            return(rangeResolver);
        }
예제 #4
0
        /// <summary>
        /// Initialize a LookupPartitionResolver.
        /// </summary>
        /// <param name="database">The database to run the samples on.</param>
        /// <returns>The created HashPartitionResolver.</returns>
        private async Task <LookupPartitionResolver <string> > InitializeLookupPartitionResolver(Database database)
        {
            DocumentCollection collectionUS = await DocumentClientHelper.GetCollectionAsync(this.client, database, "Collection.US");

            DocumentCollection collectionEU = await DocumentClientHelper.GetCollectionAsync(this.client, database, "Collection.Europe");

            DocumentCollection collectionOther = await DocumentClientHelper.GetCollectionAsync(this.client, database, "Collection.Other");

            // This implementation takes strings as input. If you'd like to implement a strongly typed LookupPartitionResolver,
            // take a look at EnumLookupPartitionResolver for an example.
            var lookupResolver = new LookupPartitionResolver <string>(
                "PrimaryRegion",
                new Dictionary <string, string>()
            {
                { Region.UnitedStatesEast.ToString(), collectionUS.SelfLink },
                { Region.UnitedStatesWest.ToString(), collectionUS.SelfLink },
                { Region.Europe.ToString(), collectionEU.SelfLink },
                { Region.AsiaPacific.ToString(), collectionOther.SelfLink },
                { Region.Other.ToString(), collectionOther.SelfLink },
            });

            this.client.PartitionResolvers[database.SelfLink] = lookupResolver;
            return(lookupResolver);
        }