예제 #1
0
        private void Initialize()
        {
            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);
                return;
            }

            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;
            }
        }
예제 #2
0
        public HistoryManager(HistoryManagerData hmd, DbStore database)
        {
            Formatter          = new SmartHistoryFormatter();
            historyManagerData = hmd;

            Util.Init(ref unusedIds);

            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();

            // Content upgrade

            var meta = database.GetMetaData(AudioLogEntriesTable);

            if (meta.Version >= CurrentHistoryVersion)
            {
                return;
            }

            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.Write(Log.Level.Info, "Database table \"{0}\" upgraded to {1}", AudioLogEntriesTable, meta.Version);
                break;
            }
        }
예제 #3
0
 private void UpdateMeta()
 {
     meta.CustomData = JsonConvert.SerializeObject(statsPoints, JsonSettings);
     database.UpdateMetaData(meta);
 }