Exemplo 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);
            }
        }
Exemplo n.º 2
0
        public async Task Save()
        {
            try
            {
                var customStore = _settingsStoreSource.GetCustomSettingsStore();

                foreach (var serverSetting in ServerSettings)
                {
                    customStore.Save(serverSetting.ServerId.ToString(), new ServerSettings()
                    {
                        ServerId        = serverSetting.ServerId,
                        IdleTimeInMins  = serverSetting.IdleTimeInMins,
                        IdleKickReason  = serverSetting.IdleKickReason,
                        KickIdlePlayers = serverSetting.KickIdlePlayers
                    });
                }

                var settings = _settingsStoreSource.GetSettingsStore();
                settings.TimeZoneInfo = Settings.TimeZoneInfo;

                settings.AdminName = Settings.AdminName.Replace(" ", string.Empty);

                settings.BanMessageTemplate  = Settings.BanMessageTemplate;
                settings.KickMessageTemplate = Settings.KickMessageTemplate;


                settings.BansUpdateSeconds    = Settings.BansUpdateSeconds;
                settings.PlayersUpdateSeconds = Settings.PlayersUpdateSeconds;

                settings.TopMost = Settings.TopMost;

                settings.Save();


                var all = await _infoRepository.GetServerInfoAsync();

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

                foreach (var serverInfo in todelete)
                {
                    await _infoRepository.RemoveAsync(serverInfo.Id);
                }

                foreach (var s in Servers)
                {
                    var m = s.GetDbModel();
                    if (m.Id == Guid.Empty)
                    {
                        m.Id = Guid.NewGuid();
                    }
                    await _infoRepository.AddOrUpdateAsync(m);
                }


                using (var dc = new ReasonRepository())
                {
                    await dc.UpdateBanReasons(BanReasons.Select(x => x.Text).Where(x => string.IsNullOrEmpty(x) == false).Distinct().ToArray());

                    await dc.UpdateBanTimes(BanTimes.Where(x => string.IsNullOrEmpty(x.Text) == false).Select(x => new BanTime {
                        TimeInMinutes = x.Minutes, Title = x.Text
                    }).ToArray());

                    await dc.UpdateKickReasons(KickReasons.Select(x => x.Text).Where(x => string.IsNullOrEmpty(x) == false).Distinct().ToArray());


                    await dc.UpdateBadNicknames(BadNicknames.Select(x => x.Text).Where(x => string.IsNullOrEmpty(x) == false).Distinct().ToArray());

                    await dc.UpdateImportantWords(ImportantWords.Select(x => x.Text).Where(x => string.IsNullOrEmpty(x) == false).Distinct().ToArray());
                }

                _eventAggregator.GetEvent <BEServersChangedEvent>().Publish(null);
                _eventAggregator.GetEvent <SettingsChangedEvent>().Publish(_settingsStoreSource.GetSettingsStore());


                foreach (Window wnd in Application.Current.Windows)
                {
                    wnd.Topmost = settings.TopMost;
                }
            }
            catch (Exception e)
            {
                _log.Error(e);
                MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }