public void TestGetParseResult2()
        {
            var res = LogFilterInterpreter.GetFilterParseResult("a || ");

            Assert.AreEqual(false, res.Succeed);
            Assert.AreEqual("a || ", res.Input);
        }
Ejemplo n.º 2
0
        private IFilter GetCurrentFilter()
        {
            var pattern = this.toolStripComboBoxString.Text;

            if (!string.IsNullOrEmpty(pattern))
            {
                if (this.toolStripComboBoxString.Items.Contains(pattern))
                {
                    this.toolStripComboBoxString.Items.Remove(pattern);
                }

                this.toolStripComboBoxString.Items.Insert(0, pattern);
                this.toolStripComboBoxString.SelectedIndex = 0;
                if (this.toolStripComboBoxString.Items.Count > Settings.Default.Data_MaxHistoryCount)
                {
                    this.toolStripComboBoxString.Items.RemoveAt(Settings.Default.Data_MaxHistoryCount);
                }
                Settings.Default.Data_FilteringHistory.Clear();
                Settings.Default.Data_FilteringHistory.AddRange(this.toolStripComboBoxString.Items.Cast <string>().ToArray());
                Settings.Default.Save();

                return(LogFilterInterpreter.Parse(pattern));
            }
            else
            {
                return(Filter.MatchAll);
            }
        }
        public void TestGetParseResult1()
        {
            var res = LogFilterInterpreter.GetFilterParseResult("a");

            Assert.AreEqual(true, res.Succeed);
            Assert.AreEqual("a", res.Input);
            Assert.AreEqual("(\"a\")", res.Ast.EvalToString(true));
        }
Ejemplo n.º 4
0
        private void filterWithTheSameThreadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var selectedItem = this.GetSelectedItem();

            if (selectedItem == null)
            {
                return;
            }

            var threadId = selectedItem.ThreadId;

            this.CreateChild(LogFilterInterpreter.Parse($"t:{threadId}"));
        }
Ejemplo n.º 5
0
        private void Find(int startIndex, bool direction)
        {
            if (this.CurrentView == null)
            {
                return;
            }
            var f = LogFilterInterpreter.Parse(this.toolStripTextBoxPattern.Text);

            var bw = new BackgroundWorker();

            bw.WorkerReportsProgress     = true;
            this.progressBarMain.Visible = true;
            this.progressBarMain.Value   = 0;

            bw.RunWorkerCompleted += (s, e1) =>
            {
                int selection = (int)e1.Result;
                if (selection != -1)
                {
                    this.dataGridViewMain.ClearSelection();
                    this.dataGridViewMain.CurrentCell = this.dataGridViewMain[0, (int)e1.Result];
                }
                this.toolStripStatusLabel.Text = "Ready";
                this.progressBarMain.Visible   = false;

                bw.Dispose();
            };

            bw.ProgressChanged += (s, e1) =>
            {
                if (this.progressBarMain.Value < e1.ProgressPercentage)
                {
                    this.progressBarMain.Value     = e1.ProgressPercentage;
                    this.toolStripStatusLabel.Text = $"Searching ... {e1.ProgressPercentage}%";
                }
            };

            bw.DoWork += (s, e1) =>
            {
                var currentView = this.CurrentView;
                foreach (int progress in currentView.Find(f, startIndex, direction))
                {
                    bw.ReportProgress(progress);
                }

                e1.Result = currentView.SelectedRowIndex ?? -1;
            };

            bw.RunWorkerAsync();
        }
Ejemplo n.º 6
0
        private void toolStripButtonFilter_Click(object sender, EventArgs e)
        {
            if (this.CurrentView == null)
            {
                return;
            }

            var childView = this.CurrentView.CreateChild(LogFilterInterpreter.Parse(this.toolStripTextBoxPattern.Text));

            childView.ItemAdded += this.UpdateMainGridRowCount;

            var node = this.treeViewDoc.SelectedNode.Nodes.Add(childView.Name, childView.Name);

            node.Tag = childView;
            this.treeViewDoc.SelectedNode = node;
        }
Ejemplo n.º 7
0
        private void toolStripButtonCount_Click(object sender, EventArgs e)
        {
            if (this.CurrentView == null)
            {
                return;
            }
            IFilter f = LogFilterInterpreter.Parse(this.toolStripTextBoxPattern.Text);

            var bw = new BackgroundWorker();

            bw.WorkerReportsProgress     = true;
            this.progressBarMain.Visible = true;
            this.progressBarMain.Value   = 0;

            bw.RunWorkerCompleted += (s, e1) =>
            {
                this.toolStripLabelCount.Text  = e1.Result.ToString();
                this.toolStripStatusLabel.Text = "Ready";
                this.progressBarMain.Visible   = false;

                bw.Dispose();
            };

            bw.ProgressChanged += (s, e1) =>
            {
                if (this.progressBarMain.Value != e1.ProgressPercentage)
                {
                    this.progressBarMain.Value     = e1.ProgressPercentage;
                    this.toolStripStatusLabel.Text = $"Counting ... {e1.ProgressPercentage}%";
                }
            };

            bw.DoWork += (s, e1) =>
            {
                var currentView = this.CurrentView;
                foreach (int progress in currentView.Count(f))
                {
                    bw.ReportProgress(progress);
                }

                e1.Result = currentView.LastCountResult ?? 0;
            };

            bw.RunWorkerAsync();
        }
Ejemplo n.º 8
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            this.cts = new CancellationTokenSource();
            var pi = this.dataGridViewMain.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);

            pi.SetValue(this.dataGridViewMain, true);

            this.boldFont   = new Font(this.dataGridViewMain.Font, FontStyle.Bold);
            this.normalFont = this.dataGridViewMain.Font;

            this.foreColorBrush          = new SolidBrush(this.dataGridViewMain.DefaultCellStyle.ForeColor);
            this.selectionForeColorBrush = new SolidBrush(this.dataGridViewMain.DefaultCellStyle.SelectionForeColor);

            this.defaultStringFormat = new StringFormat(StringFormatFlags.NoWrap)
            {
                Trimming      = StringTrimming.EllipsisCharacter,
                LineAlignment = StringAlignment.Center,
            };

            int i = 0;

            this.toolStripSplitButtonTag.DropDownItems.AddRange(this.tags.Select(t => new ToolStripMenuItem($"Tag {++i}", null, (s, e1) =>
            {
                int index = int.Parse(((ToolStripMenuItem)s).Text.Substring(4)) - 1;
                if (this.CurrentView == null)
                {
                    return;
                }
                var currentMenuItem     = (ToolStripMenuItem)s;
                bool tag                = !string.IsNullOrEmpty(this.toolStripTextBoxPattern.Text);
                currentMenuItem.Checked = tag;
                this.TagCurrentView(index, tag ? LogFilterInterpreter.Parse(this.toolStripTextBoxPattern.Text) : null);
            })
            {
                BackColor = t.Item1,
            }).ToArray());

            this.toolStripSplitButtonTag.DefaultItem  = this.toolStripSplitButtonTag.DropDownItems[0];
            this.toolStripSplitButtonFind.DefaultItem = this.findNextToolStripMenuItem;

            this.openToolStripMenuItem_Click(this, null);
        }
Ejemplo n.º 9
0
        private async void buttonSearch_Click(object sender, EventArgs e)
        {
            try
            {
                this.cts?.Cancel();

                this.cts?.Dispose();
                this.EnableButtons(false);

                this.currentFinished    = 0;
                this.progressBar1.Value = 0;


                this.cts = new CancellationTokenSource();

                if (string.IsNullOrEmpty(this.comboBoxSearchPattern.Text))
                {
                    this.Filter = LogFlow.DataModel.Filter.MatchAll;
                }
                else
                {
                    this.Filter = LogFilterInterpreter.Parse(this.comboBoxSearchPattern.Text);
                }

                var filePaths = Directory.EnumerateFiles(
                    this.comboBoxSearchFolder.Text,
                    this.comboBoxFileNamePattern.Text,
                    this.checkBoxRecursive.Checked ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
                                .ToList();

                string extension = FileExtensionModule.GetFileExtension(filePaths);

                this.totalCount = filePaths.Count;

                this.dataGridViewResult.Rows.Clear();
                this.dataGridViewResult.Rows.AddRange(filePaths.Select(p => new DataGridViewRow()
                {
                    Cells =
                    {
                        new DataGridViewTextBoxCell()
                        {
                            Value = Path.GetFileName(p)
                        },
                        new DataGridViewTextBoxCell()
                        {
                            Value = string.Empty
                        },
                        new DataGridViewTextBoxCell()
                        {
                            Value = "0 %"
                        },
                    },
                    Tag = p,
                }).ToArray());

                int lineCount;
                int.TryParse(this.comboBoxLineCount.Text, out lineCount);

                var token = this.cts.Token;

                await Task.WhenAll(Enumerable.Range(0, filePaths.Count).Select(i => Task.Run(() =>
                {
                    DataItemBase dataItem;

                    var logSource = LogSourceManager.Instance.GetLogSource(filePaths[i], new LogSourceProperties(
                                                                               false,
                                                                               true),
                                                                           extension);

                    try
                    {
                        foreach (var progress in logSource.Peek(this.Filter, lineCount, token))
                        {
                            if (token.IsCancellationRequested)
                            {
                                return;
                            }
                            this.dataGridViewResult.Rows[i].Cells[2].Value = $"{progress} %";
                        }
                        if (string.IsNullOrEmpty(this.dataGridViewResult.Rows[i].Cells[1].Value as string) && logSource.Count > 0)
                        {
                            dataItem = logSource[0];
                            this.dataGridViewResult.Rows[i].Cells[1].Value = string.Format(
                                logSource.Templates[dataItem.TemplateId],
                                dataItem.Parameters.Cast <object>().ToArray());
                        }
                        if (token.IsCancellationRequested)
                        {
                            return;
                        }
                        this.dataGridViewResult.Rows[i].Cells[2].Value = "100 %";

                        this.currentFinished++;
                    }
                    finally
                    {
                        (logSource as IDisposable)?.Dispose();

                        if (!token.IsCancellationRequested)
                        {
                            this.progressBar1.Invoke(
                                new Action(() => this.progressBar1.Value = 100 * this.currentFinished / this.totalCount));
                        }
                    }
                }, token)));

                if (token.IsCancellationRequested)
                {
                    return;
                }
                this.progressBar1.Value = 100;
                this.EnableButtons(true);

                // add to history
                Settings.Default.Data_RecentDirectories.Clear();
                Settings.Default.Data_RecentDirectories.AddRange(this.AdjustHistoryOfComboBox(this.comboBoxSearchFolder));
                Settings.Default.Data_FileNamePatterns.Clear();
                Settings.Default.Data_FileNamePatterns.AddRange(
                    this.AdjustHistoryOfComboBox(this.comboBoxFileNamePattern));

                Settings.Default.Data_SearchRecursive = this.checkBoxRecursive.Checked;

                Settings.Default.Save();
            }
            catch (ObjectDisposedException ex1)
            {
                Debug.WriteLine($"ObjectDisposedException in Search_Click: {ex1}");
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format(Resources.SearchFailedText, ex), Resources.SomethingWrong, MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
        public void TestAndSyntaxSugar3()
        {
            string res = LogFilterInterpreter.Parse("a (b)").EvalToString(true);

            Assert.AreEqual("((\"a\") && ((\"b\")))", res);
        }
        public void TestUnary3()
        {
            string res = LogFilterInterpreter.Parse("a && !(!b)").EvalToString(true);

            Assert.AreEqual("((\"a\") && (!((!(\"b\")))))", res);
        }
        public void TestLeftAssociate()
        {
            string res = LogFilterInterpreter.Parse("a && b || d").EvalToString(true);

            Assert.AreEqual("(((\"a\") && (\"b\")) || (\"d\"))", res);
        }
        public void TestParenthesis2()
        {
            string res = LogFilterInterpreter.Parse("a && (b || d)").EvalToString(false);

            Assert.AreEqual("\"a\" && (\"b\" || \"d\")", res);
        }
        public void TestParenthesis1()
        {
            string res = LogFilterInterpreter.Parse("a && (b || d)").EvalToString(true);

            Assert.AreEqual("((\"a\") && (((\"b\") || (\"d\"))))", res);
        }