private static void FillReferencesToSave <T>(EventLogContext context, InformationSystemsBase system, IReadOnlyList <T> sourceReferences) where T : ReferenceObject { if (sourceReferences == null) { return; } foreach (var itemReference in sourceReferences) { if (!context.ReferenceExistInDB(system, itemReference)) { context.AddReferenceToSaveInDB(itemReference); } } }
public static DateTime GetRowsDataMaxPeriod(this EventLogContext context, InformationSystemsBase system) { DateTime maxPeriodRowData = DateTime.MinValue; RowData firstRow = context.RowsData.FirstOrDefault(); if (firstRow != null) { var _maxPeriodData = context.RowsData .Where(p => p.InformationSystemId == system.Id); if (_maxPeriodData.Any()) { DateTimeOffset _maxPeriodRowDataTimeOffset = _maxPeriodData.Max(m => m.Period); maxPeriodRowData = _maxPeriodRowDataTimeOffset.DateTime; } } return(maxPeriodRowData); }
public static EventLogPosition GetLastPosition(this EventLogContext context, InformationSystemsBase system) { var lastLogFile = context.LogFiles .SingleOrDefault(e => e.InformationSystemId == system.Id && e.Id == context.LogFiles.Where(i => i.InformationSystemId == system.Id).Max(m => m.Id)); if (lastLogFile == null) { return(null); } else { return(new EventLogPosition( lastLogFile.LastEventNumber, lastLogFile.LastCurrentFileReferences, lastLogFile.LastCurrentFileData, lastLogFile.LastStreamPosition)); } }
public static void SaveLogPosition(this EventLogContext context, InformationSystemsBase system, FileInfo logFileInfo, EventLogPosition position) { LogFiles foundLogFile = context.LogFiles .FirstOrDefault(l => l.InformationSystemId == system.Id && l.FileName == logFileInfo.Name && l.CreateDate == logFileInfo.CreationTimeUtc); if (foundLogFile == null) { context.LogFiles.Add(new LogFiles(system, logFileInfo, position)); } else { foundLogFile.ModificationDate = logFileInfo.LastWriteTimeUtc; foundLogFile.LastCurrentFileData = position.CurrentFileData; foundLogFile.LastCurrentFileReferences = position.CurrentFileReferences; foundLogFile.LastEventNumber = position.EventNumber; foundLogFile.LastStreamPosition = position.StreamPosition; context.Entry(foundLogFile).State = EntityState.Modified; } context.SaveChanges(); }
public void FillByDatabaseContext(EventLogContext context) { Applications = context.Applications.Where(e => e.InformationSystemId == _system.Id).ToList().AsReadOnly(); Computers = context.Computers.Where(e => e.InformationSystemId == _system.Id).ToList().AsReadOnly(); Events = context.Events.Where(e => e.InformationSystemId == _system.Id).ToList().AsReadOnly(); Metadata = context.Metadata.Where(e => e.InformationSystemId == _system.Id).ToList().AsReadOnly(); PrimaryPorts = context.PrimaryPorts.Where(e => e.InformationSystemId == _system.Id).ToList().AsReadOnly(); SecondaryPorts = context.SecondaryPorts.Where(e => e.InformationSystemId == _system.Id).ToList().AsReadOnly(); Severities = context.Severities.Where(e => e.InformationSystemId == _system.Id).ToList().AsReadOnly(); TransactionStatuses = context.TransactionStatuses.Where(e => e.InformationSystemId == _system.Id).ToList().AsReadOnly(); Users = context.Users.Where(e => e.InformationSystemId == _system.Id).ToList().AsReadOnly(); WorkServers = context.WorkServers.Where(e => e.InformationSystemId == _system.Id).ToList().AsReadOnly(); ApplicationsDictionary = Applications.GroupBy(e => e.Name).ToDictionary(e => e.Key, e => e.ToList()); ComputersDictionary = Computers.GroupBy(e => e.Name).ToDictionary(e => e.Key, e => e.ToList()); EventsDictionary = Events.GroupBy(e => e.Name).ToDictionary(e => e.Key, e => e.ToList()); MetadataDictionary = Metadata.GroupBy(e => e.Name).ToDictionary(e => e.Key, e => e.ToList()); PrimaryPortsDictionary = PrimaryPorts.GroupBy(e => e.Name).ToDictionary(e => e.Key, e => e.ToList()); SecondaryPortsDictionary = SecondaryPorts.GroupBy(e => e.Name).ToDictionary(e => e.Key, e => e.ToList()); SeveritiesDictionary = Severities.GroupBy(e => e.Name).ToDictionary(e => e.Key, e => e.ToList()); TransactionStatusesDictionary = TransactionStatuses.GroupBy(e => e.Name).ToDictionary(e => e.Key, e => e.ToList()); UsersDictionary = Users.GroupBy(e => e.Name).ToDictionary(e => e.Key, e => e.ToList()); WorkServersDictionary = WorkServers.GroupBy(e => e.Name).ToDictionary(e => e.Key, e => e.ToList()); }
public static void AddReferenceToSaveInDB <T>(this EventLogContext context, T item) where T : ReferenceObject { context.Set <T>().Add(item); }