private void ExportToSQLServer(EventLogExportSettings eventLogSettings) { EventLogOnSQLServer target = new EventLogOnSQLServer(_optionsBuilder.Options, eventLogSettings.Portion); target.SetInformationSystem(new InformationSystemsBase() { Name = eventLogSettings.InforamtionSystemName, Description = eventLogSettings.InforamtionSystemDescription }); ExportHelper.ExportToTargetStorage(eventLogSettings, target); long rowsInDB; using (EventLogContext context = EventLogContext.Create(_optionsBuilder.Options, _settings.DBMSActions)) { var informationSystem = context.InformationSystems .First(i => i.Name == eventLogSettings.InforamtionSystemName); var getCount = context.RowsData .Where(r => r.InformationSystemId == informationSystem.Id) .LongCountAsync(); getCount.Wait(); rowsInDB = getCount.Result; } long rowsInSourceFiles; using (EventLogReader reader = EventLogReader.CreateReader(eventLogSettings.EventLogPath)) rowsInSourceFiles = reader.Count(); Assert.NotEqual(0, rowsInSourceFiles); Assert.NotEqual(0, rowsInDB); Assert.Equal(rowsInSourceFiles, rowsInDB); }
static void Main() { IConfiguration Configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .Build(); IConfigurationSection eventLogSection = Configuration.GetSection("EventLog"); string eventLogPath = eventLogSection.GetValue("SourcePath", string.Empty); int watchPeriodSeconds = eventLogSection.GetValue("WatchPeriod", 60); int watchPeriodSecondsMs = watchPeriodSeconds * 1000; bool useWatchMode = eventLogSection.GetValue("UseWatchMode", false); int portion = eventLogSection.GetValue("Portion", 1000); IConfigurationSection informationSystemSection = Configuration.GetSection("InformationSystem"); string informationSystemName = informationSystemSection.GetValue("Name", string.Empty); string informationSystemDescription = informationSystemSection.GetValue("Description", string.Empty); if (string.IsNullOrEmpty(eventLogPath)) { Console.WriteLine("Не указан каталог с файлами данных журнала регистрации."); Console.WriteLine("Для выхода нажмите любую клавишу..."); Console.Read(); return; } Console.WriteLine(); Console.WriteLine(); string connectionString = Configuration.GetConnectionString("EventLogDatabase"); var optionsBuilder = new DbContextOptionsBuilder <EventLogContext>(); optionsBuilder.UseSqlServer(connectionString); using (EventLogExportMaster exporter = new EventLogExportMaster()) { exporter.SetEventLogPath(eventLogPath); EventLogOnSQLServer target = new EventLogOnSQLServer(optionsBuilder.Options, portion); target.SetInformationSystem(new InformationSystemsBase() { Name = informationSystemName, Description = informationSystemDescription }); exporter.SetTarget(target); exporter.BeforeExportData += BeforeExportData; exporter.AfterExportData += AfterExportData; exporter.OnErrorExportData += OnErrorExportData; _beginPortionExport = DateTime.Now; if (useWatchMode) { while (true) { if (Console.KeyAvailable) { if (Console.ReadKey().KeyChar == 'q') { break; } } while (exporter.NewDataAvailable()) { exporter.SendData(); Thread.Sleep(watchPeriodSecondsMs); } } } else { while (exporter.NewDataAvailable()) { exporter.SendData(); } } } Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Для выхода нажмите любую клавишу..."); Console.Read(); }