/// <summary> /// Build a single index asynchronously /// </summary> /// <param name="indexInstance">An activated AbstractIndexCreationTask instance</param> /// <param name="progressCallBack">A callback we can use to report on the progress of a batch job; default is null</param> /// <returns>A task containing an IndexBuildResult report for this specific index</returns> public Task<IndexBuildResult> BuildIndexAsync(AbstractIndexCreationTask indexInstance, Action<IndexBuildResult> progressCallBack = null) { return Task.Factory.StartNew(() => indexInstance.Execute(_documentStore)) .ContinueWith(result => { var indexBuildResult = new IndexBuildResult() {IndexName = indexInstance.IndexName, ConnectionString = _documentStore.Identifier}; if (result.IsCompleted && result.Exception == null) { indexBuildResult.Result = BuildResult.Created; } else if (result.IsCanceled) { indexBuildResult.Result = BuildResult.Cancelled; } else { indexBuildResult.Result = BuildResult.Failed; indexBuildResult.BuildException = result.Exception != null ? result.Exception.Flatten() : null; } if (progressCallBack != null) { progressCallBack.Invoke(indexBuildResult); } return indexBuildResult; }); }
public void StopIndexing(Action<IndexBuildResult> progressCallBack = null) { var indexBuildResult = new IndexBuildResult() { IndexName = "StopIndexing", ConnectionString = _documentStore.Identifier }; if (string.IsNullOrEmpty(_connectionString) || string.IsNullOrWhiteSpace(_connectionString)) { if (progressCallBack != null) { indexBuildResult.Result = BuildResult.Cancelled; indexBuildResult.BuildException = new Exception("No connection string provided"); progressCallBack.Invoke(indexBuildResult); } return; } //If RavenDB finds any connection string errors it will throw them here, and we will pass that back to the client as is. var connectionStringOptions = RavenConnectionStringParser.ParseNetworkedDbOptions(_connectionString); try { using (var webClient = new WebClient()) { if (connectionStringOptions.Credentials == null) { webClient.UseDefaultCredentials = true; } else { webClient.Credentials = connectionStringOptions.Credentials; } var result = webClient.UploadString(new Uri(new Uri(_documentStore.Url), "/admin/stopindexing"), "POST", ""); indexBuildResult.Result = BuildResult.Created; if (progressCallBack != null) { progressCallBack.Invoke(indexBuildResult); } } } catch (Exception e) { if (progressCallBack != null) { indexBuildResult.Result = BuildResult.Failed; indexBuildResult.BuildException = e; progressCallBack.Invoke(indexBuildResult); } } }
public Task<IndexBuildResult> DropIndexAsync(string indexName, Action<IndexBuildResult> progressCallBack) { return Task.Factory.StartNew(() => _documentStore.DatabaseCommands.DeleteIndex(indexName)) .ContinueWith(result => { var indexBuildResult = new IndexBuildResult() { IndexName = indexName, ConnectionString = _documentStore.Identifier }; if (result.IsCompleted && result.Exception == null) { indexBuildResult.Result = BuildResult.Deleted; } else if (result.IsCanceled) { indexBuildResult.Result = BuildResult.Cancelled; } else { indexBuildResult.Result = BuildResult.Failed; indexBuildResult.BuildException = result.Exception != null ? result.Exception.Flatten() : null; } if (progressCallBack != null) { progressCallBack.Invoke(indexBuildResult); } return indexBuildResult; }); }