From d751eee8e621a124028061e01dd283b10e97bdde Mon Sep 17 00:00:00 2001 From: Isaac Mallampati Date: Tue, 14 Apr 2020 18:52:03 -0400 Subject: [PATCH] Reorganized directory structure --- BulkInsert_StoredProcedure.sql | 105 +++++ README.md | 104 +++++ cli/.DS_Store | Bin 0 -> 6148 bytes cli/EventParser_CLI.sln | 25 ++ cli/EventParser_ConsoleApp/App.config | 6 + cli/EventParser_ConsoleApp/DataRecord.cs | 14 + .../EventParser_CLI.csproj | 106 +++++ cli/EventParser_ConsoleApp/Program.cs | 197 +++++++++ .../Properties/AssemblyInfo.cs | 35 ++ cli/EventParser_ConsoleApp/packages.config | 6 + gui/.DS_Store | Bin 0 -> 6148 bytes gui/EventParser.sln | 25 ++ gui/EventParser/App.config | 9 + gui/EventParser/DataRecord.cs | 14 + gui/EventParser/EventParser.csproj | 156 +++++++ gui/EventParser/GlobalParameters.cs | 16 + gui/EventParser/Program.cs | 19 + gui/EventParser/Properties/AssemblyInfo.cs | 35 ++ .../Properties/Resources.Designer.cs | 71 ++++ gui/EventParser/Properties/Resources.resx | 117 ++++++ .../Properties/Settings.Designer.cs | 30 ++ gui/EventParser/Properties/Settings.settings | 7 + gui/EventParser/frmAbout.Designer.cs | 201 +++++++++ gui/EventParser/frmAbout.cs | 17 + gui/EventParser/frmAbout.resx | 120 ++++++ gui/EventParser/frmConnection.cs | 165 ++++++++ gui/EventParser/frmConnection.designer.cs | 294 +++++++++++++ gui/EventParser/frmConnection.resx | 120 ++++++ gui/EventParser/frmMain.Designer.cs | 389 ++++++++++++++++++ gui/EventParser/frmMain.cs | 272 ++++++++++++ gui/EventParser/frmMain.resx | 132 ++++++ gui/EventParser/packages.config | 6 + 32 files changed, 2813 insertions(+) create mode 100755 BulkInsert_StoredProcedure.sql create mode 100644 README.md create mode 100644 cli/.DS_Store create mode 100755 cli/EventParser_CLI.sln create mode 100755 cli/EventParser_ConsoleApp/App.config create mode 100755 cli/EventParser_ConsoleApp/DataRecord.cs create mode 100755 cli/EventParser_ConsoleApp/EventParser_CLI.csproj create mode 100755 cli/EventParser_ConsoleApp/Program.cs create mode 100755 cli/EventParser_ConsoleApp/Properties/AssemblyInfo.cs create mode 100755 cli/EventParser_ConsoleApp/packages.config create mode 100644 gui/.DS_Store create mode 100644 gui/EventParser.sln create mode 100644 gui/EventParser/App.config create mode 100644 gui/EventParser/DataRecord.cs create mode 100644 gui/EventParser/EventParser.csproj create mode 100644 gui/EventParser/GlobalParameters.cs create mode 100644 gui/EventParser/Program.cs create mode 100644 gui/EventParser/Properties/AssemblyInfo.cs create mode 100644 gui/EventParser/Properties/Resources.Designer.cs create mode 100644 gui/EventParser/Properties/Resources.resx create mode 100644 gui/EventParser/Properties/Settings.Designer.cs create mode 100644 gui/EventParser/Properties/Settings.settings create mode 100644 gui/EventParser/frmAbout.Designer.cs create mode 100644 gui/EventParser/frmAbout.cs create mode 100644 gui/EventParser/frmAbout.resx create mode 100644 gui/EventParser/frmConnection.cs create mode 100644 gui/EventParser/frmConnection.designer.cs create mode 100644 gui/EventParser/frmConnection.resx create mode 100644 gui/EventParser/frmMain.Designer.cs create mode 100644 gui/EventParser/frmMain.cs create mode 100644 gui/EventParser/frmMain.resx create mode 100644 gui/EventParser/packages.config diff --git a/BulkInsert_StoredProcedure.sql b/BulkInsert_StoredProcedure.sql new file mode 100755 index 0000000..9a37a68 --- /dev/null +++ b/BulkInsert_StoredProcedure.sql @@ -0,0 +1,105 @@ +/****** Object: StoredProcedure [dbo].[ImportLogs] Script Date: 19/07/2019 06:14:23 ******/ +SET ANSI_NULLS ON +GO + +SET QUOTED_IDENTIFIER ON +GO + + +CREATE PROCEDURE [dbo].[ImportLogs] @filepath NVARCHAR(500), + @bulkinsert NVARCHAR(2000) +AS + IF Object_id('event_logs') IS NOT NULL + BEGIN + -- The bulk insert command must be built as a string because the filepath of the CSV file cannot be passed as a paramter. + -- https://stackoverflow.com/questions/15671971/syntax-error-when-defining-a-parameter-for-bulk-insert + SET @bulkinsert = N'BULK INSERT event_logs FROM ''' + + @filepath + + + N''' WITH (FIELDTERMINATOR = '','', ROWTERMINATOR = ''\n'')' + EXEC sp_executesql @bulkinsert + END + ELSE + BEGIN + /****** Object: Table [dbo].[event_logs] Script Date: 19/07/2019 05:57:04 ******/ + SET ansi_nulls ON + SET quoted_identifier ON + + CREATE TABLE [dbo].[event_logs] + ( + [guid] [VARCHAR](100) NOT NULL, + [level] [VARCHAR](100) NULL, + [date_and_time] [VARCHAR](100) NULL, + [source] [VARCHAR](100) NULL, + [event_id] [SMALLINT] NULL, + [task_category] [VARCHAR](100) NULL, + [extracted_account_name] [VARCHAR](100) NOT NULL, + CONSTRAINT [PK_event_logs] PRIMARY KEY CLUSTERED ( [guid] ASC ) + WITH ( + pad_index = OFF, statistics_norecompute = OFF, ignore_dup_key = + OFF, + allow_row_locks = on, allow_page_locks = on) ON [PRIMARY] + ) + ON [PRIMARY] + + SET ansi_padding ON + + /****** Object: Index [IX_date_and_time] Script Date: 19/07/2019 05:57:04 ******/ + CREATE NONCLUSTERED INDEX [IX_date_and_time] + ON [dbo].[event_logs] ( [date_and_time] ASC ) + WITH (pad_index = OFF, statistics_norecompute = OFF, sort_in_tempdb + = + OFF, + drop_existing = OFF, online = OFF, allow_row_locks = ON, + allow_page_locks + = + ON) ON [PRIMARY] + + /****** Object: Index [IX_event_id] Script Date: 19/07/2019 05:57:04 ******/ + CREATE NONCLUSTERED INDEX [IX_event_id] + ON [dbo].[event_logs] ( [event_id] ASC ) + WITH (pad_index = OFF, statistics_norecompute = OFF, sort_in_tempdb + = + OFF, + drop_existing = OFF, online = OFF, allow_row_locks = ON, + allow_page_locks + = + ON) ON [PRIMARY] + + SET ansi_padding ON + + /****** Object: Index [IX_extracted_account_name] Script Date: 19/07/2019 05:57:04 ******/ + CREATE NONCLUSTERED INDEX [IX_extracted_account_name] + ON [dbo].[event_logs] ( [extracted_account_name] ASC ) + WITH (pad_index = OFF, statistics_norecompute = OFF, sort_in_tempdb + = + OFF, + drop_existing = OFF, online = OFF, allow_row_locks = ON, + allow_page_locks + = + ON) ON [PRIMARY] + + SET ansi_padding ON + + /****** Object: Index [IX_task_category] Script Date: 19/07/2019 05:57:04 ******/ + CREATE NONCLUSTERED INDEX [IX_task_category] + ON [dbo].[event_logs] ( [task_category] ASC ) + WITH (pad_index = OFF, statistics_norecompute = OFF, sort_in_tempdb + = + OFF, + drop_existing = OFF, online = OFF, allow_row_locks = ON, + allow_page_locks + = + ON) ON [PRIMARY] + + -- Import records once database has been created. + SET @bulkinsert = N'BULK INSERT event_logs FROM ''' + + @filepath + + + N''' WITH (FIELDTERMINATOR = '','', ROWTERMINATOR = ''\n'')' + EXEC sp_executesql @bulkinsert + + END +GO + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..28b5d91 --- /dev/null +++ b/README.md @@ -0,0 +1,104 @@ +# EventParser + +Event logs are generated through the Windows Event Viewer application and can be exported as Comma-Separated Values (CSV) files. +EventParser processes a CSV file, parses the file for specified value(s), creates a new file with the required information, then imports the updated file into an MS SQL database. +EventParser is available with a graphical user interface (GUI) or a command-line interface (CLI). + + + + + +## Getting Started +### Prerequisites +* An instance of Microsoft SQL Server 2012 +* Visual Studio 2017 (to build the application) + +### Installation +#### Local +1. Open the solution file. +2. Build the project. +3. Publish the project. +4. Specify the file path where the setup should be saved. +5. Select CD-ROM as the installation method. +6. Disable updates. +7. Complete the publishing process. +8. Copy the setup to the directory where EventParser will be installed. This is necessary because the setup automatically installs the programme to the directory it is located in. It is recommended that the application be installed on the root directory of the machine. +9. Run the setup. + +#### Server +Execute the `BulkInsert_StoredProcedure.sql` file. This script installs the Stored Procedure onto the MS SQL Server. +The Stored Procedure imports the CSV file into the database and creates a table on the first run. + + +## Usage +### GUI +1. Run the programme with administrator privileges. +2. Set the connection string. Select Options. Complete the necessary fields then click OK. +3. Specify the filepath of the CSV file to be opened. +4. Specify the filepath of the CSV file to be saved. An existing file may be overwritten, or a new file can be created. +5. Select the OK button. +6. Check the Output field to see the application’s progress. Ideally, this should be the application output. +``` +Begin processing *FILENAME* +Replacing log file header… +Parsing log file… +Importing log file into MSSQL server… +Done. +``` + +_To clear all the fields and restart the application, select the “Reset” button._ + +_The connection string is automatically saved each time the programme is run._ + + + + +### CLI +Run the programme with administrator privileges. The console application supports three arguments. Each argument **MUST** be wrapped in double quotes. + +``` + -i, —input… Specify filepath of CSV file to process + + -o, —output… Specify filepath to save CSV file + + -c, —connection… Specify connection string +``` + + +## Libraries +[CSVHelper](https://www.nuget.org/packages/CsvHelper/) - Allows for reading and writing CSV files; enables significantly faster processing. + +[CommandLineArgumentsParser](https://www.nuget.org/packages/CommandLineArgumentsParser/) - Allows command-line arguments to be passed to the CLI. + + + +## Programme Structure +#### AddMissingHeader +The exported CSV file has a missing column header. This method reads the CSV file and replaces the existing header row with a corrected version. A FileStream instance is opened. The file is overwritten. The existing header is found through a Regular Expressions (RegEx) expression. This is necessary as CSVHelper requires the column names to be defined (`DataRecord.cs`). + +#### ParseLog +This method uses CSVHelper. This method reads the CSV file. These columns are: `Level, Date and Time, Source, Event ID, Task Category`. A FileStream instance is opened to read/write to the file. The log file is read into an enumerable. A RegEx expression is used to match the value to be extracted. +Additional fields may be needed to be extracted from the `Details` column. There is uncommented code that gives an example on how to extract an additional field. +None of the fields present in the CSV file are unique. A primary key has been created by combining the timestamp with an increment. +There are instances of records which contain no `Account Name` in the `Details` column. If there is no `Account Name` to be extracted, the following row gets inserted into the account name field. This causes errors during importing. +#### ImportToMSSQL +This method imports the CSV file into the MS SQL database. This is facilitated by the `ImportLogs` Stored Procedure. The file path of the parsed CSV file is passed to the Stored Procedure as a parameter. +The Stored Procedure creates a table `event_logs` if it does not already exist. It imports the CSV file into the database via Bulk Inserts. The script must be built as a string because the Bulk Insert command does not accept file path as a parameter. + + + +## Automation +In order to make this an automated process, a batch file may be created which runs the CLI version of EventParser. As EventParser supports command line arguments, the file paths and connection strings may be passed to the CLI through the batch file. +The batch file can be run automatically at scheduled intervals via Task Scheduler. + + + +## Future Implementation +- Transactional writes for bulk inserts +- Automatic generation of Event Viewer Logs +- Removal of ‘bad’ events from log file (Logs with missing details and duplicates) + + + + + diff --git a/cli/.DS_Store b/cli/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c55cc05d7f1d73dadd7ca6bdd3f58a421ff77edd GIT binary patch literal 6148 zcmeHK%}(Pm5FVGpx+pVYy2QCQEj5Pkn^J6EUBRd8F(du`a05t%RsDz~oHg5>UNoS#xV;y4MbJ&ZcEN?Vk zL}{)(zwk@Ss;n+mFZ^pg@be(=XRRPTqux=FUx&^<);gZpL3k2%2kqL*zE1KWO1h~j zjyhdTIX{h(jvlmhKj~y<9Nz|{tjJ2cwmKX(H`eQFeWy99tKs%`qpmhLwnn3h{Ik~F z{d;+HcRzd>Jw93H1%9MPmK~1a9~vJb;nq)+SSMFlHy(3579%sj3@`)VfC0C4$;EH* zto(?~05kBp4AB0dPzgPUg+;SAk54-j+*p literal 0 HcmV?d00001 diff --git a/cli/EventParser_CLI.sln b/cli/EventParser_CLI.sln new file mode 100755 index 0000000..a9415ed --- /dev/null +++ b/cli/EventParser_CLI.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.705 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventParser_CLI", "EventParser_ConsoleApp\EventParser_CLI.csproj", "{0B61EE2C-2F75-4D41-BF75-A235E11309BC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0B61EE2C-2F75-4D41-BF75-A235E11309BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0B61EE2C-2F75-4D41-BF75-A235E11309BC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0B61EE2C-2F75-4D41-BF75-A235E11309BC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0B61EE2C-2F75-4D41-BF75-A235E11309BC}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {00621985-7711-4A66-B1DC-C26E64E1A405} + EndGlobalSection +EndGlobal diff --git a/cli/EventParser_ConsoleApp/App.config b/cli/EventParser_ConsoleApp/App.config new file mode 100755 index 0000000..db350c7 --- /dev/null +++ b/cli/EventParser_ConsoleApp/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/cli/EventParser_ConsoleApp/DataRecord.cs b/cli/EventParser_ConsoleApp/DataRecord.cs new file mode 100755 index 0000000..9b01cfc --- /dev/null +++ b/cli/EventParser_ConsoleApp/DataRecord.cs @@ -0,0 +1,14 @@ +using System; + +namespace EventParser.ConsoleApp +{ + internal class DataRecord + { + public String Level { get; set; } + public String DateAndTime { get; set; } + public String Source { get; set; } + public String EventID { get; set; } + public String TaskCategory { get; set; } + public String InformationDump { get; set; } + } +} \ No newline at end of file diff --git a/cli/EventParser_ConsoleApp/EventParser_CLI.csproj b/cli/EventParser_ConsoleApp/EventParser_CLI.csproj new file mode 100755 index 0000000..036b7a8 --- /dev/null +++ b/cli/EventParser_ConsoleApp/EventParser_CLI.csproj @@ -0,0 +1,106 @@ + + + + + Debug + AnyCPU + {0B61EE2C-2F75-4D41-BF75-A235E11309BC} + Exe + EventParser_ConsoleApp + EventParser_ConsoleApp + v4.6.1 + 512 + true + true + false + D:\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 1 + 1.0.0.%2a + false + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + 3F3076ECA4354C6804FCB68F0E0F981B9026B920 + + + EventParser_CLI_TemporaryKey.pfx + + + true + + + true + + + + ..\packages\CommandLineArgumentsParser.3.0.20\lib\net452\CommandLineArgumentsParser.dll + + + ..\packages\CsvHelper.12.1.2\lib\net45\CsvHelper.dll + + + + + ..\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll + + + + + + + + + + + + + + + + Designer + + + + + + False + Microsoft .NET Framework 4.6.1 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + + \ No newline at end of file diff --git a/cli/EventParser_ConsoleApp/Program.cs b/cli/EventParser_ConsoleApp/Program.cs new file mode 100755 index 0000000..89b6e54 --- /dev/null +++ b/cli/EventParser_ConsoleApp/Program.cs @@ -0,0 +1,197 @@ +using CommandLineParser.Arguments; +using CommandLineParser.Exceptions; +using CsvHelper; +using System; +using System.Collections; +using System.Data; +using System.Data.SqlClient; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; + +namespace EventParser.ConsoleApp +{ + public static class Arguments + { + public static string connString; + public static string input; + public static string output; + } + + internal class Program + { + // Logfile is generated with five column headers instead of six. This method ensures the logfile matches the column name headings specified in DataRecords. + private static void AddMissingHeader() + { + Console.WriteLine("Replacing log file header..."); + StreamReader reader = new StreamReader(Arguments.input); + string content = reader.ReadToEnd(); + reader.Close(); + + content = Regex.Replace(content, "Level,Date and Time,Source,Event ID,Task Category", "Level,DateAndTime,Source,EventID,TaskCategory,InformationDump"); + + StreamWriter writer = new StreamWriter(Arguments.input); //overwrites existing file instead of creating new file + writer.Write(content); + writer.Close(); + } + + // Extracts account name and generates Unique ID. Writes parsed CSV file to specified output. + private static void ParseLog() + { + Console.WriteLine("Parsing log file..."); + + using (var sr = new StreamReader(Arguments.input)) + { + using (var sw = new StreamWriter(Arguments.output)) + { + // CSVHelper initialization. + var reader = new CsvReader(sr); + var writer = new CsvWriter(sw); + + // Counters for records processed, and unique-ID logic respectively. + int i = 0; + int x = 0; + + // CSVReader will read the whole file into an enumerable. + IEnumerable records = reader.GetRecords().ToList(); + + foreach (DataRecord record in records) + { + // RegEx to extract account name. + string pattern1 = @"(?<=New Logon:\r\n\tSecurity\ ID\:\t\t).*"; + //string pattern2 = @"REGEX GOES HERE"; + + string uniqueID_timestamp = record.DateAndTime; + + // Logic for UniqueID. + var uniqueID = $"{uniqueID_timestamp}-{x++}"; + + // Order columns in CSV file will be written. + writer.WriteField(uniqueID); + writer.WriteField(record.Level); + writer.WriteField(record.DateAndTime); + writer.WriteField(record.Source); + writer.WriteField(record.EventID); + writer.WriteField(record.TaskCategory); + + string str = record.InformationDump; + if (Regex.IsMatch(str, pattern1)) + { + var matches = Regex.Matches(str, pattern1); + foreach (Match m in matches) + { + string accountName = m.Value; + writer.WriteField(accountName); + } + } + else + { + // There are instances where a record has no account name to be extracted. + writer.WriteField("Account name unavailable."); + } + + //if (Regex.IsMatch(str, pattern2)) + //{ + // var matches = Regex.Matches(str, pattern2); + // foreach (Match m in matches) + // { + // string extractedField = m.Value; + + // //extractedField = extractedField.Replace(@"", ""); + // writer.WriteField(extractedField); + // } + //} + //else + //{ + // writer.WriteField("Extracted field unavailable."); + //} + + // Ensure end-of-record is specified when using WriteField method. + writer.NextRecord(); + + // Display number of records processed. + // i++ + //i = i + 1; + //Console.WriteLine($"Records processed: {i}"); + } + } + } + } + + // Imports parsed CSV file into MS SQL Server through a Stored Procedure. + private static void ImportToMSSQL() + { + Console.WriteLine("Importing log file into MSSQL server..."); + + string connectionString = Arguments.connString; + + using (SqlConnection connection = new SqlConnection(connectionString)) + { + using (SqlCommand cmd = new SqlCommand("ImportLogs", connection)) + { + cmd.CommandType = CommandType.StoredProcedure; + + // See Stored Procedure. + cmd.Parameters.Add("@filepath", SqlDbType.VarChar).Value = Arguments.output; + + connection.Open(); + + cmd.ExecuteNonQuery(); + } + + connection.Close(); + } + } + + private static void Main(string[] args) + { + CommandLineParser.CommandLineParser parser = new CommandLineParser.CommandLineParser(); + + ValueArgument inputLogFile = new ValueArgument('i', "input", "Specify filepath of CSV file to process"); + inputLogFile.Optional = false; + ValueArgument outputLogFile = new ValueArgument('o', "output", "Specify filepath to save CSV file"); + outputLogFile.Optional = false; + ValueArgument connectionString = new ValueArgument('c', "connection", "Specify connection string"); + connectionString.Optional = false; + + parser.Arguments.Add(inputLogFile); + parser.Arguments.Add(outputLogFile); + parser.Arguments.Add(connectionString); + + //parser.ShowUsageHeader = "Welcome to EventParser!"; + //parser.ShowUsageFooter = "Thank you for using the application."; + //parser.ShowUsage(); + + try + { + parser.ParseCommandLine(args); + if (inputLogFile.Parsed) + { Arguments.input = inputLogFile.Value; } + if (outputLogFile.Parsed) + { Arguments.output = outputLogFile.Value; } + if (connectionString.Parsed) + { Arguments.connString = connectionString.Value; } + } + catch (CommandLineException e) + { + Console.WriteLine(e.Message); + parser.ShowUsage(); + } + + // Validation + if (Arguments.input != null && Arguments.output != null && Arguments.connString != null) + { + Console.WriteLine($"PROCESSING: {Arguments.input}"); + Stopwatch sw = Stopwatch.StartNew(); + + AddMissingHeader(); + ParseLog(); + ImportToMSSQL(); + + Console.WriteLine("Success."); + Console.WriteLine($"Time elapsed: {sw.ElapsedMilliseconds} ms"); + } + } + } +} diff --git a/cli/EventParser_ConsoleApp/Properties/AssemblyInfo.cs b/cli/EventParser_ConsoleApp/Properties/AssemblyInfo.cs new file mode 100755 index 0000000..f302023 --- /dev/null +++ b/cli/EventParser_ConsoleApp/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("EventParser_ConsoleApp")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("EventParser_ConsoleApp")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("0b61ee2c-2f75-4d41-bf75-a235e11309bc")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/cli/EventParser_ConsoleApp/packages.config b/cli/EventParser_ConsoleApp/packages.config new file mode 100755 index 0000000..4315b8c --- /dev/null +++ b/cli/EventParser_ConsoleApp/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/gui/.DS_Store b/gui/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..2edcab4845c43bcc16ba2f2c1413a78d33567ee2 GIT binary patch literal 6148 zcmeHKPjAyO6n|a|OFIFT24W|OkhoRQtgxMsLg@~0niK>FKwGj@ZL}ngl5`c6qJ9nd zINbOIT;ReTi5pkmvkf%OQf>$hKgs^t?~fh-USh`pzje&Kj3lh2Js*j!GS+Om*-D| z*yocTAIE+s#&M*!Q)7_cP8phR|*1d;^(aTrU z*RwZo#e#t0_9x_$!k_RC8x_kf(7hRTsy&zJAAOhfSBx9+LOTB7T}aOrdWfp$J#o@F z0N((I{u6yzJX=E&=?6dk}N@Fc0tJ1HKrtUYKvYddW z1d-2bQ7^5rvD!^rH3OP~|BwONA51KSw!*nYv2|c2t^kO2R13j2{ZdejsnAw9mxvY= zCPNWrC{tGqCc{y0DnDD{T%rsIrY;{$&CJvdg^Ag5d{ejsvnA?UGoTqLGEkG<7M=fl z)%X8mknU*)Gy`Xf0aouj{T?n!ovo$C(OGL^ImALjeshT;1S@qMiv}IVTUdmk&7=mR Vt#B?8H7NQ=K+vEo&A?w};0K#T_SgUb literal 0 HcmV?d00001 diff --git a/gui/EventParser.sln b/gui/EventParser.sln new file mode 100644 index 0000000..18f2a96 --- /dev/null +++ b/gui/EventParser.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.705 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventParser", "EventParser\EventParser.csproj", "{2612DA13-5C25-4189-A862-DED345F71E4C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2612DA13-5C25-4189-A862-DED345F71E4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2612DA13-5C25-4189-A862-DED345F71E4C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2612DA13-5C25-4189-A862-DED345F71E4C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2612DA13-5C25-4189-A862-DED345F71E4C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {CD34504D-55BD-4A3D-A9B2-4EB1379DCC00} + EndGlobalSection +EndGlobal diff --git a/gui/EventParser/App.config b/gui/EventParser/App.config new file mode 100644 index 0000000..dc5ea73 --- /dev/null +++ b/gui/EventParser/App.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/gui/EventParser/DataRecord.cs b/gui/EventParser/DataRecord.cs new file mode 100644 index 0000000..bcf1e9d --- /dev/null +++ b/gui/EventParser/DataRecord.cs @@ -0,0 +1,14 @@ +using System; + +namespace EventParser.GUI +{ + internal class DataRecord + { + public String Level { get; set; } + public String DateAndTime { get; set; } + public String Source { get; set; } + public String EventID { get; set; } + public String TaskCategory { get; set; } + public String InformationDump { get; set; } + } +} \ No newline at end of file diff --git a/gui/EventParser/EventParser.csproj b/gui/EventParser/EventParser.csproj new file mode 100644 index 0000000..ab8697a --- /dev/null +++ b/gui/EventParser/EventParser.csproj @@ -0,0 +1,156 @@ + + + + + Debug + AnyCPU + {2612DA13-5C25-4189-A862-DED345F71E4C} + WinExe + EventParser + EventParser + v4.6.1 + 512 + true + true + + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + DE3D84B12696F899F3B800E5E153BC4AEA76155F + + + EventParser_TemporaryKey.pfx + + + true + + + true + + + + ..\packages\com.rusanu.dataconnectiondialog.1.0.0.1\lib\net20\com.rusanu.dataconnectiondialog.dll + + + ..\packages\CsvHelper.12.1.2\lib\net45\CsvHelper.dll + + + + + + ..\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll + + + + + + + + + + + + + + + + Form + + + frmConnection.cs + + + Form + + + frmMain.cs + + + Form + + + frmAbout.cs + + + + + frmConnection.cs + + + frmMain.cs + + + frmAbout.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + Designer + + + + + False + Microsoft .NET Framework 4.6.1 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + + \ No newline at end of file diff --git a/gui/EventParser/GlobalParameters.cs b/gui/EventParser/GlobalParameters.cs new file mode 100644 index 0000000..c8f172e --- /dev/null +++ b/gui/EventParser/GlobalParameters.cs @@ -0,0 +1,16 @@ +namespace EventParser.GUI +{ + public static class Arguments + { + public static string connString { get; set; } + public static string input { get; set; } + public static string output { get; set; } + } + + // Necessary for connection string builder window. + public class ConnectionSettings + { + public string ConnectionString { get; set; } + public int ComandTimeout { get; set; } = 60; + } +} \ No newline at end of file diff --git a/gui/EventParser/Program.cs b/gui/EventParser/Program.cs new file mode 100644 index 0000000..18a14fd --- /dev/null +++ b/gui/EventParser/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Windows.Forms; + +namespace EventParser.GUI +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + private static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new frmMain()); + } + } +} \ No newline at end of file diff --git a/gui/EventParser/Properties/AssemblyInfo.cs b/gui/EventParser/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c2cbb85 --- /dev/null +++ b/gui/EventParser/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("EventParser")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("EventParser")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("2612da13-5c25-4189-a862-ded345f71e4c")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/gui/EventParser/Properties/Resources.Designer.cs b/gui/EventParser/Properties/Resources.Designer.cs new file mode 100644 index 0000000..94c55db --- /dev/null +++ b/gui/EventParser/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +// +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// + +namespace EventParser.GUI.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("EventParser.GUI.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/gui/EventParser/Properties/Resources.resx b/gui/EventParser/Properties/Resources.resx new file mode 100644 index 0000000..ffecec8 --- /dev/null +++ b/gui/EventParser/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/gui/EventParser/Properties/Settings.Designer.cs b/gui/EventParser/Properties/Settings.Designer.cs new file mode 100644 index 0000000..114c8d8 --- /dev/null +++ b/gui/EventParser/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +// +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// + +namespace EventParser.GUI.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/gui/EventParser/Properties/Settings.settings b/gui/EventParser/Properties/Settings.settings new file mode 100644 index 0000000..abf36c5 --- /dev/null +++ b/gui/EventParser/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/gui/EventParser/frmAbout.Designer.cs b/gui/EventParser/frmAbout.Designer.cs new file mode 100644 index 0000000..a13ac16 --- /dev/null +++ b/gui/EventParser/frmAbout.Designer.cs @@ -0,0 +1,201 @@ +namespace EventParser.GUI +{ + partial class frmAbout + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.btnClose = new System.Windows.Forms.Button(); + this.label6 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.button1 = new System.Windows.Forms.Button(); + this.label7 = new System.Windows.Forms.Label(); + this.label8 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.label1.Location = new System.Drawing.Point(152, 29); + this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(191, 37); + this.label1.TabIndex = 0; + this.label1.Text = "EventParser"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(93, 89); + this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(61, 20); + this.label2.TabIndex = 1; + this.label2.Text = "Author:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(221, 89); + this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(128, 20); + this.label3.TabIndex = 2; + this.label3.Text = "Isaac Mallampati"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(93, 132); + this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(52, 20); + this.label5.TabIndex = 3; + this.label5.Text = "Email:"; + // + // groupBox1 + // + this.groupBox1.Location = new System.Drawing.Point(18, 223); + this.groupBox1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.groupBox1.Size = new System.Drawing.Size(480, 18); + this.groupBox1.TabIndex = 8; + this.groupBox1.TabStop = false; + // + // btnClose + // + this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.btnClose.Location = new System.Drawing.Point(386, 297); + this.btnClose.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.btnClose.Name = "btnClose"; + this.btnClose.Size = new System.Drawing.Size(112, 35); + this.btnClose.TabIndex = 9; + this.btnClose.Text = "Close"; + this.btnClose.UseVisualStyleBackColor = true; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(93, 177); + this.label6.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(117, 20); + this.label6.TabIndex = 12; + this.label6.Text = "Phone number:"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(18, 305); + this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(316, 20); + this.label4.TabIndex = 14; + this.label4.Text = "Developed in July 2019. Ministry of Finance."; + // + // button1 + // + this.button1.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.button1.Location = new System.Drawing.Point(356, 252); + this.button1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(142, 35); + this.button1.TabIndex = 15; + this.button1.Text = "Read the docs"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(221, 132); + this.label7.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(174, 20); + this.label7.TabIndex = 16; + this.label7.Text = "EMAIL"; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(221, 177); + this.label8.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(118, 20); + this.label8.TabIndex = 17; + this.label8.Text = "PHONE"; + // + // frmAbout + // + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.btnClose; + this.ClientSize = new System.Drawing.Size(516, 340); + this.Controls.Add(this.label8); + this.Controls.Add(this.label7); + this.Controls.Add(this.button1); + this.Controls.Add(this.label4); + this.Controls.Add(this.label6); + this.Controls.Add(this.btnClose); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.label5); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "frmAbout"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "About EventParser"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.Button btnClose; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.Label label8; + } +} \ No newline at end of file diff --git a/gui/EventParser/frmAbout.cs b/gui/EventParser/frmAbout.cs new file mode 100644 index 0000000..98d5a73 --- /dev/null +++ b/gui/EventParser/frmAbout.cs @@ -0,0 +1,17 @@ +using System.Windows.Forms; + +namespace EventParser.GUI +{ + public partial class frmAbout : Form + { + public frmAbout() + { + InitializeComponent(); + } + + private void button1_Click(object sender, System.EventArgs e) + { + // remember to fix this + } + } +} \ No newline at end of file diff --git a/gui/EventParser/frmAbout.resx b/gui/EventParser/frmAbout.resx new file mode 100644 index 0000000..29dcb1b --- /dev/null +++ b/gui/EventParser/frmAbout.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/gui/EventParser/frmConnection.cs b/gui/EventParser/frmConnection.cs new file mode 100644 index 0000000..189f5ed --- /dev/null +++ b/gui/EventParser/frmConnection.cs @@ -0,0 +1,165 @@ +using System; +using System.Data.SqlClient; +using System.Diagnostics; +using System.Windows.Forms; + +namespace EventParser.GUI +{ + public partial class frmConnection : Form + { + public ConnectionSettings connectionSettings = null;// new ConnectionSettings(); + + private string ConnectionString + { + get + { + SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); + builder.DataSource = txtServerName.Text.Trim(); + if (cboAuthenticationType.SelectedIndex == 0) + { + builder.IntegratedSecurity = true; + } + else + { + builder.UserID = txtUserName.Text; + builder.Password = txtPassword.Text; + } + if (!string.IsNullOrEmpty(cboDatabases.Text)) + builder.InitialCatalog = cboDatabases.Text.Trim(); + return builder.ConnectionString; + } + } + + public class ConnectionSettings + { + public enum ActionsIfTableExist + { + Drop, + Append, + Skip + } + + public string ConnectionString { get; set; } + public int ComandTimeout { get; set; } = 60; + public bool DropAndRecreateTables { get; set; } = false; + } + + public frmConnection() + { + InitializeComponent(); + cboAuthenticationType.SelectedIndex = 0; + } + + private void cboAuthenticationType_SelectedIndexChanged(object sender, EventArgs e) + { + bool isSqlAuth = (cboAuthenticationType.SelectedIndex == 1); + lblUserName.Enabled = isSqlAuth; + lblPassword.Enabled = isSqlAuth; + txtUserName.Enabled = isSqlAuth; + txtPassword.Enabled = isSqlAuth; + + cboDatabases.Items.Clear(); + } + + private void btnOK_Click(object sender, EventArgs e) + { + this.connectionSettings = new ConnectionSettings(); + this.connectionSettings.ConnectionString = this.ConnectionString; + Arguments.connString = this.ConnectionString; + Arguments.connString = (this.ConnectionString); + Debug.Write(Arguments.connString); + this.connectionSettings.ComandTimeout = Convert.ToInt32(updTimeout.Value); + //this.connectionSettings.DropAndRecreateTables = chkDropCreate.Checked; + this.DialogResult = DialogResult.OK; + + this.Close(); + } + + private void cboDatabases_DropDown(object sender, EventArgs e) + { + if (CheckRequiredFields(true) == false) return; + + LoadDatabases(); + + if (cboDatabases.Items.Count != 0) + cboDatabases.SelectedIndex = 0; + } + + private bool CheckRequiredFields(bool showMessage = true) + { + if (string.IsNullOrEmpty(txtServerName.Text)) + { + if (showMessage) + MessageBox.Show("Server Name must be specified.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + return false; + } + + if (cboAuthenticationType.SelectedIndex == 1 && (string.IsNullOrEmpty(txtUserName.Text) || string.IsNullOrEmpty(txtPassword.Text))) + { + if (showMessage) + MessageBox.Show("User ID and Password must be specified.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + return false; + } + return true; + } + + private void LoadDatabases() + { + using (SqlConnection cnn = new SqlConnection(ConnectionString)) + { + using (SqlCommand cmd = new SqlCommand("SELECT name FROM master..sysdatabases ORDER BY name ASC", cnn)) + { + cboDatabases.Items.Clear(); + SqlDataReader dtr; + try + { + cnn.Open(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + Console.WriteLine(ex.ToString()); + return; + } + + dtr = cmd.ExecuteReader(); + while (dtr.Read()) + cboDatabases.Items.Add(dtr[0].ToString()); + } + } + } + + private void btnTest_Click(object sender, EventArgs e) + { + using (SqlConnection cnn = new SqlConnection(ConnectionString)) + { + try + { + cnn.Open(); + MessageBox.Show("Test connection succeeded.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void frmConnection_Load(object sender, EventArgs e) + { + if (this.connectionSettings == null) + return; + SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(this.connectionSettings.ConnectionString); + txtServerName.Text = builder.DataSource; + if (builder.IntegratedSecurity == true) + cboAuthenticationType.SelectedIndex = 0; + cboDatabases.Text = builder.InitialCatalog; + updTimeout.Value = this.connectionSettings.ComandTimeout; + //chkDropCreate.Checked = this.connectionSettings.DropAndRecreateTables; + } + + private void btnCancel_Click(object sender, EventArgs e) + { + } + } +} \ No newline at end of file diff --git a/gui/EventParser/frmConnection.designer.cs b/gui/EventParser/frmConnection.designer.cs new file mode 100644 index 0000000..d5ebfba --- /dev/null +++ b/gui/EventParser/frmConnection.designer.cs @@ -0,0 +1,294 @@ +namespace EventParser.GUI +{ + partial class frmConnection + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.cboDatabases = new System.Windows.Forms.ComboBox(); + this.label3 = new System.Windows.Forms.Label(); + this.updTimeout = new System.Windows.Forms.NumericUpDown(); + this.label5 = new System.Windows.Forms.Label(); + this.txtPassword = new System.Windows.Forms.TextBox(); + this.lblPassword = new System.Windows.Forms.Label(); + this.txtUserName = new System.Windows.Forms.TextBox(); + this.lblUserName = new System.Windows.Forms.Label(); + this.cboAuthenticationType = new System.Windows.Forms.ComboBox(); + this.label2 = new System.Windows.Forms.Label(); + this.txtServerName = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.btnCancel = new System.Windows.Forms.Button(); + this.btnOK = new System.Windows.Forms.Button(); + this.btnTest = new System.Windows.Forms.Button(); + this.groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.updTimeout)).BeginInit(); + this.SuspendLayout(); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.cboDatabases); + this.groupBox1.Controls.Add(this.label3); + this.groupBox1.Controls.Add(this.updTimeout); + this.groupBox1.Controls.Add(this.label5); + this.groupBox1.Controls.Add(this.txtPassword); + this.groupBox1.Controls.Add(this.lblPassword); + this.groupBox1.Controls.Add(this.txtUserName); + this.groupBox1.Controls.Add(this.lblUserName); + this.groupBox1.Controls.Add(this.cboAuthenticationType); + this.groupBox1.Controls.Add(this.label2); + this.groupBox1.Controls.Add(this.txtServerName); + this.groupBox1.Controls.Add(this.label1); + this.groupBox1.Location = new System.Drawing.Point(18, 18); + this.groupBox1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.groupBox1.Size = new System.Drawing.Size(452, 351); + this.groupBox1.TabIndex = 0; + this.groupBox1.TabStop = false; + // + // cboDatabases + // + this.cboDatabases.FormattingEnabled = true; + this.cboDatabases.Location = new System.Drawing.Point(140, 217); + this.cboDatabases.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.cboDatabases.Name = "cboDatabases"; + this.cboDatabases.Size = new System.Drawing.Size(282, 28); + this.cboDatabases.TabIndex = 9; + this.cboDatabases.DropDown += new System.EventHandler(this.cboDatabases_DropDown); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(9, 222); + this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(79, 20); + this.label3.TabIndex = 10; + this.label3.Text = "Database"; + // + // updTimeout + // + this.updTimeout.Increment = new decimal(new int[] { + 30, + 0, + 0, + 0}); + this.updTimeout.Location = new System.Drawing.Point(177, 282); + this.updTimeout.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.updTimeout.Maximum = new decimal(new int[] { + 1000000, + 0, + 0, + 0}); + this.updTimeout.Minimum = new decimal(new int[] { + 60, + 0, + 0, + 0}); + this.updTimeout.Name = "updTimeout"; + this.updTimeout.ReadOnly = true; + this.updTimeout.Size = new System.Drawing.Size(102, 26); + this.updTimeout.TabIndex = 4; + this.updTimeout.Value = new decimal(new int[] { + 60, + 0, + 0, + 0}); + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(9, 285); + this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(159, 20); + this.label5.TabIndex = 8; + this.label5.Text = "Comand timeout, sec"; + // + // txtPassword + // + this.txtPassword.Enabled = false; + this.txtPassword.Location = new System.Drawing.Point(224, 163); + this.txtPassword.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.txtPassword.Name = "txtPassword"; + this.txtPassword.PasswordChar = '*'; + this.txtPassword.Size = new System.Drawing.Size(198, 26); + this.txtPassword.TabIndex = 3; + // + // lblPassword + // + this.lblPassword.AutoSize = true; + this.lblPassword.Enabled = false; + this.lblPassword.Location = new System.Drawing.Point(135, 168); + this.lblPassword.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.lblPassword.Name = "lblPassword"; + this.lblPassword.Size = new System.Drawing.Size(82, 20); + this.lblPassword.TabIndex = 6; + this.lblPassword.Text = "Password:"; + // + // txtUserName + // + this.txtUserName.Enabled = false; + this.txtUserName.Location = new System.Drawing.Point(224, 123); + this.txtUserName.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.txtUserName.Name = "txtUserName"; + this.txtUserName.Size = new System.Drawing.Size(198, 26); + this.txtUserName.TabIndex = 2; + // + // lblUserName + // + this.lblUserName.AutoSize = true; + this.lblUserName.Enabled = false; + this.lblUserName.Location = new System.Drawing.Point(128, 128); + this.lblUserName.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.lblUserName.Name = "lblUserName"; + this.lblUserName.Size = new System.Drawing.Size(87, 20); + this.lblUserName.TabIndex = 4; + this.lblUserName.Text = "Username:"; + // + // cboAuthenticationType + // + this.cboAuthenticationType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cboAuthenticationType.FormattingEnabled = true; + this.cboAuthenticationType.Items.AddRange(new object[] { + "Windows Authentication", + "SQL Server Authentication"}); + this.cboAuthenticationType.Location = new System.Drawing.Point(140, 66); + this.cboAuthenticationType.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.cboAuthenticationType.Name = "cboAuthenticationType"; + this.cboAuthenticationType.Size = new System.Drawing.Size(282, 28); + this.cboAuthenticationType.TabIndex = 1; + this.cboAuthenticationType.SelectedIndexChanged += new System.EventHandler(this.cboAuthenticationType_SelectedIndexChanged); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(9, 71); + this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(112, 20); + this.label2.TabIndex = 2; + this.label2.Text = "Authentication"; + // + // txtServerName + // + this.txtServerName.Location = new System.Drawing.Point(140, 20); + this.txtServerName.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.txtServerName.Name = "txtServerName"; + this.txtServerName.Size = new System.Drawing.Size(282, 26); + this.txtServerName.TabIndex = 0; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(9, 25); + this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(99, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Server name"; + // + // btnCancel + // + this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.btnCancel.Location = new System.Drawing.Point(363, 378); + this.btnCancel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.btnCancel.Name = "btnCancel"; + this.btnCancel.Size = new System.Drawing.Size(112, 35); + this.btnCancel.TabIndex = 6; + this.btnCancel.Text = "Cancel"; + this.btnCancel.UseVisualStyleBackColor = true; + this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); + // + // btnOK + // + this.btnOK.Location = new System.Drawing.Point(242, 378); + this.btnOK.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.btnOK.Name = "btnOK"; + this.btnOK.Size = new System.Drawing.Size(112, 35); + this.btnOK.TabIndex = 5; + this.btnOK.Text = "OK"; + this.btnOK.UseVisualStyleBackColor = true; + this.btnOK.Click += new System.EventHandler(this.btnOK_Click); + // + // btnTest + // + this.btnTest.Location = new System.Drawing.Point(21, 378); + this.btnTest.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.btnTest.Name = "btnTest"; + this.btnTest.Size = new System.Drawing.Size(92, 35); + this.btnTest.TabIndex = 7; + this.btnTest.Text = "Test"; + this.btnTest.UseVisualStyleBackColor = true; + this.btnTest.Click += new System.EventHandler(this.btnTest_Click); + // + // frmConnection + // + this.AcceptButton = this.btnOK; + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.btnCancel; + this.ClientSize = new System.Drawing.Size(480, 431); + this.Controls.Add(this.btnTest); + this.Controls.Add(this.btnOK); + this.Controls.Add(this.btnCancel); + this.Controls.Add(this.groupBox1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "frmConnection"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Connection to SQL Server"; + this.Load += new System.EventHandler(this.frmConnection_Load); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.updTimeout)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.NumericUpDown updTimeout; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.TextBox txtPassword; + private System.Windows.Forms.Label lblPassword; + private System.Windows.Forms.TextBox txtUserName; + private System.Windows.Forms.Label lblUserName; + private System.Windows.Forms.ComboBox cboAuthenticationType; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox txtServerName; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button btnCancel; + private System.Windows.Forms.Button btnOK; + private System.Windows.Forms.ComboBox cboDatabases; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Button btnTest; + } +} \ No newline at end of file diff --git a/gui/EventParser/frmConnection.resx b/gui/EventParser/frmConnection.resx new file mode 100644 index 0000000..29dcb1b --- /dev/null +++ b/gui/EventParser/frmConnection.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/gui/EventParser/frmMain.Designer.cs b/gui/EventParser/frmMain.Designer.cs new file mode 100644 index 0000000..16a866e --- /dev/null +++ b/gui/EventParser/frmMain.Designer.cs @@ -0,0 +1,389 @@ + + +namespace EventParser.GUI +{ + partial class frmMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.browseCSV = new System.Windows.Forms.OpenFileDialog(); + this.mnuAboutHelp = new System.Windows.Forms.ToolStripMenuItem(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.labelOpenLogFile = new System.Windows.Forms.Label(); + this.btnStart = new System.Windows.Forms.Button(); + this.btnOpenLogFile = new System.Windows.Forms.Button(); + this.groupBoxFilepaths = new System.Windows.Forms.GroupBox(); + this.txtOpenLogFile = new System.Windows.Forms.TextBox(); + this.btnSetConnectionString = new System.Windows.Forms.Button(); + this.txtConnectionString = new System.Windows.Forms.TextBox(); + this.groupBoxConnString = new System.Windows.Forms.GroupBox(); + this.txtSaveLogFile = new System.Windows.Forms.TextBox(); + this.labelSaveLogFile = new System.Windows.Forms.Label(); + this.groupBoxOutput = new System.Windows.Forms.GroupBox(); + this.label3 = new System.Windows.Forms.Label(); + this.txtOutput = new System.Windows.Forms.TextBox(); + this.statusStrip1 = new System.Windows.Forms.StatusStrip(); + this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); + this.processedRecords = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabel4 = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabel2 = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabel5 = new System.Windows.Forms.ToolStripStatusLabel(); + this.status = new System.Windows.Forms.ToolStripStatusLabel(); + this.btnCancel = new System.Windows.Forms.Button(); + this.btnSaveLogFile = new System.Windows.Forms.Button(); + this.btnReset = new System.Windows.Forms.Button(); + this.menuStrip1.SuspendLayout(); + this.groupBoxFilepaths.SuspendLayout(); + this.groupBoxConnString.SuspendLayout(); + this.groupBoxOutput.SuspendLayout(); + this.statusStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // browseCSV + // + this.browseCSV.FileName = "browseCSV"; + this.browseCSV.Title = "Browse"; + // + // mnuAboutHelp + // + this.mnuAboutHelp.Name = "mnuAboutHelp"; + this.mnuAboutHelp.Size = new System.Drawing.Size(118, 29); + this.mnuAboutHelp.Text = "&About/Help"; + this.mnuAboutHelp.Click += new System.EventHandler(this.mnuFile_Click); + // + // menuStrip1 + // + this.menuStrip1.ImageScalingSize = new System.Drawing.Size(24, 24); + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.mnuAboutHelp}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Padding = new System.Windows.Forms.Padding(9, 3, 0, 3); + this.menuStrip1.Size = new System.Drawing.Size(861, 35); + this.menuStrip1.TabIndex = 22; + this.menuStrip1.Text = "menuStrip1"; + // + // labelOpenLogFile + // + this.labelOpenLogFile.AutoSize = true; + this.labelOpenLogFile.Location = new System.Drawing.Point(9, 25); + this.labelOpenLogFile.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelOpenLogFile.Name = "labelOpenLogFile"; + this.labelOpenLogFile.Size = new System.Drawing.Size(64, 20); + this.labelOpenLogFile.TabIndex = 14; + this.labelOpenLogFile.Text = "Log file:"; + // + // btnStart + // + this.btnStart.Enabled = false; + this.btnStart.Location = new System.Drawing.Point(696, 612); + this.btnStart.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.btnStart.Name = "btnStart"; + this.btnStart.Size = new System.Drawing.Size(122, 35); + this.btnStart.TabIndex = 3; + this.btnStart.Text = "Start"; + this.btnStart.UseVisualStyleBackColor = true; + this.btnStart.Click += new System.EventHandler(this.btnStart_Click); + // + // btnOpenLogFile + // + this.btnOpenLogFile.Location = new System.Drawing.Point(670, 45); + this.btnOpenLogFile.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.btnOpenLogFile.Name = "btnOpenLogFile"; + this.btnOpenLogFile.Size = new System.Drawing.Size(112, 35); + this.btnOpenLogFile.TabIndex = 1; + this.btnOpenLogFile.Text = "Browse..."; + this.btnOpenLogFile.UseVisualStyleBackColor = true; + this.btnOpenLogFile.Click += new System.EventHandler(this.btnBrowse_Click); + // + // groupBoxFilepaths + // + this.groupBoxFilepaths.Controls.Add(this.btnOpenLogFile); + this.groupBoxFilepaths.Controls.Add(this.txtOpenLogFile); + this.groupBoxFilepaths.Controls.Add(this.labelOpenLogFile); + this.groupBoxFilepaths.Location = new System.Drawing.Point(36, 149); + this.groupBoxFilepaths.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.groupBoxFilepaths.Name = "groupBoxFilepaths"; + this.groupBoxFilepaths.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.groupBoxFilepaths.Size = new System.Drawing.Size(792, 220); + this.groupBoxFilepaths.TabIndex = 1; + this.groupBoxFilepaths.TabStop = false; + // + // txtOpenLogFile + // + this.txtOpenLogFile.Location = new System.Drawing.Point(9, 49); + this.txtOpenLogFile.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.txtOpenLogFile.Name = "txtOpenLogFile"; + this.txtOpenLogFile.ReadOnly = true; + this.txtOpenLogFile.Size = new System.Drawing.Size(650, 26); + this.txtOpenLogFile.TabIndex = 2; + this.txtOpenLogFile.TabStop = false; + // + // btnSetConnectionString + // + this.btnSetConnectionString.Location = new System.Drawing.Point(670, 25); + this.btnSetConnectionString.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.btnSetConnectionString.Name = "btnSetConnectionString"; + this.btnSetConnectionString.Size = new System.Drawing.Size(112, 35); + this.btnSetConnectionString.TabIndex = 2; + this.btnSetConnectionString.Text = "Options"; + this.btnSetConnectionString.UseVisualStyleBackColor = true; + this.btnSetConnectionString.Click += new System.EventHandler(this.btnSetConnectionString_Click); + // + // txtConnectionString + // + this.txtConnectionString.AcceptsTab = true; + this.txtConnectionString.Location = new System.Drawing.Point(9, 29); + this.txtConnectionString.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.txtConnectionString.Name = "txtConnectionString"; + this.txtConnectionString.Size = new System.Drawing.Size(650, 26); + this.txtConnectionString.TabIndex = 1; + this.txtConnectionString.TextChanged += new System.EventHandler(this.txtConnectionString_TextChanged); + // + // groupBoxConnString + // + this.groupBoxConnString.Controls.Add(this.btnSetConnectionString); + this.groupBoxConnString.Controls.Add(this.txtConnectionString); + this.groupBoxConnString.Location = new System.Drawing.Point(36, 57); + this.groupBoxConnString.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.groupBoxConnString.Name = "groupBoxConnString"; + this.groupBoxConnString.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.groupBoxConnString.Size = new System.Drawing.Size(792, 83); + this.groupBoxConnString.TabIndex = 0; + this.groupBoxConnString.TabStop = false; + this.groupBoxConnString.Text = "SQL Server connection string:"; + // + // txtSaveLogFile + // + this.txtSaveLogFile.Location = new System.Drawing.Point(45, 300); + this.txtSaveLogFile.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.txtSaveLogFile.Name = "txtSaveLogFile"; + this.txtSaveLogFile.ReadOnly = true; + this.txtSaveLogFile.Size = new System.Drawing.Size(650, 26); + this.txtSaveLogFile.TabIndex = 4; + this.txtSaveLogFile.TabStop = false; + // + // labelSaveLogFile + // + this.labelSaveLogFile.AutoSize = true; + this.labelSaveLogFile.Location = new System.Drawing.Point(45, 277); + this.labelSaveLogFile.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelSaveLogFile.Name = "labelSaveLogFile"; + this.labelSaveLogFile.Size = new System.Drawing.Size(172, 20); + this.labelSaveLogFile.TabIndex = 17; + this.labelSaveLogFile.Text = "Parsed log file (output):"; + // + // groupBoxOutput + // + this.groupBoxOutput.Controls.Add(this.label3); + this.groupBoxOutput.Controls.Add(this.txtOutput); + this.groupBoxOutput.Location = new System.Drawing.Point(36, 380); + this.groupBoxOutput.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.groupBoxOutput.Name = "groupBoxOutput"; + this.groupBoxOutput.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.groupBoxOutput.Size = new System.Drawing.Size(792, 223); + this.groupBoxOutput.TabIndex = 21; + this.groupBoxOutput.TabStop = false; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(10, 12); + this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(62, 20); + this.label3.TabIndex = 32; + this.label3.Text = "Output:"; + // + // txtOutput + // + this.txtOutput.Location = new System.Drawing.Point(9, 35); + this.txtOutput.Multiline = true; + this.txtOutput.Name = "txtOutput"; + this.txtOutput.ReadOnly = true; + this.txtOutput.ScrollBars = System.Windows.Forms.ScrollBars.Both; + this.txtOutput.Size = new System.Drawing.Size(774, 169); + this.txtOutput.TabIndex = 31; + this.txtOutput.TabStop = false; + // + // statusStrip1 + // + this.statusStrip1.ImageScalingSize = new System.Drawing.Size(24, 24); + this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusLabel1, + this.processedRecords, + this.toolStripStatusLabel4, + this.toolStripStatusLabel2, + this.toolStripStatusLabel5, + this.status}); + this.statusStrip1.Location = new System.Drawing.Point(0, 658); + this.statusStrip1.Name = "statusStrip1"; + this.statusStrip1.Padding = new System.Windows.Forms.Padding(2, 0, 14, 0); + this.statusStrip1.Size = new System.Drawing.Size(861, 30); + this.statusStrip1.TabIndex = 29; + this.statusStrip1.Text = "statusStrip1"; + // + // toolStripStatusLabel1 + // + this.toolStripStatusLabel1.Name = "toolStripStatusLabel1"; + this.toolStripStatusLabel1.Size = new System.Drawing.Size(0, 25); + // + // processedRecords + // + this.processedRecords.Name = "processedRecords"; + this.processedRecords.Size = new System.Drawing.Size(0, 25); + // + // toolStripStatusLabel4 + // + this.toolStripStatusLabel4.Name = "toolStripStatusLabel4"; + this.toolStripStatusLabel4.RightToLeftAutoMirrorImage = true; + this.toolStripStatusLabel4.Size = new System.Drawing.Size(281, 25); + this.toolStripStatusLabel4.Spring = true; + this.toolStripStatusLabel4.Text = " "; + // + // toolStripStatusLabel2 + // + this.toolStripStatusLabel2.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.toolStripStatusLabel2.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None; + this.toolStripStatusLabel2.Name = "toolStripStatusLabel2"; + this.toolStripStatusLabel2.Size = new System.Drawing.Size(0, 25); + this.toolStripStatusLabel2.TextImageRelation = System.Windows.Forms.TextImageRelation.TextBeforeImage; + // + // toolStripStatusLabel5 + // + this.toolStripStatusLabel5.Name = "toolStripStatusLabel5"; + this.toolStripStatusLabel5.RightToLeftAutoMirrorImage = true; + this.toolStripStatusLabel5.Size = new System.Drawing.Size(281, 25); + this.toolStripStatusLabel5.Spring = true; + this.toolStripStatusLabel5.Text = " "; + // + // status + // + this.status.Name = "status"; + this.status.RightToLeftAutoMirrorImage = true; + this.status.Size = new System.Drawing.Size(281, 25); + this.status.Spring = true; + this.status.Text = " "; + // + // btnCancel + // + this.btnCancel.Location = new System.Drawing.Point(566, 614); + this.btnCancel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.btnCancel.Name = "btnCancel"; + this.btnCancel.Size = new System.Drawing.Size(122, 35); + this.btnCancel.TabIndex = 4; + this.btnCancel.Text = "Cancel"; + this.btnCancel.UseVisualStyleBackColor = true; + this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); + // + // btnSaveLogFile + // + this.btnSaveLogFile.Location = new System.Drawing.Point(705, 297); + this.btnSaveLogFile.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.btnSaveLogFile.Name = "btnSaveLogFile"; + this.btnSaveLogFile.Size = new System.Drawing.Size(112, 35); + this.btnSaveLogFile.TabIndex = 2; + this.btnSaveLogFile.Text = "Browse..."; + this.btnSaveLogFile.UseVisualStyleBackColor = true; + this.btnSaveLogFile.Click += new System.EventHandler(this.btnLogOutput_Click); + // + // btnReset + // + this.btnReset.Location = new System.Drawing.Point(36, 612); + this.btnReset.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.btnReset.Name = "btnReset"; + this.btnReset.Size = new System.Drawing.Size(122, 35); + this.btnReset.TabIndex = 5; + this.btnReset.Text = "Reset"; + this.btnReset.UseVisualStyleBackColor = true; + this.btnReset.Click += new System.EventHandler(this.btnReset_Click); + // + // frmMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(861, 688); + this.Controls.Add(this.btnReset); + this.Controls.Add(this.btnCancel); + this.Controls.Add(this.statusStrip1); + this.Controls.Add(this.groupBoxOutput); + this.Controls.Add(this.btnSaveLogFile); + this.Controls.Add(this.txtSaveLogFile); + this.Controls.Add(this.labelSaveLogFile); + this.Controls.Add(this.menuStrip1); + this.Controls.Add(this.btnStart); + this.Controls.Add(this.groupBoxFilepaths); + this.Controls.Add(this.groupBoxConnString); + this.Name = "frmMain"; + this.Text = "EventParser"; + this.Load += new System.EventHandler(this.frmMain_Load); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + this.groupBoxFilepaths.ResumeLayout(false); + this.groupBoxFilepaths.PerformLayout(); + this.groupBoxConnString.ResumeLayout(false); + this.groupBoxConnString.PerformLayout(); + this.groupBoxOutput.ResumeLayout(false); + this.groupBoxOutput.PerformLayout(); + this.statusStrip1.ResumeLayout(false); + this.statusStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.OpenFileDialog browseCSV; + private System.Windows.Forms.ToolStripMenuItem mnuAboutHelp; + private System.Windows.Forms.MenuStrip menuStrip1; + private System.Windows.Forms.Label labelOpenLogFile; + private System.Windows.Forms.Button btnStart; + private System.Windows.Forms.Button btnOpenLogFile; + private System.Windows.Forms.GroupBox groupBoxFilepaths; + private System.Windows.Forms.TextBox txtOpenLogFile; + private System.Windows.Forms.Button btnSetConnectionString; + public System.Windows.Forms.TextBox txtConnectionString; + private System.Windows.Forms.GroupBox groupBoxConnString; + private System.Windows.Forms.TextBox txtSaveLogFile; + private System.Windows.Forms.Label labelSaveLogFile; + private System.Windows.Forms.GroupBox groupBoxOutput; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.StatusStrip statusStrip1; + private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1; + private System.Windows.Forms.ToolStripStatusLabel processedRecords; + private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel2; + private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel4; + private System.Windows.Forms.ToolStripStatusLabel status; + private System.Windows.Forms.TextBox txtOutput; + private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel5; + private System.Windows.Forms.Button btnCancel; + private System.Windows.Forms.Button btnSaveLogFile; + private System.Windows.Forms.Button btnReset; + } +} + diff --git a/gui/EventParser/frmMain.cs b/gui/EventParser/frmMain.cs new file mode 100644 index 0000000..0b20c4a --- /dev/null +++ b/gui/EventParser/frmMain.cs @@ -0,0 +1,272 @@ +using CsvHelper; +using System; +using System.Collections; +using System.Configuration; +using System.Data; +using System.Data.SqlClient; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; +using System.Windows.Forms; + +namespace EventParser.GUI +{ + public partial class frmMain : Form + { + public frmMain() + { + InitializeComponent(); + } + + private void frmMain_Load(object sender, EventArgs e) + { + txtConnectionString.Text = ConfigurationManager.AppSettings["ConnectionString"]; + } + + private ConnectionSettings connectionSettings = new ConnectionSettings(); + + public void btnSetConnectionString_Click(object sender, EventArgs e) + { + frmConnection frm = new frmConnection(); + frm.ShowDialog(); + this.txtConnectionString.Text = Arguments.connString; + } + + private void btnCancel_Click(object sender, EventArgs e) + { + Application.Exit(); + } + + private void mnuFile_Click(object sender, EventArgs e) + { + frmAbout about = new frmAbout(); + about.ShowDialog(); + } + + private void btnReset_Click(object sender, EventArgs e) + { + Application.Restart(); + } + + private void buttonValidate() + { + btnStart.Enabled = Arguments.input != null && Arguments.output != null && Arguments.connString != null; + } + + private void btnBrowse_Click(object sender, EventArgs e) + { + OpenFileDialog openCSVLog = new OpenFileDialog + { + InitialDirectory = @"C:\", + Title = "Open CSV log file", + + CheckFileExists = true, + CheckPathExists = true, + + Filter = @"CSV files (*.csv)|*.csv", + //Filter = @"All files (*.*)|*.*|CSV files (*.csv)|*.csv", + FilterIndex = 2, + RestoreDirectory = true, + }; + + if (openCSVLog.ShowDialog() == DialogResult.OK) + { + txtOpenLogFile.Text = openCSVLog.FileName; + Arguments.input = openCSVLog.FileName; + buttonValidate(); + } + } + + private void btnLogOutput_Click(object sender, EventArgs e) + { + SaveFileDialog saveCSVLog = new SaveFileDialog + { + InitialDirectory = @"C:\", + Title = "Save formatted CSV log file", + + CheckPathExists = true, + + Filter = @"All files (*.*)|*.*|CSV files (*.csv)|*.csv", + FilterIndex = 2, + RestoreDirectory = true, + }; + + if (saveCSVLog.ShowDialog() == DialogResult.OK) + { + txtSaveLogFile.Text = saveCSVLog.FileName; + Arguments.output = saveCSVLog.FileName; + buttonValidate(); + } + } + + private void txtConnectionString_TextChanged(object sender, EventArgs e) + { + Arguments.connString = txtConnectionString.Text; + buttonValidate(); + } + + private void setAppSetting(string key, string value) + { + // Load App Settings. + Configuration config = ConfigurationManager.OpenExeConfiguration( + System.Reflection.Assembly.GetExecutingAssembly().Location); + + // Check if key exists in the settings. + if (config.AppSettings.Settings[key] != null) + { + // If key exists, delete it. + config.AppSettings.Settings.Remove(key); + } + // Add new key-value pair. + config.AppSettings.Settings.Add(key, value); + // Save the changed settings. + config.Save(ConfigurationSaveMode.Modified); + } + + // Logfile is generated with five column headers instead of six. This method ensures the logfile matches the column name headings specified in DataRecords. + private void AddMissingHeader() + { + txtOutput.AppendText("Replacing log file header...\r\n"); + StreamReader reader = new StreamReader(Arguments.input); + string content = reader.ReadToEnd(); + reader.Close(); + + content = Regex.Replace(content, "Level,Date and Time,Source,Event ID,Task Category", "Level,DateAndTime,Source,EventID,TaskCategory,InformationDump"); + + StreamWriter writer = new StreamWriter(Arguments.input); //overwrites existing file instead of creating new file + writer.Write(content); + writer.Close(); + } + + // Extracts account name and generates Unique ID. Writes parsed CSV file to specified output. + public void ParseLog() + { + txtOutput.AppendText("Parsing log file...\r\n"); + + using (var sr = new StreamReader(Arguments.input)) + { + using (var sw = new StreamWriter(Arguments.output)) + { + // CSVHelper initialization. + var reader = new CsvReader(sr); + var writer = new CsvWriter(sw); + + // Counters for records processed, and unique-ID logic respectively. + // int i = 0; + int x = 0; + + // CSVReader will read the whole file into an enumerable. + IEnumerable records = reader.GetRecords().ToList(); + + foreach (DataRecord record in records) + { + // RegEx pattern to extract account name. + string pattern1 = @"(?<=New Logon:\r\n\tSecurity\ ID\:\t\t).*"; + //string pattern2 = @"REGEX GOES HERE"; + + string uniqueID_timestamp = record.DateAndTime; + + // Logic for UniqueID. + var uniqueID = $"{uniqueID_timestamp}-{x++}"; + + // Order columns in CSV file will be written. + writer.WriteField(uniqueID); + writer.WriteField(record.Level); + writer.WriteField(record.DateAndTime); + writer.WriteField(record.Source); + writer.WriteField(record.EventID); + writer.WriteField(record.TaskCategory); + + string str = record.InformationDump; + if (Regex.IsMatch(str, pattern1)) + { + var matches = Regex.Matches(str, pattern1); + foreach (Match m in matches) + { + string accountName = m.Value; + writer.WriteField(accountName); + } + } + else + { + // There are instances where a record has no account name to be extracted. + writer.WriteField("Account name unavailable."); + } + + //if (Regex.IsMatch(str, pattern2)) + //{ + // var matches = Regex.Matches(str, pattern2); + // foreach (Match m in matches) + // { + // string extractedField = m.Value; + + // //extractedField = extractedField.Replace(@"", ""); + // writer.WriteField(extractedField); + // } + //} + //else + //{ + // writer.WriteField("Extracted field unavailable."); + //} + + // Ensure end-of-record is specified when using WriteField method. + writer.NextRecord(); + + // Display number of records processed. + // i++ + //i = i + 1; + //txtOutput.AppendText($"Records processed: {i}"); + } + } + } + } + + // Imports parsed CSV file into MS SQL Server through a Stored Procedure. + public void ImportToMSSQL() + { + txtOutput.AppendText("Importing log file into MSSQL server...\r\n"); + + string connectionString = Arguments.connString; + + using (SqlConnection connection = new SqlConnection(connectionString)) + { + using (SqlCommand cmd = new SqlCommand("ImportLogs", connection)) + { + cmd.CommandType = CommandType.StoredProcedure; + + // See Stored Procedure. + cmd.Parameters.Add("@filepath", SqlDbType.VarChar).Value = Arguments.output; + + connection.Open(); + + cmd.ExecuteNonQuery(); + } + + connection.Close(); + } + } + + public void btnStart_Click(object sender, EventArgs e) + { + // Save the connection string to app settings. + setAppSetting("ConnectionString", Arguments.connString); + + txtOutput.AppendText($"Begin processing: {Arguments.input} \r\n"); + + try + { + AddMissingHeader(); + ParseLog(); + ImportToMSSQL(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + Console.WriteLine(ex.ToString()); + return; + } + + txtOutput.AppendText("Done."); // fix to only output if no errors are returned + } + } +} \ No newline at end of file diff --git a/gui/EventParser/frmMain.resx b/gui/EventParser/frmMain.resx new file mode 100644 index 0000000..14e7906 --- /dev/null +++ b/gui/EventParser/frmMain.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 171, 17 + + + 327, 17 + + + 25 + + \ No newline at end of file diff --git a/gui/EventParser/packages.config b/gui/EventParser/packages.config new file mode 100644 index 0000000..f25a875 --- /dev/null +++ b/gui/EventParser/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file