예제 #1
0
        private static void SearchFolder(SearchParameters sp, string searchPath, IDictionary <string, Exception> failedFiles, List <Match> matches, ToolStripStatusLabel status, Control fileCount)
        {
            if (sp.CancellationToken.IsCancellationRequested ||
                (sp.StopAfterN.HasValue && matches.Count >= sp.StopAfterN.Value) ||
                !Directory.Exists(searchPath) ||
                sp.SkipFolders().Any(skip => searchPath.ToUpper().Contains(skip.ToUpper()) ||
                                     skip.ToUpper().Contains(searchPath.ToUpper())))
            {
                return;
            }

            MultiThread.UpdateToolStripStatus(status, searchPath);
            SearchFiles(sp, searchPath, failedFiles, matches);
            MultiThread.SetProperty(fileCount, "Text", "Found Files:" + matches.Count);

            if (!sp.IsRecursive)
            {
                return;
            }

            var dirs = Directory.GetDirectories(searchPath);

            foreach (var dir in dirs)
            {
                SearchFolder(sp, dir, failedFiles, matches, status, fileCount);
            }
        }
예제 #2
0
        private void PostSearchUiCleanup(Dictionary <string, Exception> failedFiles)
        {
            foreach (var key in failedFiles.Keys)
            {
                AddWarning($"Skipped {key}: {failedFiles[key]}");
            }
            PopulateRows();

            MultiThread.SetProperty(btnSearch, "Enabled", true);
            MultiThread.UpdateToolStripStatus(lblStatus, _stop ? $"Stopped: {_dataSource.Rows.Count} hits"   : $"Done: {_dataSource.Rows.Count} hits");
            var endTime  = DateTime.Now;
            var duration = endTime - _startTime;

            MultiThread.UpdateToolStripStatus(lblStopped, $@"Stop Search: {endTime:HH:mm:ss}");
            AddInfo($@"Stop Search: {endTime:HH:mm:ss}");
            MultiThread.UpdateToolStripStatus(lblDuration, $@"Duration: {duration.TotalSeconds}s");


            foreach (Control c in Controls)
            {
                if (c is Button || c is CheckBox || c is TextBox)
                {
                    MultiThread.SetProperty(c, "Enabled", true);
                }
            }

            MultiThread.SetProperty(btnStop, "BackColor", SystemColors.Control);
            MultiThread.SetProperty(btnStop, "Enabled", false);
            MultiThread.SetProperty(btnStop, "Visible", false);

            MultiThread.InvokeMethod(txtSearchString, "Focus", null);
            MultiThread.SetProperty(grdResults, "DataSource", _dataSource);

            MultiThread.SetProperty(tabControl, "SelectedIndex", 0);

            //might be a better way to do this, but this works.
            if (grdResults.Columns.Count > 0)
            {
                foreach (DataGridViewColumn col in grdResults.Columns)
                {
                    MultiThread.SetChildProperty(grdResults, col, "AutoSizeMode", DataGridViewAutoSizeColumnMode.AllCells);
                }
                foreach (DataGridViewColumn col in grdResults.Columns)
                {
                    int w = col.Width;
                    MultiThread.SetChildProperty(grdResults, col, "AutoSizeMode", DataGridViewAutoSizeColumnMode.None);
                    MultiThread.SetChildProperty(grdResults, col, "Width", w);
                }
            }

            MultiThread.SetProperty(tabControl, "Visible", true);
            MultiThread.InvokeMethod(grdResults, "Focus", null);
        }