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 }; } }
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 }; }