Example #1
0
        /// <summary>
        /// Async method for building tasks in parallel - can be called directly by the application if they want to wait on the results of the tasks
        /// </summary>
        /// <param name="progressCallback">An optional callback method to update the caller on the job's progress</param>
        /// <returns>A list of Tasks which return IndexBuildReports, one for each database</returns>
        public IList<Task<IndexBuildReport>> BuildAsync(Action<IndexBuildResult> progressCallback = null)
        {
            //Load our assemblies and initialize our connections to the databases
            LoadAssemblies();
            LoadDbInstances();

            var tasks = new List<Task<IndexBuildReport>>();

            //Iterate over our collection of DB instances
            foreach (var ravenInstance in RavenInstances)
            {
                //Create a new index builder
                var indexBuilder = new IndexBuilder(ravenInstance.Value, IndexAssemblies.ToArray());
                tasks.Add(indexBuilder.RunAsync(BuildInstructions, progressCallback));
            }

            return tasks;
        }
Example #2
0
        /// <summary>
        /// Synchronous method for reporting on the results of index build tasks across all assemblies and indexes
        /// </summary>
        /// <param name="progressCallback">An optional callback method that reports on the success of building an individual index</param>
        /// <returns>A list of IndexBuildReports, one for each database</returns>
        public IList<IndexBuildReport> BuildSequentially(Action<IndexBuildResult> progressCallback = null)
        {
            //Load our assemblies and initialize our connections to the databases
            LoadAssemblies();
            LoadDbInstances();

            var reports = new List<IndexBuildReport>();

            //Iterate over our collection of DB instances
            foreach (var ravenInstance in RavenInstances)
            {
                //Create a new index builder
                using (var indexBuilder = new IndexBuilder(ravenInstance.Value, IndexAssemblies.ToArray(), ravenInstance.Key))
                {
                    //Stop indexing
                    if(BuildInstructions.PauseIndexing)
                        indexBuilder.StopIndexing(progressCallback);

                    var buildReport = indexBuilder.Run(BuildInstructions, progressCallback);
                    reports.Add(buildReport);
                    if (buildReport.Failed > 0 && !BuildInstructions.ContinueJobOnFailure)
                    {
                        //Resume indexing
                        if (BuildInstructions.PauseIndexing)
                            indexBuilder.StartIndexing(progressCallback);

                        //Exit the loop
                        break;
                    }

                    //Resume indexing
                    if (BuildInstructions.PauseIndexing)
                        indexBuilder.StartIndexing(progressCallback);
                }

            }

            return reports;
        }