/// <summary> /// Creates the indexes found in the specified catalog /// </summary> public static async Task CreateIndexesAsync(ExportProvider catalogToGetnIndexingTasksFrom, IAsyncDatabaseCommands databaseCommands, DocumentConvention conventions) { var indexCompilationExceptions = new List <IndexCompilationException>(); bool failed = false; try { var tasks = catalogToGetnIndexingTasksFrom .GetExportedValues <AbstractIndexCreationTask>() .ToList(); var indexesNames = tasks.Select(x => x.IndexName).ToArray(); var definitions = tasks.Select(x => x.CreateIndexDefinition()).ToArray(); var priorities = tasks.Select(x => x.Priority ?? IndexingPriority.Normal).ToArray(); await databaseCommands.PutIndexesAsync(indexesNames, definitions, priorities).ConfigureAwait(false); foreach (var task in tasks) { await task.AfterExecuteAsync(databaseCommands, conventions).ConfigureAwait(false); } } // For old servers that don't have the new entrypoint for executing multiple indexes catch (Exception) { failed = true; } if (failed) { foreach (var task in catalogToGetnIndexingTasksFrom.GetExportedValues <AbstractIndexCreationTask>()) { try { await task.ExecuteAsync(databaseCommands, conventions).ConfigureAwait(false); } catch (IndexCompilationException e) { indexCompilationExceptions.Add(new IndexCompilationException("Failed to compile index name = " + task.IndexName, e)); } } } foreach (var task in catalogToGetnIndexingTasksFrom.GetExportedValues <AbstractTransformerCreationTask>()) { await task.ExecuteAsync(databaseCommands, conventions).ConfigureAwait(false); } if (indexCompilationExceptions.Any()) { throw new AggregateException("Failed to create one or more indexes. Please see inner exceptions for more details.", indexCompilationExceptions); } }
/// <summary> /// Creates the indexes found in the specified assembly. /// </summary> public static async Task CreateIndexesAsync(Assembly assemblyToScan, IAsyncDatabaseCommands databaseCommands, DocumentConvention conventions) { var indexCompilationExceptions = new List <IndexCompilationException>(); try { var tasks = GetAllInstancesOfType <AbstractIndexCreationTask>(assemblyToScan) .ToList(); var indexesToAdd = CreateIndexesToAdd(tasks, conventions); await databaseCommands.PutIndexesAsync(indexesToAdd).ConfigureAwait(false); foreach (var task in tasks) { await task.AfterExecuteAsync(databaseCommands, conventions).ConfigureAwait(false); } } // For old servers that don't have the new endpoint for executing multiple indexes catch (Exception ex) { Log.InfoException("Could not create indexes in one shot (maybe using older version of RavenDB ?)", ex); foreach (var task in GetAllInstancesOfType <AbstractIndexCreationTask>(assemblyToScan)) { try { await task.ExecuteAsync(databaseCommands, conventions).ConfigureAwait(false); } catch (IndexCompilationException e) { indexCompilationExceptions.Add(new IndexCompilationException("Failed to compile index name = " + task.IndexName, e)); } } } await CreateTransformersAsync(assemblyToScan, databaseCommands, conventions).ConfigureAwait(false); if (indexCompilationExceptions.Any()) { throw new AggregateException("Failed to create one or more indexes. Please see inner exceptions for more details.", indexCompilationExceptions); } }
/// <summary> /// Creates the indexes found in the specified catalog /// </summary> public static async Task CreateIndexesAsync(ExportProvider catalogToGetnIndexingTasksFrom, IAsyncDatabaseCommands databaseCommands, DocumentConvention conventions) { var indexCompilationExceptions = new List<IndexCompilationException>(); bool failed = false; try { var tasks = catalogToGetnIndexingTasksFrom .GetExportedValues<AbstractIndexCreationTask>() .ToList(); var indexesNames = tasks.Select(x => x.IndexName).ToArray(); var definitions = tasks.Select(x => x.CreateIndexDefinition()).ToArray(); var priorities = tasks.Select(x => x.Priority ?? IndexingPriority.Normal).ToArray(); await databaseCommands.PutIndexesAsync(indexesNames, definitions, priorities).ConfigureAwait(false); foreach (var task in tasks) await task.AfterExecuteAsync(databaseCommands, conventions).ConfigureAwait(false); } // For old servers that don't have the new entrypoint for executing multiple indexes catch (Exception) { failed = true; } if (failed) { foreach (var task in catalogToGetnIndexingTasksFrom.GetExportedValues<AbstractIndexCreationTask>()) { try { await task.ExecuteAsync(databaseCommands, conventions).ConfigureAwait(false); } catch (IndexCompilationException e) { indexCompilationExceptions.Add(new IndexCompilationException("Failed to compile index name = " + task.IndexName, e)); } } } foreach (var task in catalogToGetnIndexingTasksFrom.GetExportedValues<AbstractTransformerCreationTask>()) { await task.ExecuteAsync(databaseCommands, conventions).ConfigureAwait(false); } if (indexCompilationExceptions.Any()) throw new AggregateException("Failed to create one or more indexes. Please see inner exceptions for more details.", indexCompilationExceptions); }
/// <summary> /// Creates the indexes found in the specified catalog /// </summary> public static async Task CreateIndexesAsync(ExportProvider catalogToGetnIndexingTasksFrom, IAsyncDatabaseCommands databaseCommands, DocumentConvention conventions) { var indexCompilationExceptions = new List<IndexCompilationException>(); var failed = false; try { var tasks = catalogToGetnIndexingTasksFrom .GetExportedValues<AbstractIndexCreationTask>() .ToList(); var indexesToAdd = CreateIndexesToAdd(tasks, conventions); await databaseCommands.PutIndexesAsync(indexesToAdd).ConfigureAwait(false); foreach (var task in tasks) await task.AfterExecuteAsync(databaseCommands, conventions).ConfigureAwait(false); } // For old servers that don't have the new endpoint for executing multiple indexes catch (Exception) { failed = true; } if (failed) { foreach (var task in catalogToGetnIndexingTasksFrom.GetExportedValues<AbstractIndexCreationTask>()) { try { await task.ExecuteAsync(databaseCommands, conventions).ConfigureAwait(false); } catch (IndexCompilationException e) { indexCompilationExceptions.Add(new IndexCompilationException("Failed to compile index name = " + task.IndexName, e)); } } } await CreateTransformersAsync(catalogToGetnIndexingTasksFrom, databaseCommands, conventions).ConfigureAwait(false); if (indexCompilationExceptions.Any()) throw new AggregateException("Failed to create one or more indexes. Please see inner exceptions for more details.", indexCompilationExceptions); }