Esempio n. 1
0
        private Task LoadCache()
        {
            foreach (var guild in _discord.Guilds)
            {
                var serverDataManager = ServerDataManager.AddServer(guild.Id);
                var database          = new MongoDBHandler(guild.Id.ToString());

                var userDataList = database.GetAllDocumentsFromTable <UserDataModel>("UserData");
                foreach (var userData in userDataList)
                {
                    serverDataManager.SetUserData(Convert.ToUInt64(userData.UserId), userData);
                }

                var shopRoles = database.GetAllDocumentsFromTable <ShopRoleModel>("ShopRoles");
                foreach (var shopRole in shopRoles)
                {
                    serverDataManager.AddShopRole(shopRole.GetRoleId(), shopRole);
                }

                var serverSettings = database.GetAllDocumentsFromTable <ServerSettingsModel>("ServerSettings");
                foreach (var serverSetting in serverSettings)
                {
                    serverDataManager.AddServerSettings(serverSetting.Id, serverSetting);
                }
            }
            return(Task.CompletedTask);
        }
Esempio n. 2
0
        public static ServerDataManager AddServer(ulong serverId)
        {
            var serverData = new ServerDataManager(serverId);

            ServerDataManagers.Add(serverId, serverData);
            return(ServerDataManagers[serverId]);
        }
Esempio n. 3
0
        private async Task UpdateDataBaseWithCache()
        {
            foreach (var cache in ServerDataManager.GetAllServerData())
            {
                var mongoDbHandler = new MongoDBHandler(cache.Key.ToString());

                //todo: find a way to use replaceMany for generics to reduce foreach loops and load times
                foreach (var userData in cache.Value.GetUserDataModel())
                {
                    await mongoDbHandler.Upsert("UserData", Convert.ToInt64(userData.Key), userData.Value);
                }

                foreach (var shopRole in cache.Value.GetShopRoleModel())
                {
                    await mongoDbHandler.Upsert("ShopRoles", Convert.ToInt64(shopRole.Key), shopRole.Value);
                }

                foreach (var serverSettings in cache.Value.GetServerSettingsModel())
                {
                    await mongoDbHandler.Upsert("ServerSettings", serverSettings.Key, serverSettings.Value);
                }
            }
        }