예제 #1
0
        private void RaiseBeforeReadFileEvent(out bool cancel)
        {
            BeforeReadFileEventArgs beforeReadFileArgs = new BeforeReadFileEventArgs(CurrentFile);

            if (_currentFileEventNumber == 0)
            {
                RaiseBeforeReadFile(beforeReadFileArgs);
            }

            cancel = beforeReadFileArgs.Cancel;
        }
        private void RaiseBeforeReadFileEvent(out bool cancel)
        {
            BeforeReadFileEventArgs beforeReadFileArgs = new BeforeReadFileEventArgs(_logFilePath);

            if (_eventCount < 0)
            {
                RaiseBeforeReadFile(beforeReadFileArgs);
            }

            cancel = beforeReadFileArgs.Cancel;
        }
 protected void RaiseBeforeReadFile(BeforeReadFileEventArgs args)
 {
     BeforeReadFile?.Invoke(this, args);
 }
예제 #4
0
        public override bool Read()
        {
            try
            {
                BeforeReadFileEventArgs beforeReadFileArgs = new BeforeReadFileEventArgs(_logFilePath);
                if (_eventCount < 0)
                {
                    RaiseBeforeReadFile(beforeReadFileArgs);
                }

                if (beforeReadFileArgs.Cancel)
                {
                    _currentRow = null;
                    return(false);
                }

                #region bufferedRead

                if (_lastRowNumberFromBuffer == 0 ||
                    _lastRowNumberFromBuffer >= _readBufferSize)
                {
                    _readBuffer.Clear();
                    _lastRowNumberFromBuffer = 0;

                    using (_connection = new SQLiteConnection(ConnectionString))
                    {
                        _connection.Open();

                        string queryText = String.Format(
                            "Select\n" +
                            "    el.RowId,\n" +
                            "    el.Date AS Date,\n" +
                            "    el.ConnectId,\n" +
                            "    el.Session,\n" +
                            "    el.TransactionStatus,\n" +
                            "    el.TransactionDate,\n" +
                            "    el.TransactionId,\n" +
                            "    el.UserCode AS UserCode,\n" +
                            "    el.ComputerCode AS ComputerCode,\n" +
                            "    el.appCode AS ApplicationCode,\n" +
                            "    el.eventCode AS EventCode,\n" +
                            "    el.primaryPortCode AS PrimaryPortCode,\n" +
                            "    el.secondaryPortCode AS SecondaryPortCode,\n" +
                            "    el.workServerCode AS WorkServerCode,\n" +
                            "    el.Severity AS SeverityCode,\n" +
                            "    el.Comment AS Comment,\n" +
                            "    el.Data AS Data,\n" +
                            "    el.DataPresentation AS DataPresentation,\n" +
                            "    elm.metadataCode AS MetadataCode\n" +
                            "From\n" +
                            "    EventLog el\n" +
                            "    left join EventLogMetadata elm on el.RowId = elm.eventLogID\n" +
                            "    left join MetadataCodes mc on elm.metadataCode = mc.code\n" +
                            "Where RowID > {0}\n" +
                            "Order By rowID\n" +
                            "Limit {1}\n", _lastRowId, _readBufferSize);

                        using (SQLiteCommand cmd = new SQLiteCommand(queryText, _connection))
                        {
                            using (SQLiteDataReader reader = cmd.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    try
                                    {
                                        _readBuffer.Add(new RowData
                                        {
                                            RowID             = reader.GetInt64OrDefault(0),
                                            Period            = reader.GetInt64OrDefault(1).ToDateTimeFormat(),
                                            ConnectId         = reader.GetInt64OrDefault(2),
                                            Session           = reader.GetInt64OrDefault(3),
                                            TransactionStatus = GetTransactionStatus(reader.GetInt64OrDefault(4)),
                                            TransactionDate   = reader.GetInt64OrDefault(5).ToNullableDateTimeELFormat(),
                                            TransactionId     = reader.GetInt64OrDefault(6),
                                            User             = GetUserByCode(reader.GetInt64OrDefault(7)),
                                            Computer         = GetComputerByCode(reader.GetInt64OrDefault(8)),
                                            Application      = GetApplicationByCode(reader.GetInt64OrDefault(9)),
                                            Event            = GetEventByCode(reader.GetInt64OrDefault(10)),
                                            PrimaryPort      = GetPrimaryPortByCode(reader.GetInt64OrDefault(11)),
                                            SecondaryPort    = GetSecondaryPortByCode(reader.GetInt64OrDefault(12)),
                                            WorkServer       = GetWorkServerByCode(reader.GetInt64OrDefault(13)),
                                            Severity         = GetSeverityByCode(reader.GetInt64OrDefault(14)),
                                            Comment          = reader.GetStringOrDefault(15),
                                            Data             = reader.GetStringOrDefault(16).FromWin1251ToUTF8(),
                                            DataPresentation = reader.GetStringOrDefault(17),
                                            Metadata         = GetMetadataByCode(reader.GetInt64OrDefault(18))
                                        });
                                    }
                                    catch (Exception ex)
                                    {
                                        RaiseOnError(new OnErrorEventArgs(ex, reader.GetRowAsString(), false));
                                        _currentRow = null;
                                    }
                                }
                            }
                        }
                    }
                }

                #endregion

                if (_lastRowNumberFromBuffer >= _readBuffer.Count)
                {
                    RaiseAfterReadFile(new AfterReadFileEventArgs(_logFilePath));
                    _currentRow = null;
                    return(false);
                }

                RaiseBeforeRead(new BeforeReadEventArgs(null, _eventCount));

                _currentRow = _readBuffer
                              .Where(bufRow => bufRow.RowID > _lastRowId)
                              .First();
                _lastRowNumberFromBuffer += 1;
                _lastRowId = _currentRow.RowID;

                RaiseAfterRead(new AfterReadEventArgs(_currentRow, _eventCount));

                return(true);
            }
            catch (Exception ex)
            {
                RaiseOnError(new OnErrorEventArgs(ex, null, true));
                _currentRow = null;
                return(false);
            }
        }
        public override bool Read()
        {
            try
            {
                if (_stream == null)
                {
                    if (_logFilesWithData.Length <= _indexCurrentFile)
                    {
                        _currentRow = null;
                        return(false);
                    }

                    InitializeStream(_defaultBeginLineForLGF, _indexCurrentFile);
                    _currentFileEventNumber = 0;
                }
                _eventSource.Clear();

                BeforeReadFileEventArgs beforeReadFileArgs = new BeforeReadFileEventArgs(CurrentFile);
                if (_currentFileEventNumber == 0)
                {
                    RaiseBeforeReadFile(beforeReadFileArgs);
                }

                if (beforeReadFileArgs.Cancel)
                {
                    NextFile();
                    return(Read());
                }

                string sourceData;
                bool   newLine       = true;
                int    countBracket  = 0;
                bool   textBlockOpen = false;

                while (true)
                {
                    sourceData = _stream.ReadLine();
                    if (sourceData == null)
                    {
                        NextFile();
                        return(Read());
                    }

                    if (newLine)
                    {
                        _eventSource.Append(sourceData);
                    }
                    else
                    {
                        _eventSource.AppendLine();
                        _eventSource.Append(sourceData);
                    }

                    if (LogParserLGF.ItsEndOfEvent(sourceData, ref countBracket, ref textBlockOpen))
                    {
                        newLine = true;
                        _currentFileEventNumber += 1;
                        string prepearedSourceData = _eventSource.ToString();

                        RaiseBeforeRead(new BeforeReadEventArgs(prepearedSourceData, _currentFileEventNumber));

                        try
                        {
                            RowData eventData = LogParser.Parse(prepearedSourceData);

                            if (eventData.Period >= ReferencesReadDate)
                            {
                                ReadEventLogReferences();
                                eventData = LogParser.Parse(prepearedSourceData);
                            }

                            _currentRow = eventData;
                        }
                        catch (Exception ex)
                        {
                            RaiseOnError(new OnErrorEventArgs(ex, prepearedSourceData, false));
                            _currentRow = null;
                        }

                        RaiseAfterRead(new AfterReadEventArgs(_currentRow, _currentFileEventNumber));

                        return(true);
                    }
                    else
                    {
                        newLine = false;
                    }
                }
            }
            catch (Exception ex)
            {
                RaiseOnError(new OnErrorEventArgs(ex, null, true));
                _currentRow = null;
                return(false);
            }
        }