public HistoryManager(ConfHistory config) { Formatter = new SmartHistoryFormatter(); Util.Init(out unusedIds); this.config = config; }
public HistoryManager(ConfHistory config, DbStore database) { Formatter = new SmartHistoryFormatter(); this.config = config; this.database = database; Initialize(); }
public HistoryManager(ConfHistory config, DbStore database) { Formatter = new SmartHistoryFormatter(); this.config = config; var meta = database.GetMetaData(AudioLogEntriesTable); if (meta.Version > CurrentHistoryVersion) { Log.Error("Database table \"{0}\" is higher than the current version. (table:{1}, app:{2}). " + "Please download the latest TS3AudioBot to read the history.", AudioLogEntriesTable, meta.Version, CurrentHistoryVersion); throw new NotSupportedException(); } audioLogEntries = database.GetCollection <AudioLogEntry>(AudioLogEntriesTable); audioLogEntries.EnsureIndex(x => x.AudioResource.UniqueId, true); audioLogEntries.EnsureIndex(x => x.Timestamp); audioLogEntries.EnsureIndex(ResourceTitleQueryColumn, $"LOWER($.{nameof(AudioLogEntry.AudioResource)}.{nameof(AudioResource.ResourceTitle)})"); RestoreFromFile(); if (meta.Version == CurrentHistoryVersion) { return; } if (audioLogEntries.Count() == 0) { meta.Version = CurrentHistoryVersion; database.UpdateMetaData(meta); return; } // Content upgrade switch (meta.Version) { case 0: var all = audioLogEntries.FindAll().ToArray(); foreach (var audioLogEntry in all) { switch (audioLogEntry.AudioResource.AudioType) { case "MediaLink": audioLogEntry.AudioResource.AudioType = "media"; break; case "Youtube": audioLogEntry.AudioResource.AudioType = "youtube"; break; case "Soundcloud": audioLogEntry.AudioResource.AudioType = "soundcloud"; break; case "Twitch": audioLogEntry.AudioResource.AudioType = "twitch"; break; } } audioLogEntries.Update(all); meta.Version = 1; database.UpdateMetaData(meta); goto default; default: Log.Info("Database table \"{0}\" upgraded to {1}", AudioLogEntriesTable, meta.Version); break; } }