/// <summary> /// Captures all moderations. /// </summary> public void CaptureModeration() { lock (Container.lockModeratedClientList) { var entries = new List <LogEntry>(); var lastModerated = DateTime.MinValue; lock (Repository.Container.lockDatabase) { if (Repository.Container.Database.Moderate.Any()) { lastModerated = Repository.Container.Database.Moderate.Max(m => m.Creation); } } if (lastModerated == DateTime.MinValue) { LogService.Debug("Start capturing previous Moderation data. This may take some time..."); } uint? index = null; ushort length = 10; try { while (true) { var logEntriesResult = index.HasValue ? QueryRunner.GetLogEntries(length, false, index) : QueryRunner.GetLogEntries(length, false); entries.AddRange(logEntriesResult.LogEntries.Where(m => m.LogLevel == LogLevel.Info && m.LogCategory == "VirtualServer" && m.TimeStamp > lastModerated)); index = logEntriesResult.LogPositionToContinueReading; if (index == 0) { break; } if (!logEntriesResult.LogEntries.Any() || logEntriesResult.LogEntries.Min(l => l.TimeStamp) < lastModerated) { break; } if (entries.Count > 10000) { break; } length = 100; } } catch (ArgumentException) { } foreach (var logEntry in entries) { var entity = ModeratedClientEntity.Parse(logEntry); if (entity.HasValue) { lock (Repository.Container.lockDatabase) { Repository.Container.Database.Moderate.AddObject(new Moderate { Id = Guid.NewGuid(), ClientDatabaseId = (int)entity.Value.User, ModeratorDatabaseId = (int)entity.Value.Moderator, Creation = entity.Value.Moderated, ServerGroup = (int)entity.Value.ServerGroup, Type = (byte)entity.Value.Type }); Repository.Container.Database.SaveChanges(); } } } if (lastModerated == DateTime.MinValue) { LogService.Debug("Finished capturing Moderation data."); } } }
/// <summary> /// Captures all moderations. /// </summary> public void CaptureModeration() { lock (Container.lockModeratedClientList) { var entries = new List <LogEntry>(); var lastModerated = DateTime.MinValue; lock (Repository.Container.lockDatabase) { using (var command = new SQLiteCommand(this.Container.DatabaseConnection)) { command.CommandText = "SELECT MAX(CreationDate) FROM Moderate"; var result = command.ExecuteScalar(); if (result is Int32 && (Int32)result > 0) { lastModerated = ((Int32)result).ToDateTime(); } if (result is Int64 && (Int64)result > 0) { lastModerated = ((Int64)result).ToDateTime(); } } } if (lastModerated == DateTime.MinValue) { LogService.Debug("Start capturing previous Moderation data. This may take some time..."); } uint? index = null; ushort length = 10; try { while (true) { var logEntriesResult = index.HasValue ? QueryRunner.GetLogEntries(length, false, index) : QueryRunner.GetLogEntries(length, false); entries.AddRange(logEntriesResult.LogEntries.Where(m => m.LogLevel == LogLevel.Info && m.LogCategory == "VirtualServer" && m.TimeStamp > lastModerated)); index = logEntriesResult.LogPositionToContinueReading; if (index == 0) { break; } if (!logEntriesResult.LogEntries.Any() || logEntriesResult.LogEntries.Min(l => l.TimeStamp) < lastModerated) { break; } if (entries.Count > 10000) { break; } length = 100; } } catch (ArgumentException) { } foreach (var logEntry in entries) { var entity = ModeratedClientEntity.Parse(logEntry); if (entity.HasValue) { lock (Repository.Container.lockDatabase) { using (var command = new SQLiteCommand(this.Container.DatabaseConnection)) { command.CommandText = string.Format("INSERT INTO Moderate(ClientDatabaseId, ModeratorDatabaseId, ServerGroupId, Type, CreationDate) VALUES({0}, {1}, {2}, {3}, {4})", entity.Value.User, entity.Value.Moderator, entity.Value.ServerGroup, (int)entity.Value.Type, entity.Value.Moderated.ToTimeStamp()); command.ExecuteNonQuery(); } } } } if (lastModerated == DateTime.MinValue) { LogService.Debug("Finished capturing Moderation data."); } } }