private Task UpdateIndexInReplicationAsync(IAsyncDatabaseCommands asyncDatabaseCommands, DocumentConvention documentConvention, IndexDefinition indexDefinition) { var asyncServerClient = asyncDatabaseCommands as AsyncServerClient; if (asyncServerClient == null) { return(new CompletedTask()); } return(asyncServerClient.GetAsync("Raven/Replication/Destinations").ContinueWith(doc => { if (doc == null) { return new CompletedTask(); } var replicationDocument = documentConvention.CreateSerializer().Deserialize <ReplicationDocument>(new RavenJTokenReader(doc.Result.DataAsJson)); if (replicationDocument == null) { return new CompletedTask(); } var tasks = new List <Task>(); foreach (var replicationDestination in replicationDocument.Destinations) { tasks.Add(asyncServerClient.DirectPutIndexAsync(IndexName, indexDefinition, true, replicationDestination.Url)); } return Task.Factory.ContinueWhenAll(tasks.ToArray(), indexingTask => { foreach (var indexTask in indexingTask) { if (indexTask.IsFaulted) { Logger.WarnException("Could not put index in replication server", indexTask.Exception); } } }); }).Unwrap()); }
/// <summary> /// Toes the index definition. /// </summary> public IndexDefinition ToIndexDefinition(DocumentConvention convention, bool validateMap = true) { if (Map == null && validateMap) { throw new InvalidOperationException( string.Format("Map is required to generate an index, you cannot create an index without a valid Map property (in index {0}).", indexName)); } try { if (Reduce != null) { IndexDefinitionHelper.ValidateReduce(Reduce); } string querySource = (typeof(TDocument) == typeof(object) || ContainsWhereEntityIs()) ? "docs" : "docs." + convention.GetTypeTagName(typeof(TDocument)); var indexDefinition = new IndexDefinition { Reduce = IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode <TDocument, TReduceResult>(Reduce, convention, "results", translateIdentityProperty: false), Indexes = ConvertToStringDictionary(Indexes), Stores = ConvertToStringDictionary(Stores), SortOptions = ConvertToStringDictionary(SortOptions), Analyzers = ConvertToStringDictionary(Analyzers), SuggestionsOptions = ConvertToStringSet(SuggestionsOptions), TermVectors = ConvertToStringDictionary(TermVectors), SpatialIndexes = ConvertToStringDictionary(SpatialIndexes), DisableInMemoryIndexing = DisableInMemoryIndexing, MaxIndexOutputsPerDocument = MaxIndexOutputsPerDocument, LockMode = LockMode, }; #if !DNXCORE50 if (convention.PrettifyGeneratedLinqExpressions) { indexDefinition.Reduce = IndexPrettyPrinter.TryFormat(indexDefinition.Reduce); } #endif foreach (var indexesString in IndexesStrings) { if (indexDefinition.Indexes.ContainsKey(indexesString.Key)) { throw new InvalidOperationException("There is a duplicate key in indexes: " + indexesString.Key); } indexDefinition.Indexes.Add(indexesString); } foreach (var storeString in StoresStrings) { if (indexDefinition.Stores.ContainsKey(storeString.Key)) { throw new InvalidOperationException("There is a duplicate key in stores: " + storeString.Key); } indexDefinition.Stores.Add(storeString); } foreach (var analyzerString in AnalyzersStrings) { if (indexDefinition.Analyzers.ContainsKey(analyzerString.Key)) { throw new InvalidOperationException("There is a duplicate key in analyzers: " + analyzerString.Key); } indexDefinition.Analyzers.Add(analyzerString); } foreach (var termVectorString in TermVectorsStrings) { if (indexDefinition.TermVectors.ContainsKey(termVectorString.Key)) { throw new InvalidOperationException("There is a duplicate key in term vectors: " + termVectorString.Key); } indexDefinition.TermVectors.Add(termVectorString); } foreach (var spatialString in SpatialIndexesStrings) { if (indexDefinition.SpatialIndexes.ContainsKey(spatialString.Key)) { throw new InvalidOperationException("There is a duplicate key in spatial indexes: " + spatialString.Key); } indexDefinition.SpatialIndexes.Add(spatialString); } foreach (var sortOption in SortOptionsStrings) { if (indexDefinition.SortOptions.ContainsKey(sortOption.Key)) { throw new InvalidOperationException("There is a duplicate key in sort options: " + sortOption.Key); } indexDefinition.SortOptions.Add(sortOption); } if (Map != null) { indexDefinition.Map = IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode <TDocument, TReduceResult>( Map, convention, querySource, translateIdentityProperty: true); #if !DNXCORE50 if (convention.PrettifyGeneratedLinqExpressions) { indexDefinition.Map = IndexPrettyPrinter.TryFormat(indexDefinition.Map); } #endif } return(indexDefinition); } catch (Exception e) { throw new IndexCompilationException("Failed to create index " + indexName, e); } }