コード例 #1
0
        private void DoFilter(SearchParameters sp)
        {
            foreach (DataGridViewRow row in grdResults.Rows)
            {
                var rowText = new StringBuilder();
                foreach (DataGridViewCell cell in row.Cells)
                {
                    rowText.Append(cell.Value);
                }
                var itemText = rowText.ToString();

                //Check row text
                var match = Regex.IsMatch(itemText, sp.SearchString);

                //Check FileContents
                var filePath = Path.Combine(row.Cells["Directory"].Value.ToString(), row.Cells["Name"].Value.ToString());
                if (!match && sp.SearchType == SearchType.FileContents && File.Exists(filePath))
                {
                    match = Utility.SearchContents(sp, filePath, out var _);
                }

                var selectMatch = (string)MultiThread.GetProperty(ddlFilterInclude, "Text");
                if (match == (selectMatch == "Select Match"))
                {
                    row.Selected = true;
                }
            }

            PostFilterUiCleanup();
        }
コード例 #2
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);
            }
        }
コード例 #3
0
        private void PostFilterUiCleanup()
        {
            foreach (Control c in Controls)
            {
                MultiThread.SetProperty(c, "Enabled", true);
            }
            MultiThread.SetProperty(btnStop, "Enabled", false);
            MultiThread.SetProperty(btnStop, "BackColor", SystemColors.Control);

            AddInfo($@"End Filter: {_startTime:HH:mm:ss}");
        }
コード例 #4
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);
        }
コード例 #5
0
        private void AddLog(string message, LogType logType)
        {
            Color lineColor;

            switch (logType)
            {
            case LogType.Info:
                if (!_properties.LogInfo)
                {
                    return;
                }
                lineColor = Color.Black;
                break;

            case LogType.Warning:
                if (!_properties.LogWarning)
                {
                    return;
                }
                lineColor    = Color.BlueViolet;
                _newWarnings = true;
                tabControl.Refresh();
                break;

            case LogType.Error:
                if (!_properties.LogError)
                {
                    return;
                }
                lineColor  = Color.Red;
                _newErrors = true;
                tabControl.Refresh();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(logType), logType, null);
            }


            var preLength = int.Parse(MultiThread.GetProperty(rtbLog, "TextLength").ToString());

            MultiThread.InvokeMethod(rtbLog, "AppendText", new object[] { $"\r\n {DateTime.Now} - " });
            MultiThread.InvokeMethod(rtbLog, "AppendText", new object[] { message });

            var postLength = int.Parse(MultiThread.GetProperty(rtbLog, "TextLength").ToString());

            MultiThread.InvokeMethod(rtbLog, "Select", new object[] { preLength, postLength });

            MultiThread.SetProperty(rtbLog, "SelectionColor", lineColor);

            switch (logType)
            {
            case LogType.Info:
                MultiThread.SetProperty(rtbLog, "SelectionColor", Color.Black);
                break;

            case LogType.Warning:
                MultiThread.SetProperty(rtbLog, "SelectionColor", Color.BlueViolet);
                break;

            case LogType.Error:
                MultiThread.SetProperty(rtbLog, "SelectionColor", Color.Red);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(logType), logType, null);
            }

            MultiThread.InvokeMethod(rtbLog, "Select", new object[] { 0, 0 });
        }