mirror of
https://github.com/BDDSM/YY.EventLogReaderAssistant.git
synced 2024-11-21 10:05:51 +02:00
Изменена основная логика чтения
- Метод Read() выполняется без аргументов. Доступ к текущей строке осуществляется через свойство "Row" - Избавился от излишних классов строки данных - Привел в порядок основную демо программу работы с библиотекой
This commit is contained in:
parent
3eb641ca86
commit
d0d7944f00
@ -20,7 +20,7 @@ namespace YY.EventLogAssistant
|
||||
}
|
||||
}
|
||||
private SQLiteConnection _connection;
|
||||
private List<EventLogRowData> _readBuffer;
|
||||
private List<RowData> _readBuffer;
|
||||
private long _lastRowId;
|
||||
private const int _readBufferSize = 10000;
|
||||
private long _lastRowNumberFromBuffer;
|
||||
@ -29,12 +29,12 @@ namespace YY.EventLogAssistant
|
||||
internal EventLogLGDReader() : base() { }
|
||||
internal EventLogLGDReader(string logFilePath) : base(logFilePath)
|
||||
{
|
||||
_readBuffer = new List<EventLogRowData>();
|
||||
_readBuffer = new List<RowData>();
|
||||
_lastRowId = 0;
|
||||
_lastRowNumberFromBuffer = 0;
|
||||
}
|
||||
|
||||
public override bool Read(out EventLogRowData rowData)
|
||||
public override bool Read()
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -44,7 +44,7 @@ namespace YY.EventLogAssistant
|
||||
|
||||
if (beforeReadFileArgs.Cancel)
|
||||
{
|
||||
rowData = null;
|
||||
_currentRow = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ namespace YY.EventLogAssistant
|
||||
{
|
||||
try
|
||||
{
|
||||
EventLogRowData bufferRowData = new EventLogRowData();
|
||||
RowData bufferRowData = new RowData();
|
||||
bufferRowData.RowID = reader.GetInt64OrDefault(0);
|
||||
bufferRowData.Period = reader.GetInt64OrDefault(1).ToDateTimeFormat();
|
||||
bufferRowData.ConnectId = reader.GetInt64OrDefault(2);
|
||||
@ -123,7 +123,7 @@ namespace YY.EventLogAssistant
|
||||
catch (Exception ex)
|
||||
{
|
||||
RaiseOnError(new OnErrorEventArgs(ex, reader.GetRowAsString(), false));
|
||||
rowData = null;
|
||||
_currentRow = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -136,26 +136,26 @@ namespace YY.EventLogAssistant
|
||||
if (_lastRowNumberFromBuffer >= _readBuffer.Count)
|
||||
{
|
||||
RaiseAfterReadFile(new AfterReadFileEventArgs(_logFilePath));
|
||||
rowData = null;
|
||||
_currentRow = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
RaiseBeforeRead(new BeforeReadEventArgs(null, _eventCount));
|
||||
|
||||
rowData = _readBuffer
|
||||
_currentRow = _readBuffer
|
||||
.Where(bufRow => bufRow.RowID > _lastRowId)
|
||||
.First();
|
||||
_lastRowNumberFromBuffer = _lastRowNumberFromBuffer + 1;
|
||||
_lastRowId = rowData.RowID;
|
||||
_lastRowId = _currentRow.RowID;
|
||||
|
||||
RaiseAfterRead(new AfterReadEventArgs(rowData, _eventCount));
|
||||
RaiseAfterRead(new AfterReadEventArgs(_currentRow, _eventCount));
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
RaiseOnError(new OnErrorEventArgs(ex, null, true));
|
||||
rowData = null;
|
||||
_currentRow = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ namespace YY.EventLogAssistant
|
||||
_eventSource = new StringBuilder();
|
||||
}
|
||||
|
||||
public override bool Read(out EventLogRowData rowData)
|
||||
public override bool Read()
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -62,7 +62,7 @@ namespace YY.EventLogAssistant
|
||||
{
|
||||
if (_logFilesWithData.Length <= _indexCurrentFile)
|
||||
{
|
||||
rowData = null;
|
||||
_currentRow = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ namespace YY.EventLogAssistant
|
||||
if (beforeReadFileArgs.Cancel)
|
||||
{
|
||||
NextFile();
|
||||
return Read(out rowData);
|
||||
return Read();
|
||||
}
|
||||
|
||||
string sourceData;
|
||||
@ -92,7 +92,7 @@ namespace YY.EventLogAssistant
|
||||
if (sourceData == null)
|
||||
{
|
||||
NextFile();
|
||||
return Read(out rowData);
|
||||
return Read();
|
||||
}
|
||||
|
||||
if (newLine)
|
||||
@ -115,16 +115,16 @@ namespace YY.EventLogAssistant
|
||||
|
||||
try
|
||||
{
|
||||
EventLogRowData eventData = LogParser.Parse(prepearedSourceData);
|
||||
rowData = eventData;
|
||||
RowData eventData = LogParser.Parse(prepearedSourceData);
|
||||
_currentRow = eventData;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RaiseOnError(new OnErrorEventArgs(ex, prepearedSourceData, false));
|
||||
rowData = null;
|
||||
_currentRow = null;
|
||||
}
|
||||
|
||||
RaiseAfterRead(new AfterReadEventArgs(rowData, _currentFileEventNumber));
|
||||
RaiseAfterRead(new AfterReadEventArgs(_currentRow, _currentFileEventNumber));
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -137,7 +137,7 @@ namespace YY.EventLogAssistant
|
||||
catch (Exception ex)
|
||||
{
|
||||
RaiseOnError(new OnErrorEventArgs(ex, null, true));
|
||||
rowData = null;
|
||||
_currentRow = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -393,13 +393,13 @@ namespace YY.EventLogAssistant
|
||||
_reader = reader;
|
||||
}
|
||||
|
||||
public EventLogRowData Parse(string eventSource)
|
||||
public RowData Parse(string eventSource)
|
||||
{
|
||||
var parseResult = ParseEventLogString(eventSource);
|
||||
|
||||
DateTime eventDate = DateTime.ParseExact(parseResult[0], "yyyyMMddHHmmss", CultureInfo.InvariantCulture);
|
||||
|
||||
EventLogRowData eventData = new EventLogRowData();
|
||||
RowData eventData = new RowData();
|
||||
eventData.RowID = _reader.CurrentFileEventNumber;
|
||||
eventData.Period = eventDate;
|
||||
|
||||
|
@ -58,6 +58,7 @@ namespace YY.EventLogAssistant
|
||||
protected List<SecondaryPorts> _secondaryPorts;
|
||||
protected List<Users> _users;
|
||||
protected List<WorkServers> _workServers;
|
||||
protected RowData _currentRow;
|
||||
|
||||
public delegate void BeforeReadFileHandler(EventLogReader sender, BeforeReadFileEventArgs args);
|
||||
public delegate void AfterReadFileHandler(EventLogReader sender, AfterReadFileEventArgs args);
|
||||
@ -118,10 +119,11 @@ namespace YY.EventLogAssistant
|
||||
public IReadOnlyList<SecondaryPorts> SecondaryPorts { get { return _secondaryPorts; } }
|
||||
public IReadOnlyList<Users> Users { get { return _users; } }
|
||||
public IReadOnlyList<WorkServers> WorkServers { get { return _workServers; } }
|
||||
public RowData Row { get { return _currentRow; } }
|
||||
|
||||
protected virtual void ReadEventLogReferences() { }
|
||||
|
||||
public virtual bool Read(out EventLogRowData rowData)
|
||||
public virtual bool Read()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@ -166,6 +168,7 @@ namespace YY.EventLogAssistant
|
||||
_secondaryPorts.Clear();
|
||||
_users.Clear();
|
||||
_workServers.Clear();
|
||||
_currentRow = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,13 +5,13 @@ namespace YY.EventLogAssistant
|
||||
{
|
||||
public sealed class AfterReadEventArgs : EventArgs
|
||||
{
|
||||
public AfterReadEventArgs(EventLogRowData rowData, long eventNumber)
|
||||
public AfterReadEventArgs(RowData rowData, long eventNumber)
|
||||
{
|
||||
RowData = rowData;
|
||||
EventNumber = eventNumber;
|
||||
}
|
||||
|
||||
public EventLogRowData RowData { get; }
|
||||
public RowData RowData { get; }
|
||||
public long EventNumber { get; }
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ namespace YY.EventLogAssistant
|
||||
{
|
||||
internal interface IEventLogReader
|
||||
{
|
||||
bool Read(out EventLogRowData rowData);
|
||||
bool Read();
|
||||
bool GoToEvent(long eventNumber);
|
||||
EventLogPosition GetCurrentPosition();
|
||||
void SetCurrentPosition(EventLogPosition newPosition);
|
||||
|
@ -19,13 +19,13 @@ namespace YY.EventLogAssistant
|
||||
regexDataUUID = new Regex(@"[\d]+:[\dA-Za-zА-Яа-я]{32}}");
|
||||
}
|
||||
|
||||
public EventLogRowData Parse(string eventSource)
|
||||
public RowData Parse(string eventSource)
|
||||
{
|
||||
var parseResult = ParseEventLogString(eventSource);
|
||||
|
||||
DateTime eventDate = DateTime.ParseExact(parseResult[0], "yyyyMMddHHmmss", CultureInfo.InvariantCulture);
|
||||
|
||||
EventLogRowData eventData = new EventLogRowData();
|
||||
RowData eventData = new RowData();
|
||||
eventData.RowID = _reader.CurrentFileEventNumber;
|
||||
eventData.Period = eventDate;
|
||||
|
||||
|
@ -1,27 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace YY.EventLogAssistant.Models
|
||||
{
|
||||
public class EventLogRowData : RowData
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public Severity Severity { get; set; }
|
||||
public long? ConnectId { get; set; }
|
||||
public long? Session { get; set; }
|
||||
public TransactionStatus TransactionStatus { get; set; }
|
||||
public DateTime? TransactionDate { get; set; }
|
||||
public long? TransactionId { get; set; }
|
||||
public Users User { get; set; }
|
||||
public Computers Computer { get; set; }
|
||||
public Applications Application { get; set; }
|
||||
public Events Event { get; set; }
|
||||
public string Comment { get; set; }
|
||||
public Metadata Metadata { get; set; }
|
||||
public string Data { get; set; }
|
||||
public string DataUUID { get; set; }
|
||||
public string DataPresentation { get; set; }
|
||||
public WorkServers WorkServer { get; set; }
|
||||
public PrimaryPorts PrimaryPort { get; set; }
|
||||
public SecondaryPorts SecondaryPort { get; set; }
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace YY.EventLogAssistant.Models
|
||||
{
|
||||
public abstract class RowData
|
||||
public class RowData
|
||||
{
|
||||
[Key]
|
||||
[Column(Order = 1)]
|
||||
@ -15,5 +15,24 @@ namespace YY.EventLogAssistant.Models
|
||||
[Key]
|
||||
[Column(Order = 3)]
|
||||
public long RowID { get; set; }
|
||||
public long Id { get; set; }
|
||||
public Severity Severity { get; set; }
|
||||
public long? ConnectId { get; set; }
|
||||
public long? Session { get; set; }
|
||||
public TransactionStatus TransactionStatus { get; set; }
|
||||
public DateTime? TransactionDate { get; set; }
|
||||
public long? TransactionId { get; set; }
|
||||
public Users User { get; set; }
|
||||
public Computers Computer { get; set; }
|
||||
public Applications Application { get; set; }
|
||||
public Events Event { get; set; }
|
||||
public string Comment { get; set; }
|
||||
public Metadata Metadata { get; set; }
|
||||
public string Data { get; set; }
|
||||
public string DataUUID { get; set; }
|
||||
public string DataPresentation { get; set; }
|
||||
public WorkServers WorkServer { get; set; }
|
||||
public PrimaryPorts PrimaryPort { get; set; }
|
||||
public SecondaryPorts SecondaryPort { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Services\" />
|
||||
<Folder Include="Models\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -11,63 +11,54 @@ namespace YY.EventLogAssistantConsoleApp
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string testDataDirectoryPath = $"{ Environment.CurrentDirectory}{Path.DirectorySeparatorChar}TestData\\1Cv8.lgf";
|
||||
if (args.Length == 0)
|
||||
return;
|
||||
|
||||
EventLogReader reader = EventLogReader.CreateReader(testDataDirectoryPath);
|
||||
string dataDirectoryPath = args[0];
|
||||
Console.WriteLine($"{DateTime.Now}: Инициализация чтения логов ({dataDirectoryPath})...");
|
||||
|
||||
EventLogReader reader = EventLogReader.CreateReader(dataDirectoryPath);
|
||||
reader.AfterReadEvent += Reader_AfterReadEvent;
|
||||
reader.AfterReadFile += Reader_AfterReadFile;
|
||||
reader.BeforeReadEvent += Reader_BeforeReadEvent;
|
||||
reader.BeforeReadFile += Reader_BeforeReadFile;
|
||||
reader.OnErrorEvent += Reader_OnErrorEvent;
|
||||
|
||||
// Пример задания точного положения для чтения в файле. Для формата *.lgf
|
||||
//reader.SetCurrentPosition(new EventLogPosition(
|
||||
// 5,
|
||||
// reader.LogFilePath,
|
||||
// reader.LogFilePath,
|
||||
// 436));
|
||||
Console.WriteLine($"{DateTime.Now}: Всего событий к обработке: ({reader.Count()})...");
|
||||
|
||||
Console.WriteLine($"Всего событий: {reader.Count()}");
|
||||
while (reader.Read())
|
||||
_eventNumber += 1;
|
||||
|
||||
long totalEvents = 0;
|
||||
EventLogRowData rowData;
|
||||
while (reader.Read(out rowData))
|
||||
totalEvents += 1;
|
||||
|
||||
Console.WriteLine("Для выхода нажмите любую клавишу...");
|
||||
Console.WriteLine($"{DateTime.Now}: Для выхода нажмите любую клавишу...");
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
private static void Reader_BeforeReadFile(EventLogReader sender, BeforeReadFileEventArgs args)
|
||||
{
|
||||
// Пример получения текущей позиции чтения
|
||||
var positionBeforeReadFile = sender.GetCurrentPosition();
|
||||
|
||||
Console.WriteLine("Reader_BeforeReadFile");
|
||||
Console.WriteLine($"{DateTime.Now}: Начало чтения файла \"{args.FileName}\"");
|
||||
Console.WriteLine($"{DateTime.Now}: {_eventNumber}");
|
||||
}
|
||||
|
||||
private static void Reader_AfterReadFile(EventLogReader sender, AfterReadFileEventArgs args)
|
||||
{
|
||||
// Пример получения текущей позиции чтения
|
||||
var positionAfterReadFile = sender.GetCurrentPosition();
|
||||
|
||||
Console.WriteLine("Reader_AfterReadFile");
|
||||
Console.WriteLine($"{DateTime.Now}: Окончание чтения файла \"{args.FileName}\"");
|
||||
}
|
||||
|
||||
private static void Reader_BeforeReadEvent(EventLogReader sender, BeforeReadEventArgs args)
|
||||
{
|
||||
_eventNumber += 1;
|
||||
Console.WriteLine($"Reader_BeforeReadEvent: {_eventNumber}");
|
||||
Console.SetCursorPosition(0, Console.CursorTop - 1);
|
||||
Console.WriteLine($"{DateTime.Now}: (+){_eventNumber}");
|
||||
}
|
||||
|
||||
private static void Reader_AfterReadEvent(EventLogReader sender, AfterReadEventArgs args)
|
||||
{
|
||||
Console.WriteLine($"Reader_AfterReadEvent {_eventNumber}");
|
||||
Console.SetCursorPosition(0, Console.CursorTop - 1);
|
||||
Console.WriteLine($"{DateTime.Now}: [+]{_eventNumber}");
|
||||
}
|
||||
|
||||
private static void Reader_OnErrorEvent(EventLogReader sender, OnErrorEventArgs args)
|
||||
{
|
||||
Console.WriteLine("Reader_OnErrorEvent");
|
||||
Console.WriteLine($"{DateTime.Now}: Ошибка чтения логов \"{args.Exception}\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"profiles": {
|
||||
"YY.EventLogAssistantConsoleApp": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "\"\\\\Srv-1c-01-vm\\жр lgf (генератор событий)\""
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user