1
0
mirror of https://github.com/romanlryji/EventLogLoader.git synced 2024-11-24 08:32:52 +02:00

Deleted unnesessary parse function. Minor bug fixes

This commit is contained in:
Alex Bochkov 2017-01-10 22:46:12 -08:00
parent c6a9ed642a
commit a4fdd3b089
4 changed files with 125 additions and 197 deletions

View File

@ -182,18 +182,22 @@ Public Class ServiceDescriptionClass
Dim Text = My.Computer.FileSystem.ReadAllText(TMP)
My.Computer.FileSystem.DeleteFile(TMP)
Dim Array = ParserServices.ParseString(Text)
Dim i = 0
For Each a In Array
If Not a Is Nothing Then
If a.Length = 11 And a(0).StartsWith("1.2.") Then
Dim ClusterSetting = ParserServices.ParseEventLogString(Text)
Dim DatabaseSettings = ParserServices.ParseEventLogString(ClusterSetting(2)) 'third element contains all database descriptions
For Each Row2 As String In DatabaseSettings
If Row2.StartsWith("{") Then
'this is an infobase description
Dim DatabaseDescription = ParserServices.ParseEventLogString(Row2)
Dim IB = New Infobases
IB.Name = a(2).ToString
IB.GUID = a(1).ToString
IB.Description = a(3).ToString
IB.Name = DatabaseDescription(1).ToString
IB.GUID = DatabaseDescription(0).ToString
IB.Description = DatabaseDescription(2).ToString
IB.SizeEventLog = 0
Try
@ -225,12 +229,12 @@ Public Class ServiceDescriptionClass
i = i + 1
End If
End If
End If
Next
System.Array.Sort(ArrayInfobases)
Catch ex As Exception

View File

@ -56,6 +56,11 @@ Public Class EventLogProcessor
Usr.Name = Name
Usr.Guid = Guid
'reference file in old evenlog format may contain duplicated values when object description has been changed (for example, user renamed)
If DictUsers.ContainsKey(Code) Then
DictUsers.Remove(Code)
End If
DictUsers.Add(Code, Usr)
End Sub
@ -97,6 +102,11 @@ Public Class EventLogProcessor
MD.Name = Name
MD.Guid = Guid
'reference file in old evenlog format may contain duplicated values when object description has been changed (for example, user renamed)
If DictMetadata.ContainsKey(Code) Then
DictMetadata.Remove(Code)
End If
DictMetadata.Add(Code, MD)
End Sub
@ -921,6 +931,8 @@ Public Class EventLogProcessor
DictMainPorts.Clear()
DictSecondPorts.Clear()
Dim LastProcessedObjectForDebug As String = ""
Try
Dim FileName = Path.Combine(Catalog, "1Cv8.lgf")
@ -940,29 +952,34 @@ Public Class EventLogProcessor
SR.Close()
FS.Close()
Text = Text.Substring(Text.IndexOf("{"))
Dim ArrayLines = ParserServices.ParseString(Text)
Dim ObjectTexts = ParserServices.ParseEventlogString("{" + Text + "}")
For Each TextObject In ObjectTexts
LastProcessedObjectForDebug = TextObject
Dim a = ParserServices.ParseEventlogString(TextObject)
Dim i = 0
For Each a In ArrayLines
If Not a Is Nothing Then
Select Case a(1)
Select Case a(0)
Case "1"
AddUser(Convert.ToInt32(a(4)), a(2), a(3))
AddUser(Convert.ToInt32(a(3)), a(1), a(2))
Case "2"
AddComputer(Convert.ToInt32(a(3)), a(2))
AddComputer(Convert.ToInt32(a(2)), a(1))
Case "3"
AddApplication(Convert.ToInt32(a(3)), a(2))
AddApplication(Convert.ToInt32(a(2)), a(1))
Case "4"
AddEvent(Convert.ToInt32(a(3)), a(2))
AddEvent(Convert.ToInt32(a(2)), a(1))
Case "5"
AddMetadata(Convert.ToInt32(a(4)), a(2), a(3))
AddMetadata(Convert.ToInt32(a(3)), a(1), a(2))
Case "6"
AddServer(Convert.ToInt32(a(3)), a(2))
AddServer(Convert.ToInt32(a(2)), a(1))
Case "7"
AddMainPort(Convert.ToInt32(a(3)), a(2))
AddMainPort(Convert.ToInt32(a(2)), a(1))
Case "8"
AddSecondPort(Convert.ToInt32(a(3)), a(2))
AddSecondPort(Convert.ToInt32(a(2)), a(1))
'Case "9" - не видел этих в файле
'Case "10"
Case "11"
@ -974,15 +991,61 @@ Public Class EventLogProcessor
End Select
End If
Next
'Dim ArrayLines = ParserServices.ParseString(Text)
'Dim i = 0
'For Each a In ArrayLines
' If Not a Is Nothing Then
' Select Case a(1)
' Case "1"
' AddUser(Convert.ToInt32(a(4)), a(2), a(3))
' Case "2"
' AddComputer(Convert.ToInt32(a(3)), a(2))
' Case "3"
' AddApplication(Convert.ToInt32(a(3)), a(2))
' Case "4"
' AddEvent(Convert.ToInt32(a(3)), a(2))
' Case "5"
' AddMetadata(Convert.ToInt32(a(4)), a(2), a(3))
' Case "6"
' AddServer(Convert.ToInt32(a(3)), a(2))
' Case "7"
' AddMainPort(Convert.ToInt32(a(3)), a(2))
' Case "8"
' AddSecondPort(Convert.ToInt32(a(3)), a(2))
' 'Case "9" - не видел этих в файле
' 'Case "10"
' Case "11"
' Case "12"
' Case "13"
' 'в числе последних трех должны быть статус транзакции и важность
' Case Else
' End Select
' End If
'Next
SaveReferenceValuesToDatabase()
End If
End If
Catch ex As Exception
Log.Error(ex, "Error occurred while working with reference file")
Dim AdditionalString = ""
If Not String.IsNullOrEmpty(LastProcessedObjectForDebug) Then
AdditionalString = "Attempted to process this object: " + LastProcessedObjectForDebug
End If
Log.Error(ex, "Error occurred while working with reference file. " + AdditionalString)
End Try

View File

@ -1,150 +1,6 @@
Public Module ParserServices
Function ParseString(Text As String)
Dim Array(0)
If Not Text = "" Then
Dim RowArr(2)
Dim j = 0
Dim OpenBlock = False
Dim Level = 0
For i = 0 To Text.Length - 1
Dim Simb = Text.Substring(i, 1)
Dim SubStr = ""
If OpenBlock Then
If Simb = """" Then
OpenBlock = False
End If
Else
If Simb = "{" Then
Level = Level + 1
SubStr = "НачалоУровня"
ElseIf Simb = "}" Then
Level = Level - 1
SubStr = "ОкончаниеУровня"
ElseIf Simb = """" Then
OpenBlock = True
ElseIf Simb = "," Then
SubStr = "Разделитель"
End If
End If
If Not SubStr = "" Then
ReDim Preserve Array(j)
ReDim RowArr(2)
RowArr(0) = i
RowArr(1) = SubStr
RowArr(2) = Level
Array(j) = RowArr
j = j + 1
End If
Next
End If
Dim ArrayBases(0)
Dim ArrayRow(2)
Dim ArrayLines(0)
If Array.Length > 1 Then
Dim ArrayLevel(10) As Integer
Dim ArrayValue(0)
Dim Level = 0
' Dim CountLines = 0
Dim LastVal = 0
Dim StrLevel = ""
For Each a In Array
Select Case a(1)
Case "НачалоУровня"
If Not StrLevel = "" Then
ArrayValue(0) = StrLevel
ArrayLines(ArrayLines.Length - 1) = ArrayValue
ReDim Preserve ArrayLines(ArrayLines.Length)
End If
' CountLines = CountLines + 1
ArrayLevel(Level) = ArrayLevel(Level) + 1
Level = Level + 1
StrLevel = ""
For j = 0 To Level - 1
StrLevel = IIf(StrLevel = "", "", StrLevel + ".") + ArrayLevel(j).ToString
Next
ReDim ArrayValue(0)
Case "ОкончаниеУровня"
Dim TextStr = Text.Substring(LastVal + 1, a(0) - LastVal - 1)
TextStr = TextStr.Replace("""""", """")
If TextStr = """" Then TextStr = ""
If TextStr.StartsWith("""") And TextStr.EndsWith("""") Then
TextStr = TextStr.Substring(1, TextStr.Length - 2)
End If
'If Not TextStr = "" Then
ReDim Preserve ArrayValue(ArrayValue.Length)
ArrayValue(ArrayValue.Length - 1) = TextStr
'End If
ArrayValue(0) = StrLevel
ArrayLines(ArrayLines.Length - 1) = ArrayValue
ReDim Preserve ArrayLines(ArrayLines.Length)
'ArrayLevel(Level) = ArrayLevel(Level) - 1
ArrayLevel(Level) = 0
Level = Level - 1
ReDim ArrayValue(0)
StrLevel = ""
For j = 0 To Level - 1
StrLevel = IIf(StrLevel = "", "", StrLevel + ".") + ArrayLevel(j).ToString
Next
Case "Разделитель"
Dim TextStr = Text.Substring(LastVal + 1, a(0) - LastVal - 1)
TextStr = TextStr.Replace("""""", """")
If TextStr = """" Then TextStr = ""
If TextStr.StartsWith("""") And TextStr.EndsWith("""") Then
TextStr = TextStr.Substring(1, TextStr.Length - 2)
End If
'If Not TextStr = "" Then
ReDim Preserve ArrayValue(ArrayValue.Length)
ArrayValue(ArrayValue.Length - 1) = TextStr
'End If
End Select
LastVal = a(0)
Next
End If
Return ArrayLines
End Function
Function ParseEventlogString(Text As String)
Function ParseEventLogString(Text As String)
Dim ArrayLines(0)
@ -156,14 +12,19 @@
Dim i = 0
While Delim > 0
Str = Str + Text2.Substring(0, Delim)
Str = Str + Text2.Substring(0, Delim).Trim
Text2 = Text2.Substring(Delim + 1)
If CountSubstringInString(Str, "{") = CountSubstringInString(Str, "}") _
And Math.IEEERemainder(CountSubstringInString(Str, """"), 2) = 0 Then
ReDim Preserve ArrayLines(i)
ArrayLines(i) = Str.Trim
If Str.StartsWith("""") And Str.EndsWith("""") Then
Str = Str.Substring(1, Str.Length - 2)
End If
ArrayLines(i) = Str
i = i + 1
Str = ""
Else

View File

@ -211,42 +211,42 @@ Public Class EventLogLoaderService
'**********************************************************************************
command.CommandText =
"IF NOT EXISTS (select * from sysobjects where id = object_id(N'Users'))" + vbNewLine +
"CREATE TABLE [dbo].[Users]([InfobaseCode] int NOT NULL, [Code] int NOT NULL, [Name] [char](100), [Guid] [char](40));" + vbNewLine +
"CREATE TABLE [dbo].[Users]([InfobaseCode] int NOT NULL, [Code] int NOT NULL, [Name] [nvarchar](100), [Guid] [varchar](40));" + vbNewLine +
"IF NOT EXISTS (select * from sys.indexes where object_id = object_id(N'Users') AND Name = 'ClusteredIndex')" + vbNewLine +
"CREATE UNIQUE CLUSTERED INDEX [ClusteredIndex] ON [dbo].[Users] ([InfobaseCode] ASC, [Code] ASC);" + vbNewLine +
"" +
"IF NOT EXISTS (select * from sysobjects where id = object_id(N'Metadata'))" + vbNewLine +
"CREATE TABLE [dbo].[Metadata]([InfobaseCode] int NOT NULL, [Code] int NOT NULL, [Name] [char](100), [Guid] [char](40));" + vbNewLine +
"CREATE TABLE [dbo].[Metadata]([InfobaseCode] int NOT NULL, [Code] int NOT NULL, [Name] [nvarchar](100), [Guid] [varchar](40));" + vbNewLine +
"IF NOT EXISTS (select * from sys.indexes where object_id = object_id(N'Metadata') AND Name = 'ClusteredIndex')" + vbNewLine +
"CREATE UNIQUE CLUSTERED INDEX [ClusteredIndex] ON [dbo].[Metadata] ([InfobaseCode] ASC, [Code] ASC);" + vbNewLine +
"" +
"IF NOT EXISTS (select * from sysobjects where id = object_id(N'Computers'))" + vbNewLine +
"CREATE TABLE [dbo].[Computers]([InfobaseCode] int NOT NULL, [Code] int NOT NULL, [Name] [char](100));" + vbNewLine +
"CREATE TABLE [dbo].[Computers]([InfobaseCode] int NOT NULL, [Code] int NOT NULL, [Name] [nvarchar](100));" + vbNewLine +
"IF NOT EXISTS (select * from sys.indexes where object_id = object_id(N'Computers') AND Name = 'ClusteredIndex')" + vbNewLine +
"CREATE UNIQUE CLUSTERED INDEX [ClusteredIndex] ON [dbo].[Computers] ([InfobaseCode] ASC, [Code] ASC);" + vbNewLine +
"" +
"IF NOT EXISTS (select * from sysobjects where id = object_id(N'Applications'))" + vbNewLine +
"CREATE TABLE [dbo].[Applications]([InfobaseCode] int NOT NULL, [Code] int NOT NULL,[Name] [char](100));" + vbNewLine +
"CREATE TABLE [dbo].[Applications]([InfobaseCode] int NOT NULL, [Code] int NOT NULL,[Name] [nvarchar](100));" + vbNewLine +
"IF NOT EXISTS (select * from sys.indexes where object_id = object_id(N'Applications') AND Name = 'ClusteredIndex')" + vbNewLine +
"CREATE UNIQUE CLUSTERED INDEX [ClusteredIndex] ON [dbo].[Applications] ([InfobaseCode] ASC, [Code] ASC);" + vbNewLine +
"" +
"IF NOT EXISTS (select * from sysobjects where id = object_id(N'EventsType'))" + vbNewLine +
"CREATE TABLE [dbo].[EventsType]([InfobaseCode] int NOT NULL, [Code] int NOT NULL, [Name] [char](100));" + vbNewLine +
"CREATE TABLE [dbo].[EventsType]([InfobaseCode] int NOT NULL, [Code] int NOT NULL, [Name] [nvarchar](max));" + vbNewLine +
"IF NOT EXISTS (select * from sys.indexes where object_id = object_id(N'EventsType') AND Name = 'ClusteredIndex')" + vbNewLine +
"CREATE UNIQUE CLUSTERED INDEX [ClusteredIndex] ON [dbo].[EventsType] ([InfobaseCode] ASC, [Code] ASC);" + vbNewLine +
"" +
"IF NOT EXISTS (select * from sysobjects where id = object_id(N'Servers'))" + vbNewLine +
"CREATE TABLE [dbo].[Servers]([InfobaseCode] int NOT NULL, [Code] int NOT NULL, [Name] [char](100));" + vbNewLine +
"CREATE TABLE [dbo].[Servers]([InfobaseCode] int NOT NULL, [Code] int NOT NULL, [Name] [nvarchar](100));" + vbNewLine +
"IF NOT EXISTS (select * from sys.indexes where object_id = object_id(N'Servers') AND Name = 'ClusteredIndex')" + vbNewLine +
"CREATE UNIQUE CLUSTERED INDEX [ClusteredIndex] ON [dbo].[Servers] ([InfobaseCode] ASC, [Code] ASC);" + vbNewLine +
"" +
"IF NOT EXISTS (select * from sysobjects where id = object_id(N'MainPorts'))" + vbNewLine +
"CREATE TABLE [dbo].[MainPorts]([InfobaseCode] int NOT NULL, [Code] int NOT NULL, [Name] [char](100));" + vbNewLine +
"CREATE TABLE [dbo].[MainPorts]([InfobaseCode] int NOT NULL, [Code] int NOT NULL, [Name] [nvarchar](100));" + vbNewLine +
"IF NOT EXISTS (select * from sys.indexes where object_id = object_id(N'MainPorts') AND Name = 'ClusteredIndex')" + vbNewLine +
"CREATE UNIQUE CLUSTERED INDEX [ClusteredIndex] ON [dbo].[MainPorts] ([InfobaseCode] ASC, [Code] ASC);" + vbNewLine +
"" +
"IF NOT EXISTS (select * from sysobjects where id = object_id(N'SecondPorts'))" + vbNewLine +
"CREATE TABLE [dbo].[SecondPorts]([InfobaseCode] int NOT NULL, [Code] int NOT NULL, [Name] [char](100));" + vbNewLine +
"CREATE TABLE [dbo].[SecondPorts]([InfobaseCode] int NOT NULL, [Code] int NOT NULL, [Name] [nvarchar](100));" + vbNewLine +
"IF NOT EXISTS (select * from sys.indexes where object_id = object_id(N'SecondPorts') AND Name = 'ClusteredIndex')" + vbNewLine +
"CREATE UNIQUE CLUSTERED INDEX [ClusteredIndex] ON [dbo].[SecondPorts] ([InfobaseCode] ASC, [Code] ASC);"
@ -297,7 +297,7 @@ Public Class EventLogLoaderService
"" +
"CREATE TABLE IF NOT EXISTS `Applications`(`InfobaseCode` int(11) NOT NULL, `Code` int(11) NOT NULL, `Name` varchar(100), PRIMARY KEY (`InfobaseCode`, `Code`));" + vbNewLine +
"" +
"CREATE TABLE IF NOT EXISTS `EventsType`(`InfobaseCode` int(11) NOT NULL, `Code` int(11) NOT NULL, `Name` varchar(100), PRIMARY KEY (`InfobaseCode`, `Code`));" + vbNewLine +
"CREATE TABLE IF NOT EXISTS `EventsType`(`InfobaseCode` int(11) NOT NULL, `Code` int(11) NOT NULL, `Name` text, PRIMARY KEY (`InfobaseCode`, `Code`));" + vbNewLine +
"" +
"CREATE TABLE IF NOT EXISTS `Servers`(`InfobaseCode` int(11) NOT NULL, `Code` int(11) NOT NULL, `Name` varchar(100), PRIMARY KEY (`InfobaseCode`, `Code`));" + vbNewLine +
"" +