Exemplo n.º 1
0
        public frmLogViewer(LogApp app, Dictionary <string, List <LogRecord> > lstRecord)
        {
            InitializeComponent();

            this.Text = "浏览从" + app.Name + "的日志文件中读取的日志";

            foreach (string s in lstRecord.Keys)
            {
                LogTable lt = app.GetTable(s);

                LogShowTabPage page = new LogShowTabPage(lt.Name);
                page.ResetCloumns(lt);
                page.SetLogs(lstRecord[s]);

                page.Parent = this.myTabControl1;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 计算几张表中相同的检索条件
        /// </summary>
        /// <returns></returns>
        private void ReCalculateCommonFilter()
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                Dictionary <int, LogColumn> commonFilters = new Dictionary <int, LogColumn>();
                Dictionary <int, int>       DctTime       = new Dictionary <int, int>(); // 用这个来保存命中次数
                int selectedTablesCount = 0;                                             // 如果命中次数和选中的表的数量相同,则说明是共同条件

                foreach (ListViewItem lvi in this.lstLogSource.Items)
                {
                    if (lvi.Checked)
                    {
                        LogTable lt = m_app.GetTable(Convert.ToString(lvi.Tag));
                        selectedTablesCount++;

                        foreach (LogTableItem item in lt.Columns)
                        {
                            if (item.IsFilterColumn && item.Visible)
                            {
                                if (commonFilters.ContainsKey(item.LogColumnIndex))
                                {
                                    DctTime[item.LogColumnIndex]++;
                                }
                                else
                                {
                                    commonFilters.Add(item.LogColumnIndex, LogColumnService.Instance.GetLogColumn(item.LogColumnIndex));
                                    DctTime.Add(item.LogColumnIndex, 1);
                                }
                            }
                        }
                    }
                }

                this.dgvConditions.SuspendLayout();
                this.dgvConditions.Rows.Clear();

                foreach (int key in commonFilters.Keys)
                {
                    if (DctTime[key] == selectedTablesCount)
                    {
                        string[] avaliableRelations = RelationService.Instance.GetAvaliableRelations(commonFilters[key].Type).ToArray();

                        if (avaliableRelations.Length > 0)
                        {
                            IRelation relation = RelationService.Instance.GetRelation(commonFilters[key].Type,
                                                                                      avaliableRelations[0]);

                            this.dgvConditions.Rows.Add(new object[] { false, commonFilters[key].Name,
                                                                       string.Empty, relation.ParamsCount == 1?relation.DefaultValue:string.Empty,
                                                                       relation.ParamsCount == 1?string.Empty:relation.DefaultValue,
                                                                       relation.ParamsCount == 1?string.Empty:relation.DefaultValue });

                            DataGridViewRow dgvr = this.dgvConditions.Rows[this.dgvConditions.Rows.Count - 1];
                            dgvr.Tag = key;

                            DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)dgvr.Cells[RelationColumnIndex];
                            cell.Items.Clear();
                            cell.Items.AddRange(avaliableRelations);
                            cell.Value = cell.Items[0];
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("设置条件检索失败,错误消息为:" + ex.Message);
            }
            finally
            {
                this.Cursor = Cursors.Default;
                this.dgvConditions.ResumeLayout();
            }
        }
Exemplo n.º 3
0
        private void LogConsumer()
        {
            try
            {
                int      count             = 1;
                string   previousTableGuid = string.Empty;
                LogApp   app   = null;
                LogTable table = null;
                List <EvaluateResult> lstResults = new List <EvaluateResult>();

                LogRecordsPool.Instance.ResetBreakSign();

                while ((!LogRecordsPool.Instance.GetFinishSign()) ||
                       (!LogRecordsPool.Instance.IsPoolEmpty()))
                {
                    LogRecord record = LogRecordsPool.Instance.GetOneLogRecord();

                    if (record == null)
                    {
                        continue;
                    }

                    if (string.Compare(previousTableGuid, record.TableGuid, true) != 0)
                    {
                        app   = AppService.Instance.GetApp(record.AppGuid);
                        table = app.GetTable(record.TableGuid);

                        previousTableGuid = record.TableGuid;
                        count             = 1;
                    }

                    this.lblStatus.Invoke(new UpdateInfoDelegate(UpdateInfo), new object[] { app.Name, table.Name, count.ToString() });

                    foreach (IRuleProcessor p in RulesService.Instance.ImmediatelyReturnProcessors)
                    {
                        p.Execute(record, LogColumnService.Instance);
                        lstResults.AddRange(p.Result);
                    }

                    foreach (IRuleProcessor p in RulesService.Instance.FinalReturnProcessors)
                    {
                        p.Execute(record, LogColumnService.Instance);
                    }

                    count++;
                }

                foreach (IRuleProcessor p in RulesService.Instance.FinalReturnProcessors)
                {
                    p.Analysis();
                    lstResults.AddRange(p.Result);
                }

#if DEBUG
                Console.WriteLine("show rule result");
#endif

                if (!LogRecordsPool.Instance.GetBreakSign())
                {
                    this.BeginInvoke(new ShowResultDelegate(ShowResult),
                                     new object[] { lstResults });
                }
            }
            catch (ThreadAbortException)
            {
                Thread.ResetAbort();
            }
            catch (Exception ex)
            {
                MessageBox.Show("日志分析失败,错误消息为:" + ex.Message);
            }
            finally
            {
                this.Invoke(new CleanDelegate(Clean));
            }
        }