Exemplo n.º 1
0
        private List <IndexJob> BuildIndexJobs(string tableName, long startRow, long batchSize, long endRow, string indexFilePath)
        {
            const string BatchFmt = "{0} WHERE [__RowNumber] >= {1} AND [__RowNumber] < {2} ";

            StringBuilder selectSqlBase = new StringBuilder();

            selectSqlBase.AppendFormat("SELECT TOP {0} * FROM [{1}] WITH (NOLOCK)", endRow, tableName);

            bool            useBatch  = (endRow > batchSize);
            string          selectSql = null;
            List <IndexJob> jobs      = new List <IndexJob>();

            while (startRow < endRow)
            {
                if (useBatch)
                {
                    selectSql = string.Format(BatchFmt,
                                              selectSqlBase.ToString(), startRow, startRow + batchSize > endRow ? endRow : startRow + batchSize);
                }
                else
                {
                    selectSql = selectSqlBase.ToString();
                }

                DTTableSource dataSource = new DTTableSource(null);
                dataSource.TableInfo = new TableInfo(tableName, selectSql, null);

                string   indexPath = startRow > 1 ? Path.Combine(indexFilePath, startRow.ToString()) : indexFilePath;
                IndexJob indexJob  = _factory.GetCreateIndexJob(indexPath, dataSource);
                jobs.Add(indexJob);

                startRow += batchSize;
            }

            return(jobs);
        }
Exemplo n.º 2
0
        private void DoExecution(IndexJob job, TextBox textBoxStatus)
        {
            // Monitor the job execution thread as it progresses
            IndexProgressInfo status = new IndexProgressInfo();

            while (job.IsThreadDone(500, status) == false)
            {
                // Set the status text based on the current indexing step
                switch (status.Step)
                {
                case IndexingStep.ixStepBegin:
                    textBoxStatus.Text = "Opening index";
                    break;

                case IndexingStep.ixStepCheckingFiles:
                    textBoxStatus.Text = "Checking files";
                    break;

                case IndexingStep.ixStepCompressing:
                    textBoxStatus.Text = "Compressing index";
                    break;

                case IndexingStep.ixStepCreatingIndex:
                    textBoxStatus.Text = "Creating index";
                    break;

                case IndexingStep.ixStepDone:
                    textBoxStatus.Text = "Indexing Complete";
                    break;

                case IndexingStep.ixStepMerging:
                    textBoxStatus.Text = "Merging words into index";
                    break;

                case IndexingStep.ixStepNone:
                    textBoxStatus.Text = string.Empty;
                    break;

                case IndexingStep.ixStepReadingFiles:
                    textBoxStatus.Text = status.File.Name;
                    break;

                case IndexingStep.ixStepStoringWords:
                    textBoxStatus.Text = status.File.Name + " (storing words)";
                    break;

                default:
                    textBoxStatus.Text = string.Empty;
                    break;
                }

                // Let other form events be handled while we're looping
                Application.DoEvents();

                DTTableSource ds = (DTTableSource)job.DataSourceToIndex;
                if (ds != null) // Only applies to Indexing job
                {
                    _textBoxProcessed.Text = ds.RecordProcessed.ToString();
                    if (_stopRequested)
                    {
                        ds.StopRequested = true;
                    }
                }
            }

            // If there were errors, display the errors as additions to the
            // status text
            JobErrorInfo err = job.Errors;

            for (int i = 0; i < err.Count; i++)
            {
                textBoxStatus.Text = textBoxStatus.Text + " " + err.Message(i);
            }
        }