public void AddServer()
        {
            if (string.IsNullOrWhiteSpace(ServerIpText) || string.IsNullOrWhiteSpace(ServerQueryPortText))
            {
                return;
            }

            if (Servers.All(item => item.ServerIp != ServerIpText))
            {
                Servers.Add(new ServersModel()
                {
                    ContentButton       = "Join Server",
                    IsJoinButtonEnabled = false,

                    ServerInfo        = "Loading...",
                    ServerInfoToolTip = $@"Server Address: {ServerIpText}
Server Query Port: {ServerQueryPortText}",

                    ServerIp        = ServerIpText,
                    ServerQueryPort = ServerQueryPortText
                });
            }
            else
            {
                MessageBox.Show($"The \"{ServerIpText}\" server address is already in the list!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 2
0
        private DeleteDatabaseResult DeleteDatabase(Options options, RavenServer serverToUse, string name, bool hardDelete, DocumentStore store)
        {
            try
            {
                if (options.AdminCertificate != null)
                {
                    using (var adminStore =
                               new DocumentStore {
                        Urls = UseFiddler(serverToUse.WebUrl), Database = name, Certificate = options.AdminCertificate
                    }.Initialize())
                    {
                        return(adminStore.Maintenance.Server.Send(new DeleteDatabasesOperation(name, hardDelete)));
                    }
                }

                return(store.Maintenance.Server.Send(new DeleteDatabasesOperation(name, hardDelete)));
            }
            catch (OperationCanceledException)
            {
                //failed to delete in time
            }
            catch (TimeoutException)
            {
                //failed to delete in time
            }
            catch (DatabaseDoesNotExistException)
            {
            }
            catch (NoLeaderException)
            {
            }
            catch (AllTopologyNodesDownException)
            {
            }
            catch (Exception e)
            {
                if (e is RavenException && (e.InnerException is TimeoutException || e.InnerException is OperationCanceledException))
                {
                    return(null);
                }

                if (Servers.Contains(serverToUse))
                {
                    if (Servers.All(s => s.Disposed))
                    {
                        return(null);
                    }
                }

                if (serverToUse.Disposed)
                {
                    return(null);
                }

                throw;
            }
            return(null);
        }
Exemplo n.º 3
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.º 4
0
        public PopularServer[] GetPopularServers(int count)
        {
            var lastMatchTimestamp = Matches.GetLastMatchTimestampAmongAllServers();

            var popularServers =
                Servers.All()
                .Select(server => new PopularServer(server, lastMatchTimestamp))
                .OrderByDescending(server => server.AverageMatchesPerDay)
                .Take(count)
                .ToArray();

            return(popularServers);
        }
        public void AddTs()
        {
            if (string.IsNullOrWhiteSpace(ServerIpText) || string.IsNullOrWhiteSpace(TsSelectorUrlText))
            {
                return;
            }

            var tsItem = Servers.FirstOrDefault(i => i.ServerIp == ServerIpText);

            if (tsItem != null)
            {
                MessageBox.Show("There can be only one instance of the same TS server!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (Servers.All(item => item.ServerIp != ServerIpText))
            {
                Servers.Add(new ServersModel()
                {
                    ContentButton       = "Join TeamSpeak",
                    IsJoinButtonEnabled = false,
                    JoinServerToolTip   = $@"Join: {_tsViewModel.TsChannelNameText}
Password: {_tsViewModel.TsChannelPasswordText}",

                    ServerInfo        = "Loading...",
                    ServerInfoToolTip = $@"Server Address: {ServerIpText}
TeamSpeak Selector: {TsSelectorText}
TeamSpeak Selector URL: {TsSelectorUrlText}",

                    ServerIp      = ServerIpText,
                    TsSelector    = TsSelectorText,
                    TsSelectorUrl = TsSelectorUrlText
                });
            }
            else
            {
                MessageBox.Show("The same instance of the TS server is already in the list!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 6
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);
            }
        }