Ejemplo n.º 1
0
        public void Save()
        {
            try
            {
                var settings = _settingsStoreSource.GetSettingsStore();
                settings.TimeZoneInfo         = Settings.TimeZoneInfo;
                settings.AdminName            = Settings.AdminName.Replace(" ", string.Empty);
                settings.BansUpdateSeconds    = Settings.BansUpdateSeconds;
                settings.PlayersUpdateSeconds = Settings.PlayersUpdateSeconds;
                settings.Save();

                using (var servierInfoRepository = new ServerInfoRepository())
                {
                    var all = servierInfoRepository.GetServerInfo();

                    var todelete = all.Where(x => Servers.All(s => s.GetDbModel().Id != x.Id));

                    foreach (var serverInfo in todelete)
                    {
                        servierInfoRepository.Remove(serverInfo.Id);
                    }

                    foreach (var s in Servers)
                    {
                        var m = s.GetDbModel();
                        if (m.Id == Guid.Empty)
                        {
                            m.Id = Guid.NewGuid();
                        }
                        servierInfoRepository.AddOrUpdate(m);
                    }
                }

                using (var dc = new ReasonRepository())
                {
                    dc.UpdateBanReasons(BanReasons.Select(x => x.Text).Where(x => string.IsNullOrEmpty(x) == false).Distinct().ToArray());
                    dc.UpdateBanTimes(BanTimes.Where(x => string.IsNullOrEmpty(x.Text) == false).Select(x => new BanTime()
                    {
                        TimeInMinutes = x.Minutes, Title = x.Text
                    }).ToArray());
                    dc.UpdateKickReasons(KickReasons.Select(x => x.Text).Where(x => string.IsNullOrEmpty(x) == false).Distinct().ToArray());
                }

                _eventAggregator.GetEvent <BEServersChangedEvent>().Publish(null);
                _eventAggregator.GetEvent <SettingsChangedEvent>().Publish(_settingsStoreSource.GetSettingsStore());
            }
            catch (Exception e)
            {
                _log.Error(e);
                MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 2
0
        public OptionsModel(IEventAggregator eventAggregator, ISettingsStoreSource settingsStoreSource)
        {
            _eventAggregator     = eventAggregator;
            _settingsStoreSource = settingsStoreSource;
            using (var servierInfoRepository = new ServerInfoRepository())
            {
                Servers = servierInfoRepository.GetServerInfo().Select(x => new ServerInfoModel(x)).ToList();
            }

            using (var dc = new ReasonRepository())
            {
                BanReasons = dc.GetBanReasons().Select(x => new ReasonEdit()
                {
                    Text = x
                }).ToList();
                KickReasons = dc.GetKickReasons().Select(x => new ReasonEdit()
                {
                    Text = x
                }).ToList();
                BanTimes =
                    dc.GetBanTimes().Select(x => new BanTimeEdit()
                {
                    Text = x.Title, Minutes = x.TimeInMinutes
                }).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;
        }