Esempio n. 1
0
        private void AddIndexes(DocumentCollection collection, List <DocumentStoreConfig> storeConfigs)
        {
            foreach (var storeConfig in storeConfigs)
            {
                foreach (var config in storeConfig.Documents)
                {
                    var documentKey = CreateDocumentContentKey(storeConfig.StoreName, config.DocumentName);

                    foreach (var path in config.InclusionIndexes)
                    {
                        // Update the path to include the full content path.
                        var newPath = new IncludedPath
                        {
                            Path    = $"/{documentKey}{path.Path}",
                            Indexes = path.Indexes
                        };

                        collection.IndexingPolicy.IncludedPaths.Add(newPath);
                    }

                    foreach (var path in config.ExclusionIndexes)
                    {
                        // Update the path to include the full content path.
                        var newPath = new ExcludedPath
                        {
                            Path = $"/{documentKey}{path.Path}"
                        };

                        collection.IndexingPolicy.ExcludedPaths.Add(newPath);
                    }
                }
            }
        }
Esempio n. 2
0
        public PSExcludedPath(ExcludedPath excludedPath)
        {
            if (excludedPath == null)
            {
                return;
            }

            Path = excludedPath.Path;
        }
        public IndexingPolicyImpl <ParentImplT, IParentT, DefinitionParentT, UpdateParentT> WithExcludedPath(ExcludedPath excludedPath)
        {
            if (Inner.ExcludedPaths == null)
            {
                Inner.ExcludedPaths = new List <ExcludedPath>();
            }

            Inner.ExcludedPaths.Add(excludedPath);
            return(this);
        }
Esempio n. 4
0
        /// <summary>
        /// Creates the collection.
        /// </summary>
        /// <param name="db">The database.</param>
        /// <param name="collection">The collection</param>
        /// <param name="allowUpdate">if set to <c>true</c> [allow updates].</param>
        /// <returns>
        /// The Resource Response for collection
        /// </returns>
        /// <exception cref="InvalidOperationException">Document collection partition key cannot be changed.</exception>
        private async Task <DocumentCollection> CreateCollectionAsync(Microsoft.Azure.Documents.Database db, Collection collection, bool allowUpdate)
        {
            ResourceResponse <DocumentCollection> response = null;

            this.logger.Info("Checking whether {0} collection exists or not", collection.Name);
            var existingColl = this.client.CreateDocumentCollectionQuery(db.SelfLink).Where(x => x.Id == collection.Name).AsEnumerable().SingleOrDefault();

            this.logger.Info("Initializing {0} collection", collection.Name);
            var documentCollection = new DocumentCollection
            {
                Id = collection.Name,
                DefaultTimeToLive = collection.Ttl
            };

            // Setting up Partition Key
            if (collection.Partitioned && !string.IsNullOrEmpty(collection.PartitionKey))
            {
                this.logger.Info("Setting up Partition Key for the {0} collection", collection.Name);
                documentCollection.PartitionKey = new PartitionKeyDefinition();
                documentCollection.PartitionKey.Paths.Add(collection.PartitionKey);
            }

            // Excluded Paths
            foreach (var path in collection.ExcludedPaths)
            {
                this.logger.Info("Setting up excluded paths for the {0} collection", collection.Name);
                var excludedPaths = new ExcludedPath()
                {
                    Path = path
                };
                documentCollection.IndexingPolicy.ExcludedPaths.Add(excludedPaths);
            }

            // Included Paths
            foreach (var path in collection.IncludedPaths)
            {
                this.logger.Info("Setting up included path {0} for the {1} collection", path, collection.Name);
                var includedPaths = new IncludedPath()
                {
                    Path = path
                };
                documentCollection.IndexingPolicy.IncludedPaths.Add(includedPaths);
            }

            // Range Index Path
            foreach (var path in collection.RangeIndexIncludedPaths)
            {
                this.logger.Info("Setting up range included path {0} for the {1} collection", path, collection.Name);
                var includedPaths = new IncludedPath()
                {
                    Path = path, Indexes = new System.Collections.ObjectModel.Collection <Index> {
                        new RangeIndex(DataType.String)
                        {
                            Precision = -1
                        }
                    }
                };
                documentCollection.IndexingPolicy.IncludedPaths.Add(includedPaths);
            }

            documentCollection.IndexingPolicy.IndexingMode = this.GetIndexingMode(collection.IndexingMode);
            if (existingColl == null)
            {
                this.logger.Info("{0} Collection doesn't exist, Creating it", collection.Name);
                response = await this.client.CreateDocumentCollectionAsync(db.SelfLink, documentCollection, new RequestOptions { OfferThroughput = collection.ResourceUnits }).ConfigureAwait(false);
            }
            else if (allowUpdate)
            {
                this.logger.Info("{0} Collection exists, Updating the collection", collection.Name);

                var validationResult = ValidatePartitionKey(existingColl.PartitionKey, documentCollection.PartitionKey);
                if (validationResult)
                {
                    existingColl.PartitionKey = documentCollection.PartitionKey;
                }
                else
                {
                    throw new InvalidOperationException("Document collection partition key cannot be changed.");
                }

                existingColl.IndexingPolicy = documentCollection.IndexingPolicy;
                response = await this.client.ReplaceDocumentCollectionAsync(existingColl).ConfigureAwait(false);

                this.logger.Info("Updating throughput of the collection");
                var offer = this.client.CreateOfferQuery().Where(t => t.ResourceLink == existingColl.SelfLink).AsEnumerable().SingleOrDefault();
                if (offer != null)
                {
                    offer = new OfferV2(offer, collection.ResourceUnits);
                    await this.client.ReplaceOfferAsync(offer).ConfigureAwait(false);
                }
            }
            else
            {
                this.logger.Info("{0} Collection exists. Skipping update", collection.Name);
                response = new ResourceResponse <DocumentCollection>(existingColl);
            }

            if (response != null)
            {
                return(response.Resource);
            }

            return(null);
        }
Esempio n. 5
0
 public PSExcludedPath(ExcludedPath excludedPath)
 {
     Path = excludedPath.Path;
 }
 IndexingPolicy.Definition.IWithAttach <DefinitionParentT> IndexingPolicy.Definition.IWithExcludedPaths <DefinitionParentT> .WithExcludedPath(ExcludedPath excludedPath)
 {
     return(this.WithExcludedPath(excludedPath));
 }
 IndexingPolicy.Update.IUpdate <UpdateParentT> IndexingPolicy.Update.IWithExcludedPaths <UpdateParentT> .WithExcludedPath(ExcludedPath excludedPath)
 {
     return(this.WithExcludedPath(excludedPath));
 }
 public ExcludedPathViewModel(ExcludedPath excludedPath)
 {
     ExcludedPath = excludedPath;
 }
 public ExcludedPathViewModel()
 {
     ExcludedPath = new ExcludedPath();
 }