Exemplo n.º 1
0
        public override void Save(IList <RowData> rowsData)
        {
            using (EventLogContext _context = EventLogContext.Create(_databaseOptions, _databaseActions))
            {
                if (_maxPeriodRowData == DateTime.MinValue)
                {
                    _maxPeriodRowData = _context.GetRowsDataMaxPeriod(_system);
                }

                List <Database.Models.RowData> newEntities = new List <Database.Models.RowData>();
                foreach (var itemRow in rowsData)
                {
                    if (itemRow == null)
                    {
                        continue;
                    }
                    if (_maxPeriodRowData != DateTime.MinValue && itemRow.Period <= _maxPeriodRowData)
                    {
                        if (_context.RowDataExistOnDatabase(_system, itemRow))
                        {
                            continue;
                        }
                    }

                    newEntities.Add(new Database.Models.RowData(_system, itemRow, _referencesCache));
                }

                _context.BulkInsert(newEntities);
            }
        }
        private string GetConfigFile()
        {
            // TODO
            // Перенести формирование конфигурационного файла в скрипты CI

            string configFilePath = "appsettings.json";

            if (!File.Exists(configFilePath))
            {
                configFilePath = "travisci-appsettings.json";
                IConfiguration Configuration = new ConfigurationBuilder()
                                               .AddJsonFile(configFilePath, optional: true, reloadOnChange: true)
                                               .Build();
                string connectionString = Configuration.GetConnectionString("EventLogDatabase");
                try
                {
                    _optionsBuilder = new DbContextOptionsBuilder <EventLogContext>();
                    _optionsBuilder.UseNpgsql(connectionString);
                    using (EventLogContext context = EventLogContext.Create(_optionsBuilder.Options, new EventLogPostgreSQLActions()))
                        context.Database.EnsureDeleted();
                }
                catch
                {
                    configFilePath = "appveyor-appsettings.json";
                }
            }

            if (!File.Exists(configFilePath))
            {
                throw new Exception("Файл конфигурации не обнаружен.");
            }

            return(configFilePath);
        }
Exemplo n.º 3
0
        public override void SaveLogPosition(FileInfo logFileInfo, EventLogPosition position)
        {
            using (EventLogContext _context = EventLogContext.Create(_databaseOptions, _databaseActions))
                _context.SaveLogPosition(_system, logFileInfo, position);

            _lastEventLogFilePosition = position;
        }
        private void ExportToPostgreSQL(EventLogExportSettings eventLogSettings)
        {
            EventLogOnPostgreSQL target = new EventLogOnPostgreSQL(_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);
        }
Exemplo n.º 5
0
        public override void UpdateReferences(ReferencesData data)
        {
            using (EventLogContext _context = EventLogContext.Create(_databaseOptions, _databaseActions))
            {
                _context.FillReferencesToSave(_system, data);
                _context.SaveChanges();

                if (_referencesCache == null)
                {
                    _referencesCache = new ReferencesDataCache(_system);
                }
                _referencesCache.FillByDatabaseContext(_context);
            }
        }
        public EventLogExportMasterTests()
        {
            string configFilePath = GetConfigFile();

            _settings = new CommonTestSettings(
                configFilePath,
                new EventLogPostgreSQLActions());

            _optionsBuilder = new DbContextOptionsBuilder <EventLogContext>();
            _optionsBuilder.UseNpgsql(_settings.ConnectionString);

            using (EventLogContext context = EventLogContext.Create(_optionsBuilder.Options, _settings.DBMSActions))
                context.Database.EnsureDeleted();
        }
Exemplo n.º 7
0
        public override EventLogPosition GetLastPosition()
        {
            if (_lastEventLogFilePosition != null)
            {
                return(_lastEventLogFilePosition);
            }

            EventLogPosition position;

            using (EventLogContext _context = EventLogContext.Create(_databaseOptions, _databaseActions))
                position = _context.GetLastPosition(_system);
            _lastEventLogFilePosition = position;

            return(position);
        }
Exemplo n.º 8
0
 public override void SetInformationSystem(InformationSystemsBase system)
 {
     using (EventLogContext _context = EventLogContext.Create(_databaseOptions, _databaseActions))
         _system = _context.CreateOrUpdateInformationSystem(system);
 }