public HistoryManager(HistoryManagerData hmd)
        {
            Formatter          = new SmartHistoryFormatter();
            historyManagerData = hmd;

            #region CheckUpgrade
            AudioLogEntry[] moveData = null;

            var upgrader = new Deprecated.HistoryFile();
            // check if the old history database system can open it
            try
            {
                upgrader.OpenFile(historyManagerData.HistoryFile);
                Log.Write(Log.Level.Info, "Found old history database vesion, upgrading now.");

                moveData = upgrader
                           .GetAll()
                           .Select(x => new AudioLogEntry((int)x.Id, x.AudioResource)
                {
                    PlayCount    = x.PlayCount,
                    Timestamp    = x.Timestamp,
                    UserInvokeId = x.UserInvokeId,
                })
                           .ToArray();
                // the old database allowed 0-id, while the new one kinda doesn't
                var nullIdEntity = moveData.FirstOrDefault(x => x.Id == 0);
                if (nullIdEntity != null)
                {
                    nullIdEntity.Id = moveData.Select(x => x.Id).Max() + 1;
                }

                upgrader.CloseFile();
                upgrader.BackupFile();
                upgrader.historyFile.Delete();
            }
            // if not it is already the new one or corrupted
            catch (FormatException) { }
            finally
            {
                upgrader.Dispose();
            }
            #endregion

            Util.Init(ref unusedIds);
            var historyFile = new FileInfo(hmd.HistoryFile);
            database = new LiteDatabase(historyFile.FullName);

            audioLogEntries = database.GetCollection <AudioLogEntry>(AudioLogEntriesTable);
            audioLogEntries.EnsureIndex(x => x.AudioResource.ResourceTitle);
            audioLogEntries.EnsureIndex(x => x.AudioResource.UniqueId, true);

            RestoreFromFile();

            #region CheckUpgrade
            if (moveData != null)
            {
                audioLogEntries.Insert(moveData);
            }
            #endregion
        }
Beispiel #2
0
        public HistoryManager(ConfHistory config, DbStore database)
        {
            Formatter = new SmartHistoryFormatter();

            this.config   = config;
            this.database = database;

            Initialize();
        }
Beispiel #3
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;
            }
        }
Beispiel #4
0
 public HistoryManager(HistoryManagerData hmd)
 {
     Formatter   = new SmartHistoryFormatter();
     historyFile = new HistoryFile();
     historyFile.OpenFile(hmd.historyFile);
 }
Beispiel #5
0
        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;
            }
        }