Exemplo n.º 1
0
        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
        }
Exemplo n.º 2
0
        public HistoryManager(HistoryManagerData hmd)
        {
            Formatter          = new SmartHistoryFormatter();
            historyManagerData = hmd;

            Util.Init(out unusedIds);
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 4
0
 public HistoryManager(HistoryManagerData hmd)
 {
     Formatter   = new SmartHistoryFormatter();
     historyFile = new HistoryFile();
     historyFile.OpenFile(hmd.historyFile);
 }
Exemplo n.º 5
0
 public HistoryManager(HistoryManagerData hmd)
 {
     Formatter = new SmartHistoryFormatter();
     historyFile = new HistoryFile();
     historyFile.OpenFile(hmd.historyFile);
 }