private void ResetCache()
        {
            if (_validCache)
            {
                return;
            }
            lock (Lock)
            {
                if (_validCache)
                {
                    return;
                }
                _log.Info("Refresh ServerInfo cache.");
                var playersByGuidsCache = new ConcurrentDictionary <Guid, ServerInfoDto>();
                var players             = _infoRepository.GetServerInfoAsync().Result;

                foreach (var playerDto in players)
                {
                    playersByGuidsCache.AddOrUpdate(playerDto.Id, playerDto, (key, value) => value);
                }

                _cache      = playersByGuidsCache;
                _validCache = true;
            }
        }
Esempio n. 2
0
        private async void Init()
        {
            Servers = (await _infoRepository.GetServerInfoAsync()).Select(x => new ServerInfoModel(x)).ToList();


            using (var dc = new ReasonRepository())
            {
                BanReasons = (await dc.GetBanReasonsAsync()).Select(x => new ReasonEdit {
                    Text = x
                }).ToList();
                KickReasons = (await dc.GetKickReasonsAsync()).Select(x => new ReasonEdit {
                    Text = x
                }).ToList();
                BanTimes =
                    (await dc.GetBanTimesAsync()).Select(x => new BanTimeEdit {
                    Text = x.Title, Minutes = x.TimeInMinutes
                }).ToList();

                BadNicknames = (await dc.GetBadNicknamesAsync()).Select(x => new ReasonEdit {
                    Text = x
                }).ToList();
                ImportantWords = (await dc.GetImportantWordsAsync()).Select(x => new ReasonEdit {
                    Text = x
                }).ToList();
            }

            var zones = TimeZoneInfo.GetSystemTimeZones().ToArray();

            for (var i = 0; i < zones.Length; i++)
            {
                if (zones[i].Id == Settings.TimeZoneInfo?.Id)
                {
                    zones[i] = Settings.TimeZoneInfo;
                }
            }

            TimeZones = zones;

            RaisePropertyChanged(nameof(Servers));
            RaisePropertyChanged(nameof(BanReasons));
            RaisePropertyChanged(nameof(KickReasons));
            RaisePropertyChanged(nameof(BanTimes));
            RaisePropertyChanged(nameof(BadNicknames));
            RaisePropertyChanged(nameof(ImportantWords));
            RaisePropertyChanged(nameof(TimeZones));
        }
        public async Task Init(Guid serverId)
        {
            ServerList      = (await _repository.GetServerInfoAsync()).OrderBy(x => x.Name).ToList();
            SelectedServers = serverId.ToString();

            RaisePropertyChanged(nameof(ServerList));
            RaisePropertyChanged(nameof(SelectedServers));
        }
Esempio n. 4
0
        private async void Init()
        {
            var dbServers = (await _infoRepository.GetServerInfoAsync()).ToArray();

            Servers = dbServers.Select(x => new ServerInfoModel(x)).ToList();


            using (var dc = new ReasonRepository())
            {
                BanReasons = (await dc.GetBanReasonsAsync()).Select(x => new ReasonEdit {
                    Text = x
                }).ToList();
                KickReasons = (await dc.GetKickReasonsAsync()).Select(x => new ReasonEdit {
                    Text = x
                }).ToList();
                BanTimes =
                    (await dc.GetBanTimesAsync()).Select(x => new BanTimeEdit {
                    Text = x.Title, Minutes = x.TimeInMinutes
                }).ToList();

                BadNicknames = (await dc.GetBadNicknamesAsync()).Select(x => new ReasonEdit {
                    Text = x
                }).ToList();
                ImportantWords = (await dc.GetImportantWordsAsync()).Select(x => new ReasonEdit {
                    Text = x
                }).ToList();
            }

            var zones = TimeZoneInfo.GetSystemTimeZones().ToArray();

            for (var i = 0; i < zones.Length; i++)
            {
                if (zones[i].Id == Settings.TimeZoneInfo?.Id)
                {
                    zones[i] = Settings.TimeZoneInfo;
                }
            }

            TimeZones = zones;

            var customStore = _settingsStoreSource.GetCustomSettingsStore();

            ServerSettings = dbServers.Select(x => new
            {
                ServerSettings =
                    customStore.Load <ServerSettings>(x.Id.ToString()) ?? new ServerSettings()
                {
                    IdleTimeInMins  = 0,
                    KickIdlePlayers = false,
                    IdleKickReason  = "Lobby Idle",
                    ServerId        = x.Id
                },
                ServerName = x.Name
            })
                             .Select(x => new ServerSettingsVM()
            {
                ServerId        = x.ServerSettings.ServerId,
                IdleTimeInMins  = x.ServerSettings.IdleTimeInMins,
                ServerName      = x.ServerName,
                IdleKickReason  = x.ServerSettings.IdleKickReason,
                KickIdlePlayers = x.ServerSettings.KickIdlePlayers
            })
                             .ToList();


            RaisePropertyChanged(nameof(Servers));
            RaisePropertyChanged(nameof(BanReasons));
            RaisePropertyChanged(nameof(KickReasons));
            RaisePropertyChanged(nameof(BanTimes));
            RaisePropertyChanged(nameof(BadNicknames));
            RaisePropertyChanged(nameof(ImportantWords));
            RaisePropertyChanged(nameof(TimeZones));
            RaisePropertyChanged(nameof(ServerSettings));
        }