You've already forked YY.EventLogReaderAssistant
mirror of
https://github.com/BDDSM/YY.EventLogReaderAssistant.git
synced 2025-06-30 22:14:05 +02:00
Рефакторинг модулей решения.
This commit is contained in:
@ -10,8 +10,8 @@ namespace YY.EventLogAssistant.Services.Tests
|
|||||||
{
|
{
|
||||||
#region Private Member Variables
|
#region Private Member Variables
|
||||||
|
|
||||||
private string sampleDataDirectory;
|
private readonly string sampleDataDirectory;
|
||||||
private string sampleDatabaseFile;
|
private readonly string sampleDatabaseFile;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -48,14 +48,12 @@ namespace YY.EventLogAssistant.Services.Tests
|
|||||||
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
|
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
|
||||||
{
|
{
|
||||||
connection.Open();
|
connection.Open();
|
||||||
using (SQLiteCommand command = new SQLiteCommand(queryText, connection))
|
using SQLiteCommand command = new SQLiteCommand(queryText, connection);
|
||||||
|
SQLiteDataReader reader = command.ExecuteReader();
|
||||||
|
if (reader.Read())
|
||||||
{
|
{
|
||||||
SQLiteDataReader reader = command.ExecuteReader();
|
DataPresentation = SQLiteExtensions.GetStringOrDefault(reader, 0);
|
||||||
if (reader.Read())
|
DataPresentationEmpty = SQLiteExtensions.GetStringOrDefault(reader, 1);
|
||||||
{
|
|
||||||
DataPresentation = SQLiteExtensions.GetStringOrDefault(reader, 0);
|
|
||||||
DataPresentationEmpty = SQLiteExtensions.GetStringOrDefault(reader, 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,14 +81,12 @@ namespace YY.EventLogAssistant.Services.Tests
|
|||||||
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
|
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
|
||||||
{
|
{
|
||||||
connection.Open();
|
connection.Open();
|
||||||
using (SQLiteCommand command = new SQLiteCommand(queryText, connection))
|
using SQLiteCommand command = new SQLiteCommand(queryText, connection);
|
||||||
|
SQLiteDataReader reader = command.ExecuteReader();
|
||||||
|
if (reader.Read())
|
||||||
{
|
{
|
||||||
SQLiteDataReader reader = command.ExecuteReader();
|
connectionId = SQLiteExtensions.GetInt64OrDefault(reader, 0);
|
||||||
if (reader.Read())
|
sessionId = SQLiteExtensions.GetInt64OrDefault(reader, 1);
|
||||||
{
|
|
||||||
connectionId = SQLiteExtensions.GetInt64OrDefault(reader, 0);
|
|
||||||
sessionId = SQLiteExtensions.GetInt64OrDefault(reader, 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,13 +115,11 @@ namespace YY.EventLogAssistant.Services.Tests
|
|||||||
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
|
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
|
||||||
{
|
{
|
||||||
connection.Open();
|
connection.Open();
|
||||||
using (SQLiteCommand command = new SQLiteCommand(queryText, connection))
|
using SQLiteCommand command = new SQLiteCommand(queryText, connection);
|
||||||
|
SQLiteDataReader reader = command.ExecuteReader();
|
||||||
|
if (reader.Read())
|
||||||
{
|
{
|
||||||
SQLiteDataReader reader = command.ExecuteReader();
|
rowAsString = reader.GetRowAsString();
|
||||||
if (reader.Read())
|
|
||||||
{
|
|
||||||
rowAsString = reader.GetRowAsString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int countLines = rowAsString.Split('\n').Where(str => str != string.Empty).Count();
|
int countLines = rowAsString.Split('\n').Where(str => str != string.Empty).Count();
|
||||||
@ -153,16 +147,14 @@ namespace YY.EventLogAssistant.Services.Tests
|
|||||||
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
|
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
|
||||||
{
|
{
|
||||||
connection.Open();
|
connection.Open();
|
||||||
using (SQLiteCommand command = new SQLiteCommand(queryText, connection))
|
using SQLiteCommand command = new SQLiteCommand(queryText, connection);
|
||||||
|
SQLiteDataReader reader = command.ExecuteReader();
|
||||||
|
if (reader.Read())
|
||||||
{
|
{
|
||||||
SQLiteDataReader reader = command.ExecuteReader();
|
object rowsCountObject = reader.GetValue(0);
|
||||||
if (reader.Read())
|
if (rowsCountObject is long)
|
||||||
{
|
{
|
||||||
object rowsCountObject = reader.GetValue(0);
|
rowsCount = Convert.ToInt64(rowsCountObject);
|
||||||
if (rowsCountObject is long)
|
|
||||||
{
|
|
||||||
rowsCount = Convert.ToInt64(rowsCountObject);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,9 +10,9 @@ namespace YY.EventLogAssistant.Services.Tests
|
|||||||
{
|
{
|
||||||
#region Private Member Variables
|
#region Private Member Variables
|
||||||
|
|
||||||
private string sampleDataDirectory;
|
private readonly string sampleDataDirectory;
|
||||||
private string sampleDatabaseFile;
|
private readonly string sampleDatabaseFile;
|
||||||
private string[] sampleFilesLGP;
|
private readonly string[] sampleFilesLGP;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -38,17 +38,13 @@ namespace YY.EventLogAssistant.Services.Tests
|
|||||||
string lineContent = string.Empty;
|
string lineContent = string.Empty;
|
||||||
using (StreamReader reader = new StreamReader(sampleDatabaseFile))
|
using (StreamReader reader = new StreamReader(sampleDatabaseFile))
|
||||||
{
|
{
|
||||||
using(StreamLineReader lineReader = new StreamLineReader(reader.BaseStream, reader.CurrentEncoding))
|
using StreamLineReader lineReader = new StreamLineReader(reader.BaseStream, reader.CurrentEncoding);
|
||||||
|
if (lineReader.GoToLine(1))
|
||||||
{
|
{
|
||||||
if(lineReader.GoToLine(1))
|
lineContent = lineReader.ReadLine();
|
||||||
{
|
|
||||||
lineContent = lineReader.ReadLine();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Guid.TryParse(lineContent, out Guid eventLogGuid);
|
||||||
Guid eventLogGuid = Guid.Empty;
|
|
||||||
Guid.TryParse(lineContent, out eventLogGuid);
|
|
||||||
|
|
||||||
Assert.NotEqual(Guid.Empty, eventLogGuid);
|
Assert.NotEqual(Guid.Empty, eventLogGuid);
|
||||||
}
|
}
|
||||||
@ -68,10 +64,8 @@ namespace YY.EventLogAssistant.Services.Tests
|
|||||||
long lineCounterLibrary = 0;
|
long lineCounterLibrary = 0;
|
||||||
using (StreamReader reader = new StreamReader(sampleDatabaseFile))
|
using (StreamReader reader = new StreamReader(sampleDatabaseFile))
|
||||||
{
|
{
|
||||||
using (StreamLineReader lineReader = new StreamLineReader(reader.BaseStream, reader.CurrentEncoding))
|
using StreamLineReader lineReader = new StreamLineReader(reader.BaseStream, reader.CurrentEncoding);
|
||||||
{
|
lineCounterLibrary = lineReader.GetCount();
|
||||||
lineCounterLibrary = lineReader.GetCount();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.Equal(lineCounterNative, lineCounterLibrary);
|
Assert.Equal(lineCounterNative, lineCounterLibrary);
|
||||||
@ -97,15 +91,13 @@ namespace YY.EventLogAssistant.Services.Tests
|
|||||||
List<string> resultLines = new List<string>();
|
List<string> resultLines = new List<string>();
|
||||||
using (StreamReader reader = new StreamReader(sampleDatabaseFile, utf8))
|
using (StreamReader reader = new StreamReader(sampleDatabaseFile, utf8))
|
||||||
{
|
{
|
||||||
using (StreamLineReader lineReader = new StreamLineReader(reader.BaseStream, reader.CurrentEncoding))
|
using StreamLineReader lineReader = new StreamLineReader(reader.BaseStream, reader.CurrentEncoding);
|
||||||
|
string currentLine = lineReader.ReadLine();
|
||||||
|
do
|
||||||
{
|
{
|
||||||
string currentLine = lineReader.ReadLine();
|
resultLines.Add(currentLine);
|
||||||
do
|
currentLine = lineReader.ReadLine();
|
||||||
{
|
} while (currentLine != null);
|
||||||
resultLines.Add(currentLine);
|
|
||||||
currentLine = lineReader.ReadLine();
|
|
||||||
} while (currentLine != null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.Equal(correctLines, resultLines);
|
Assert.Equal(correctLines, resultLines);
|
||||||
@ -134,36 +126,16 @@ namespace YY.EventLogAssistant.Services.Tests
|
|||||||
|
|
||||||
using (StreamReader reader = new StreamReader(fileLGP, utf8))
|
using (StreamReader reader = new StreamReader(fileLGP, utf8))
|
||||||
{
|
{
|
||||||
using (StreamLineReader lineReader = new StreamLineReader(reader.BaseStream, reader.CurrentEncoding))
|
using StreamLineReader lineReader = new StreamLineReader(reader.BaseStream, reader.CurrentEncoding);
|
||||||
|
string currentLine = lineReader.ReadLine();
|
||||||
|
while (currentLine != null)
|
||||||
{
|
{
|
||||||
string currentLine = lineReader.ReadLine();
|
resultLines.Add(currentLine);
|
||||||
while (currentLine != null)
|
currentLine = lineReader.ReadLine();
|
||||||
{
|
|
||||||
resultLines.Add(currentLine);
|
|
||||||
|
|
||||||
int cnt = resultLines.Count - 1;
|
|
||||||
if (correctLines[cnt] != resultLines[cnt])
|
|
||||||
{
|
|
||||||
int fff = 1;
|
|
||||||
} else if(cnt == 173)
|
|
||||||
{
|
|
||||||
int sdafdfa = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentLine = lineReader.ReadLine();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//for (int i = 0; i < correctLines.Count; i++)
|
|
||||||
//{
|
|
||||||
// if(correctLines[i] != resultLines[i])
|
|
||||||
// {
|
|
||||||
// int fff = 1;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
Assert.Equal(correctLines, resultLines);
|
Assert.Equal(correctLines, resultLines);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,8 +8,8 @@ namespace YY.EventLogAssistant.Services.Tests
|
|||||||
{
|
{
|
||||||
#region Private Member Variables
|
#region Private Member Variables
|
||||||
|
|
||||||
private string sampleDataDirectory;
|
private readonly string sampleDataDirectory;
|
||||||
private string sampleDatabaseFile;
|
private readonly string sampleDatabaseFile;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -62,8 +62,6 @@ namespace YY.EventLogAssistant.Services.Tests
|
|||||||
public void FromWin1251ToUTF8_Test()
|
public void FromWin1251ToUTF8_Test()
|
||||||
{
|
{
|
||||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||||
Encoding utf8 = Encoding.GetEncoding("UTF-8");
|
|
||||||
Encoding win1251 = Encoding.GetEncoding("windows-1251");
|
|
||||||
|
|
||||||
string sourceText = "Заказ звонка технической поддержки";
|
string sourceText = "Заказ звонка технической поддержки";
|
||||||
string checkValue = "Заказ звонка технической поддержки";
|
string checkValue = "Заказ звонка технической поддержки";
|
||||||
|
@ -22,7 +22,7 @@ namespace YY.EventLogAssistant
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private SQLiteConnection _connection;
|
private SQLiteConnection _connection;
|
||||||
private List<RowData> _readBuffer;
|
private readonly List<RowData> _readBuffer;
|
||||||
private long _lastRowId;
|
private long _lastRowId;
|
||||||
private const int _readBufferSize = 1000;
|
private const int _readBufferSize = 1000;
|
||||||
private long _lastRowNumberFromBuffer;
|
private long _lastRowNumberFromBuffer;
|
||||||
@ -107,28 +107,28 @@ namespace YY.EventLogAssistant
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
RowData bufferRowData = new RowData();
|
_readBuffer.Add(new RowData
|
||||||
bufferRowData.RowID = reader.GetInt64OrDefault(0);
|
{
|
||||||
bufferRowData.Period = reader.GetInt64OrDefault(1).ToDateTimeFormat();
|
RowID = reader.GetInt64OrDefault(0),
|
||||||
bufferRowData.ConnectId = reader.GetInt64OrDefault(2);
|
Period = reader.GetInt64OrDefault(1).ToDateTimeFormat(),
|
||||||
bufferRowData.Session = reader.GetInt64OrDefault(3);
|
ConnectId = reader.GetInt64OrDefault(2),
|
||||||
bufferRowData.TransactionStatus = (TransactionStatus)reader.GetInt64OrDefault(4);
|
Session = reader.GetInt64OrDefault(3),
|
||||||
bufferRowData.TransactionDate = reader.GetInt64OrDefault(5).ToNullableDateTimeELFormat();
|
TransactionStatus = GetTransactionStatus(reader.GetInt64OrDefault(4)),
|
||||||
bufferRowData.TransactionId = reader.GetInt64OrDefault(6);
|
TransactionDate = reader.GetInt64OrDefault(5).ToNullableDateTimeELFormat(),
|
||||||
bufferRowData.Severity = (Severity)reader.GetInt64OrDefault(15);
|
TransactionId = reader.GetInt64OrDefault(6),
|
||||||
bufferRowData.Comment = reader.GetStringOrDefault(16);
|
User = GetUserByCode(reader.GetInt64OrDefault(7)),
|
||||||
bufferRowData.Data = reader.GetStringOrDefault(17).FromWin1251ToUTF8();
|
Computer = GetComputerByCode(reader.GetInt64OrDefault(8)),
|
||||||
bufferRowData.DataPresentation = reader.GetStringOrDefault(18);
|
Application = GetApplicationByCode(reader.GetInt64OrDefault(9)),
|
||||||
bufferRowData.User = _users.Where(i => i.Code == reader.GetInt64OrDefault(7)).FirstOrDefault();
|
Event = GetEventByCode(reader.GetInt64OrDefault(10)),
|
||||||
bufferRowData.Computer = _computers.Where(i => i.Code == reader.GetInt64OrDefault(8)).FirstOrDefault();
|
PrimaryPort = GetPrimaryPortByCode(reader.GetInt64OrDefault(11)),
|
||||||
bufferRowData.Application = _applications.Where(i => i.Code == reader.GetInt64OrDefault(9)).FirstOrDefault();
|
SecondaryPort = GetSecondaryPortByCode(reader.GetInt64OrDefault(12)),
|
||||||
bufferRowData.Event = _events.Where(i => i.Code == reader.GetInt64OrDefault(10)).FirstOrDefault();
|
WorkServer = GetWorkServerByCode(reader.GetInt64OrDefault(13)),
|
||||||
bufferRowData.PrimaryPort = _primaryPorts.Where(i => i.Code == reader.GetInt64OrDefault(11)).FirstOrDefault();
|
Severity = GetSeverityByCode(reader.GetInt64OrDefault(14)),
|
||||||
bufferRowData.SecondaryPort = _secondaryPorts.Where(i => i.Code == reader.GetInt64OrDefault(12)).FirstOrDefault();
|
Comment = reader.GetStringOrDefault(15),
|
||||||
bufferRowData.WorkServer = _workServers.Where(i => i.Code == reader.GetInt64OrDefault(13)).FirstOrDefault();
|
Data = reader.GetStringOrDefault(16).FromWin1251ToUTF8(),
|
||||||
bufferRowData.Metadata = _metadata.Where(i => i.Code == reader.GetInt64OrDefault(18)).FirstOrDefault();
|
DataPresentation = reader.GetStringOrDefault(17),
|
||||||
|
Metadata = GetMetadataByCode(reader.GetInt64OrDefault(18))
|
||||||
_readBuffer.Add(bufferRowData);
|
});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -155,7 +155,7 @@ namespace YY.EventLogAssistant
|
|||||||
_currentRow = _readBuffer
|
_currentRow = _readBuffer
|
||||||
.Where(bufRow => bufRow.RowID > _lastRowId)
|
.Where(bufRow => bufRow.RowID > _lastRowId)
|
||||||
.First();
|
.First();
|
||||||
_lastRowNumberFromBuffer = _lastRowNumberFromBuffer + 1;
|
_lastRowNumberFromBuffer += 1;
|
||||||
_lastRowId = _currentRow.RowID;
|
_lastRowId = _currentRow.RowID;
|
||||||
|
|
||||||
RaiseAfterRead(new AfterReadEventArgs(_currentRow, _eventCount));
|
RaiseAfterRead(new AfterReadEventArgs(_currentRow, _eventCount));
|
||||||
@ -237,9 +237,12 @@ namespace YY.EventLogAssistant
|
|||||||
"From\n" +
|
"From\n" +
|
||||||
" EventLog el\n");
|
" EventLog el\n");
|
||||||
|
|
||||||
SQLiteCommand cmd = new SQLiteCommand(_connection);
|
SQLiteCommand cmd = new SQLiteCommand(_connection)
|
||||||
cmd.CommandType = System.Data.CommandType.Text;
|
{
|
||||||
cmd.CommandText = queryText;
|
CommandType = System.Data.CommandType.Text,
|
||||||
|
CommandText = queryText
|
||||||
|
};
|
||||||
|
|
||||||
SQLiteDataReader reader = cmd.ExecuteReader();
|
SQLiteDataReader reader = cmd.ExecuteReader();
|
||||||
if (reader.Read())
|
if (reader.Read())
|
||||||
{
|
{
|
||||||
|
@ -14,11 +14,11 @@ namespace YY.EventLogAssistant
|
|||||||
|
|
||||||
private const long _defaultBeginLineForLGF = 3;
|
private const long _defaultBeginLineForLGF = 3;
|
||||||
private int _indexCurrentFile;
|
private int _indexCurrentFile;
|
||||||
private string[] _logFilesWithData;
|
private readonly string[] _logFilesWithData;
|
||||||
private long _eventCount = -1;
|
private long _eventCount = -1;
|
||||||
|
|
||||||
StreamReader _stream;
|
StreamReader _stream;
|
||||||
StringBuilder _eventSource;
|
readonly StringBuilder _eventSource;
|
||||||
|
|
||||||
private LogParserLGF _logParser;
|
private LogParserLGF _logParser;
|
||||||
private LogParserLGF LogParser
|
private LogParserLGF LogParser
|
||||||
|
@ -16,17 +16,15 @@ namespace YY.EventLogAssistant
|
|||||||
FileAttributes attr = File.GetAttributes(pathLogFile);
|
FileAttributes attr = File.GetAttributes(pathLogFile);
|
||||||
|
|
||||||
FileInfo logFileInfo = null;
|
FileInfo logFileInfo = null;
|
||||||
string currentLogFilesPath;
|
|
||||||
string logFileWithReferences;
|
string logFileWithReferences;
|
||||||
if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
|
if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
|
||||||
{
|
{
|
||||||
currentLogFilesPath = pathLogFile;
|
string currentLogFilesPath = pathLogFile;
|
||||||
logFileWithReferences = string.Format("{0}{1}{2}", currentLogFilesPath, Path.DirectorySeparatorChar, @"1Cv8.lgf");
|
logFileWithReferences = string.Format("{0}{1}{2}", currentLogFilesPath, Path.DirectorySeparatorChar, @"1Cv8.lgf");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logFileInfo = new FileInfo(pathLogFile);
|
logFileInfo = new FileInfo(pathLogFile);
|
||||||
currentLogFilesPath = logFileInfo.Directory.FullName;
|
|
||||||
logFileWithReferences = logFileInfo.FullName;
|
logFileWithReferences = logFileInfo.FullName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,6 +208,44 @@ namespace YY.EventLogAssistant
|
|||||||
|
|
||||||
return severity;
|
return severity;
|
||||||
}
|
}
|
||||||
|
public Severity GetSeverityByCode(long code)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return (Severity)code;
|
||||||
|
} catch
|
||||||
|
{
|
||||||
|
return Severity.Unknown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public TransactionStatus GetTransactionStatus(string code)
|
||||||
|
{
|
||||||
|
TransactionStatus transactionStatus;
|
||||||
|
|
||||||
|
if (code == "R")
|
||||||
|
transactionStatus = TransactionStatus.Unfinished;
|
||||||
|
else if (code == "N")
|
||||||
|
transactionStatus = TransactionStatus.NotApplicable;
|
||||||
|
else if (code == "U")
|
||||||
|
transactionStatus = TransactionStatus.Committed;
|
||||||
|
else if (code == "C")
|
||||||
|
transactionStatus = TransactionStatus.RolledBack;
|
||||||
|
else
|
||||||
|
transactionStatus = TransactionStatus.Unknown;
|
||||||
|
|
||||||
|
return transactionStatus;
|
||||||
|
}
|
||||||
|
public TransactionStatus GetTransactionStatus(long code)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return (TransactionStatus)code;
|
||||||
|
} catch
|
||||||
|
{
|
||||||
|
return TransactionStatus.Unknown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Metadata GetMetadataByCode(string code)
|
public Metadata GetMetadataByCode(string code)
|
||||||
{
|
{
|
||||||
|
@ -32,11 +32,11 @@ namespace YY.EventLogAssistant
|
|||||||
}
|
}
|
||||||
else if (Simb == "}" & !textBlockOpen)
|
else if (Simb == "}" & !textBlockOpen)
|
||||||
{
|
{
|
||||||
count = count - 1;
|
count -= 1;
|
||||||
}
|
}
|
||||||
else if (Simb == "{" & !textBlockOpen)
|
else if (Simb == "{" & !textBlockOpen)
|
||||||
{
|
{
|
||||||
count = count + 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,8 +47,8 @@ namespace YY.EventLogAssistant
|
|||||||
|
|
||||||
#region Private Member Variables
|
#region Private Member Variables
|
||||||
|
|
||||||
private EventLogLGFReader _reader;
|
private readonly EventLogLGFReader _reader;
|
||||||
private Regex _regexDataUUID;
|
private readonly Regex _regexDataUUID;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -176,29 +176,31 @@ namespace YY.EventLogAssistant
|
|||||||
string[] parseResult = ParseEventLogString(eventSource);
|
string[] parseResult = ParseEventLogString(eventSource);
|
||||||
string transactionSourceString = parseResult[2].RemoveBraces();
|
string transactionSourceString = parseResult[2].RemoveBraces();
|
||||||
|
|
||||||
RowData eventData = new RowData();
|
RowData dataRow =new RowData()
|
||||||
eventData.RowID = _reader.CurrentFileEventNumber;
|
{
|
||||||
eventData.Period = DateTime.ParseExact(parseResult[0], "yyyyMMddHHmmss", CultureInfo.InvariantCulture);
|
RowID = _reader.CurrentFileEventNumber,
|
||||||
eventData.TransactionStatus = GetTransactionStatus(parseResult[1]);
|
Period = DateTime.ParseExact(parseResult[0], "yyyyMMddHHmmss", CultureInfo.InvariantCulture),
|
||||||
eventData.TransactionDate = GetTransactionDate(transactionSourceString);
|
TransactionStatus = _reader.GetTransactionStatus(parseResult[1]),
|
||||||
eventData.TransactionId = GetTransactionId(transactionSourceString);
|
TransactionDate = GetTransactionDate(transactionSourceString),
|
||||||
eventData.User = _reader.GetUserByCode(parseResult[3]);
|
TransactionId = GetTransactionId(transactionSourceString),
|
||||||
eventData.Computer = _reader.GetComputerByCode(parseResult[4]);
|
User = _reader.GetUserByCode(parseResult[3]),
|
||||||
eventData.Application = _reader.GetApplicationByCode(parseResult[5]);
|
Computer = _reader.GetComputerByCode(parseResult[4]),
|
||||||
eventData.ConnectId = parseResult[6].ToInt32();
|
Application = _reader.GetApplicationByCode(parseResult[5]),
|
||||||
eventData.Event = _reader.GetEventByCode(parseResult[7]);
|
ConnectId = parseResult[6].ToInt32(),
|
||||||
eventData.Severity = _reader.GetSeverityByCode(parseResult[8]);
|
Event = _reader.GetEventByCode(parseResult[7]),
|
||||||
eventData.Comment = parseResult[9].RemoveQuotes();
|
Severity = _reader.GetSeverityByCode(parseResult[8]),
|
||||||
eventData.Metadata = _reader.GetMetadataByCode(parseResult[10]);
|
Comment = parseResult[9].RemoveQuotes(),
|
||||||
eventData.Data = GetData(parseResult[11]);
|
Metadata = _reader.GetMetadataByCode(parseResult[10]),
|
||||||
eventData.DataUUID = GetDataUUID(eventData.Data);
|
Data = GetData(parseResult[11]),
|
||||||
eventData.DataPresentation = parseResult[12].RemoveQuotes();
|
DataPresentation = parseResult[12].RemoveQuotes(),
|
||||||
eventData.WorkServer = _reader.GetWorkServerByCode(parseResult[13]);
|
WorkServer = _reader.GetWorkServerByCode(parseResult[13]),
|
||||||
eventData.PrimaryPort = _reader.GetPrimaryPortByCode(parseResult[14]);
|
PrimaryPort = _reader.GetPrimaryPortByCode(parseResult[14]),
|
||||||
eventData.SecondaryPort = _reader.GetSecondaryPortByCode(parseResult[15]);
|
SecondaryPort = _reader.GetSecondaryPortByCode(parseResult[15]),
|
||||||
eventData.Session = parseResult[16].ToInt64();
|
Session = parseResult[16].ToInt64()
|
||||||
|
};
|
||||||
|
dataRow.DataUUID = GetDataUUID(dataRow.Data);
|
||||||
|
|
||||||
return eventData;
|
return dataRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -246,24 +248,6 @@ namespace YY.EventLogAssistant
|
|||||||
return dataUUID;
|
return dataUUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TransactionStatus GetTransactionStatus(string sourceString)
|
|
||||||
{
|
|
||||||
TransactionStatus transactionStatus;
|
|
||||||
|
|
||||||
if (sourceString == "R")
|
|
||||||
transactionStatus = TransactionStatus.Unfinished;
|
|
||||||
else if (sourceString == "N")
|
|
||||||
transactionStatus = TransactionStatus.NotApplicable;
|
|
||||||
else if (sourceString == "U")
|
|
||||||
transactionStatus = TransactionStatus.Committed;
|
|
||||||
else if (sourceString == "C")
|
|
||||||
transactionStatus = TransactionStatus.RolledBack;
|
|
||||||
else
|
|
||||||
transactionStatus = TransactionStatus.Unknown;
|
|
||||||
|
|
||||||
return transactionStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
private DateTime? GetTransactionDate(string sourceString)
|
private DateTime? GetTransactionDate(string sourceString)
|
||||||
{
|
{
|
||||||
DateTime? transactionDate;
|
DateTime? transactionDate;
|
||||||
@ -313,7 +297,7 @@ namespace YY.EventLogAssistant
|
|||||||
|
|
||||||
while (delimIndex > 0)
|
while (delimIndex > 0)
|
||||||
{
|
{
|
||||||
bufferString = bufferString + preparedString.Substring(0, delimIndex).Trim();
|
bufferString += preparedString.Substring(0, delimIndex).Trim();
|
||||||
partNumber += 1;
|
partNumber += 1;
|
||||||
preparedString = preparedString.Substring(delimIndex + 1);
|
preparedString = preparedString.Substring(delimIndex + 1);
|
||||||
if (partNumber == 1 && !String.IsNullOrEmpty(bufferString) && bufferString[0] == '\"')
|
if (partNumber == 1 && !String.IsNullOrEmpty(bufferString) && bufferString[0] == '\"')
|
||||||
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
[assembly: InternalsVisibleTo("YY.EventLogAssistant.Tests")]
|
[assembly: InternalsVisibleTo("YY.EventLogAssistant.Tests")]
|
||||||
namespace YY.EventLogAssistant.Services
|
namespace YY.EventLogAssistant.Services
|
||||||
@ -13,11 +12,11 @@ namespace YY.EventLogAssistant.Services
|
|||||||
#region Private Member Variables
|
#region Private Member Variables
|
||||||
|
|
||||||
private const int _bufferLength = 1024;
|
private const int _bufferLength = 1024;
|
||||||
private byte[] _utf8Preamble = Encoding.UTF8.GetPreamble();
|
private readonly byte[] _utf8Preamble = Encoding.UTF8.GetPreamble();
|
||||||
private Stream _base;
|
private Stream _base;
|
||||||
private Encoding _encoding;
|
private readonly Encoding _encoding;
|
||||||
private int _read = 0, _index = 0;
|
private int _read = 0, _index = 0;
|
||||||
private byte[] _readBuffer = new byte[_bufferLength];
|
private readonly byte[] _readBuffer = new byte[_bufferLength];
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -150,7 +149,7 @@ namespace YY.EventLogAssistant.Services
|
|||||||
Array.Copy(bufferString, 0, readyConvertData, 0, bufferSizeCopy);
|
Array.Copy(bufferString, 0, readyConvertData, 0, bufferSizeCopy);
|
||||||
|
|
||||||
string prepearedString;
|
string prepearedString;
|
||||||
if (_encoding == Encoding.UTF8 && byteArrayStartsWith(readyConvertData, 0, _utf8Preamble))
|
if (_encoding == Encoding.UTF8 && ByteArrayStartsWith(readyConvertData, 0, _utf8Preamble))
|
||||||
{
|
{
|
||||||
prepearedString = _encoding.GetString(readyConvertData, _utf8Preamble.Length, readyConvertData.Length - _utf8Preamble.Length);
|
prepearedString = _encoding.GetString(readyConvertData, _utf8Preamble.Length, readyConvertData.Length - _utf8Preamble.Length);
|
||||||
}
|
}
|
||||||
@ -160,7 +159,7 @@ namespace YY.EventLogAssistant.Services
|
|||||||
return prepearedString;
|
return prepearedString;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool byteArrayStartsWith(byte[] source, int offset, byte[] match)
|
private bool ByteArrayStartsWith(byte[] source, int offset, byte[] match)
|
||||||
{
|
{
|
||||||
if (match.Length > (source.Length - offset))
|
if (match.Length > (source.Length - offset))
|
||||||
{
|
{
|
||||||
|
@ -9,39 +9,6 @@ namespace YY.EventLogAssistant.Services
|
|||||||
{
|
{
|
||||||
internal static class StringExtensions
|
internal static class StringExtensions
|
||||||
{
|
{
|
||||||
#region Private Member Variables
|
|
||||||
|
|
||||||
private static readonly Dictionary<int, char> CharactersToMap = new Dictionary<int, char>
|
|
||||||
{
|
|
||||||
{130, '‚'},
|
|
||||||
{131, 'ƒ'},
|
|
||||||
{132, '„'},
|
|
||||||
{133, '…'},
|
|
||||||
{134, '†'},
|
|
||||||
{135, '‡'},
|
|
||||||
{136, 'ˆ'},
|
|
||||||
{137, '‰'},
|
|
||||||
{138, 'Š'},
|
|
||||||
{139, '‹'},
|
|
||||||
{140, 'Œ'},
|
|
||||||
{145, '‘'},
|
|
||||||
{146, '’'},
|
|
||||||
{147, '“'},
|
|
||||||
{148, '”'},
|
|
||||||
{149, '•'},
|
|
||||||
{150, '–'},
|
|
||||||
{151, '—'},
|
|
||||||
{152, '˜'},
|
|
||||||
{153, '™'},
|
|
||||||
{154, 'š'},
|
|
||||||
{155, '›'},
|
|
||||||
{156, 'œ'},
|
|
||||||
{159, 'Ÿ'},
|
|
||||||
{173, '-'}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Public Methods
|
#region Public Methods
|
||||||
|
|
||||||
public static long From16To10(this string sourceValue)
|
public static long From16To10(this string sourceValue)
|
||||||
@ -92,8 +59,7 @@ namespace YY.EventLogAssistant.Services
|
|||||||
|
|
||||||
public static Guid ToGuid(this string sourceValue)
|
public static Guid ToGuid(this string sourceValue)
|
||||||
{
|
{
|
||||||
Guid guidFromString = Guid.Empty;
|
Guid.TryParse(sourceValue, out Guid guidFromString);
|
||||||
Guid.TryParse(sourceValue, out guidFromString);
|
|
||||||
return guidFromString;
|
return guidFromString;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,28 +75,6 @@ namespace YY.EventLogAssistant.Services
|
|||||||
return source.GetString(resultBytes);
|
return source.GetString(resultBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HashSet<char> CharListToSet(string charList)
|
|
||||||
{
|
|
||||||
HashSet<char> set = new HashSet<char>();
|
|
||||||
|
|
||||||
for (int i = 0; i < charList.Length; i++)
|
|
||||||
{
|
|
||||||
if ((i + 1) < charList.Length && charList[i + 1] == '-')
|
|
||||||
{
|
|
||||||
// Character range
|
|
||||||
char startChar = charList[i++];
|
|
||||||
i++; // Hyphen
|
|
||||||
char endChar = (char)0;
|
|
||||||
if (i < charList.Length)
|
|
||||||
endChar = charList[i++];
|
|
||||||
for (int j = startChar; j <= endChar; j++)
|
|
||||||
set.Add((char)j);
|
|
||||||
}
|
|
||||||
else set.Add(charList[i]);
|
|
||||||
}
|
|
||||||
return set;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"profiles": {
|
"profiles": {
|
||||||
"YY.EventLogAssistantConsoleApp": {
|
"YY.EventLogAssistantConsoleApp": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"commandLineArgs": "\"E:\\Dev\\YY\\YY.EventLogAssistant\\YY.EventLogAssistant\\YY.EventLogAssistantConsoleApp\\bin\\Debug\\netcoreapp3.1\\TestData\\1Cv8.lgd\" \"\\\\Srv-1c-01-vm\\жр lgf (генератор событий)\""
|
"commandLineArgs": "\"\\\\Srv-1c-01-vm\\жр lgf (генератор событий)\" \"E:\\Dev\\YY\\YY.EventLogAssistant\\YY.EventLogAssistant\\YY.EventLogAssistantConsoleApp\\bin\\Debug\\netcoreapp3.1\\TestData\\1Cv8.lgd\""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user