예제 #1
0
        private void ReadAndUpgradeStats()
        {
            meta         = database.GetMetaData(StatsTable);
            trackEntries = database.GetCollection <StatsData>(StatsTable);
            trackEntries.EnsureIndex(x => x.Time);

            if (meta.Version != StatsVersion)
            {
                statsPoints = new StatsMeta
                {
                    LastSend = Tools.Now,
                };
                meta.Version = StatsVersion;
                UpdateMeta();
            }
            else
            {
                statsPoints = JsonConvert.DeserializeObject <StatsMeta>(meta.CustomData, JsonSettings);
                // Upgrade steps here
            }

            overallStats = trackEntries.FindById(0);
            if (overallStats is null)
            {
                overallStats = new StatsData
                {
                    Id = 0
                };
            }
        }
예제 #2
0
        public TokenManager(DbStore database)
        {
            dbTokenList = database.GetCollection <DbApiToken>(ApiTokenTable);
            dbTokenList.EnsureIndex(x => x.UserUid, true);
            dbTokenList.EnsureIndex(x => x.Token, true);

            database.GetMetaData(ApiTokenTable);
        }
예제 #3
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;
            }
        }
예제 #4
0
        public SessionManager(DbStore database)
        {
            Util.Init(ref openSessions);
            Util.Init(ref liveTokenList);

            dbTokenList = database.GetCollection <DbApiToken>(ApiTokenTable);
            dbTokenList.EnsureIndex(x => x.UserUid, true);
            dbTokenList.EnsureIndex(x => x.Token, true);

            database.GetMetaData(ApiTokenTable);
        }
예제 #5
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;
            }
        }
예제 #6
0
파일: Stats.cs 프로젝트: yakMM/TS3AudioBot
        public Stats(ConfRoot conf, DbStore database, BotManager botManager, DedicatedTaskScheduler scheduler)
        {
            this.conf          = conf;
            this.database      = database;
            this.botManager    = botManager;
            uploadParamEnabled = true;
            runtimeLastTrack   = Tools.Now;
            ticker             = scheduler.CreateTimer(TrackPoint, CheckInterval, false);

            meta         = database.GetMetaData(StatsTable);
            trackEntries = database.GetCollection <StatsData>(StatsTable);
            trackEntries.EnsureIndex(x => x.Id, true);
            trackEntries.EnsureIndex(x => x.Time);
            accEntries = database.GetCollection <StatsData>(StatsTableAcc);
            accEntries.EnsureIndex(x => x.Id, true);

            if (meta.Version != StatsVersion || meta.CustomData is null)
            {
                statsPoints = new StatsMeta
                {
                    LastSend = Tools.Now,
                };
                meta.Version = StatsVersion;
                UpdateMeta();
            }
            else
            {
                statsPoints = JsonConvert.DeserializeObject <StatsMeta>(meta.CustomData, JsonSettings) ?? new StatsMeta();
                // Upgrade steps here
            }

            overallStats = accEntries.FindById(OverallId) ?? new StatsData
            {
                Id = OverallId
            };
        }