Пример #1
0
        public MainWindowViewModel(ConfigurationManager cfg, ServerStatusCache statusCache, Updater updater)
        {
            _cfg     = cfg;
            _updater = updater;

            var servers = new ServerListTabViewModel(cfg, statusCache, updater);
            var news    = new NewsTabViewModel();
            var options = new OptionsTabViewModel(cfg);
            var home    = new HomePageViewModel(cfg, statusCache, updater);

            Tabs = new MainWindowTabViewModel[]
            {
                home,
                servers,
                news,
                options
            };

            this.WhenAnyValue(x => x.SelectedIndex).Subscribe(i => Tabs[i].Selected());

            this.WhenAnyValue(x => x._cfg.UserName)
            .Subscribe(_ =>
            {
                this.RaisePropertyChanged(nameof(Username));
                this.RaisePropertyChanged(nameof(LoggedIn));
                this.RaisePropertyChanged(nameof(LoginText));
                this.RaisePropertyChanged(nameof(ManageAccountText));
            });

            AccountDropDown = new AccountDropDownViewModel(cfg);
            LoginViewModel  = new MainWindowLoginViewModel(cfg);
        }
        public ServerEntryViewModel(ServerStatusCache cache, ConfigurationManager cfg, Updater updater, string address)
        {
            _cache     = cache;
            _cacheData = cache.GetStatusFor(address);
            _cfg       = cfg;
            _updater   = updater;

            this.WhenAnyValue(x => x.IsAltBackground)
            .Subscribe(_ => this.RaisePropertyChanged(nameof(BackgroundColor)));

            this.WhenAnyValue(x => x._cacheData.PlayerCount)
            .Subscribe(_ => this.RaisePropertyChanged(nameof(ServerStatusString)));

            this.WhenAnyValue(x => x._cacheData.Status)
            .Subscribe(_ =>
            {
                this.RaisePropertyChanged(nameof(IsOnline));
                this.RaisePropertyChanged(nameof(ServerStatusString));
            });

            this.WhenAnyValue(x => x._cacheData.Name)
            .Subscribe(_ => this.RaisePropertyChanged(nameof(Name)));

            this.WhenAnyValue(x => x._cacheData.Ping)
            .Subscribe(_ => this.RaisePropertyChanged(nameof(PingText)));

            _cfg.FavoriteServers.Connect()
            .Subscribe(_ => { this.RaisePropertyChanged(nameof(FavoriteButtonText)); });
        }
Пример #3
0
        public ServerListTabViewModel(DataManager cfg, ServerStatusCache statusCache, Updater updater,
                                      LoginManager loginMgr)
        {
            _cfg         = cfg;
            _statusCache = statusCache;
            _updater     = updater;
            _loginMgr    = loginMgr;

            AllServers.CollectionChanged += (s, e) =>
            {
                foreach (var server in AllServers)
                {
                    server.DoInitialUpdate();
                }

                RepopulateServerList();
            };

            this.WhenAnyValue(x => x.SearchString)
            .Subscribe(_ => RepopulateServerList());

            this.WhenAnyValue(x => x.Status)
            .Subscribe(_ =>
            {
                this.RaisePropertyChanged(nameof(ListEmptyText));
                this.RaisePropertyChanged(nameof(ListVisible));
            });

            SearchedServers.CollectionChanged += (s, e) =>
            {
                this.RaisePropertyChanged(nameof(ListEmptyText));
                this.RaisePropertyChanged(nameof(ListVisible));
            };
        }
Пример #4
0
        public ServerEntryViewModel(MainWindowViewModel windowVm, string address)
        {
            _cache     = Locator.Current.GetService <ServerStatusCache>();
            _cfg       = Locator.Current.GetService <DataManager>();
            _windowVm  = windowVm;
            _cacheData = _cache.GetStatusFor(address);

            this.WhenAnyValue(x => x.IsAltBackground)
            .Subscribe(_ => this.RaisePropertyChanged(nameof(BackgroundColor)));

            this.WhenAnyValue(x => x._cacheData.PlayerCount)
            .Subscribe(_ => this.RaisePropertyChanged(nameof(ServerStatusString)));

            this.WhenAnyValue(x => x._cacheData.Status)
            .Subscribe(_ =>
            {
                this.RaisePropertyChanged(nameof(IsOnline));
                this.RaisePropertyChanged(nameof(ServerStatusString));
            });

            this.WhenAnyValue(x => x._cacheData.Name)
            .Subscribe(_ => this.RaisePropertyChanged(nameof(Name)));

            this.WhenAnyValue(x => x._cacheData.Ping)
            .Subscribe(_ => this.RaisePropertyChanged(nameof(PingText)));

            _cfg.FavoriteServers.Connect()
            .Subscribe(_ => { this.RaisePropertyChanged(nameof(FavoriteButtonText)); });
        }
        public ServerListTabViewModel(MainWindowViewModel windowVm)
        {
            _windowVm    = windowVm;
            _statusCache = Locator.Current.GetService <ServerStatusCache>();
            _http        = Locator.Current.GetService <HttpClient>();

            AllServers.CollectionChanged += (s, e) =>
            {
                foreach (var server in AllServers)
                {
                    server.DoInitialUpdate();
                }

                RepopulateServerList();
            };

            this.WhenAnyValue(x => x.SearchString)
            .Subscribe(_ => RepopulateServerList());

            this.WhenAnyValue(x => x.Status)
            .Subscribe(_ =>
            {
                this.RaisePropertyChanged(nameof(ListEmptyText));
                this.RaisePropertyChanged(nameof(ListVisible));
            });

            SearchedServers.CollectionChanged += (s, e) =>
            {
                this.RaisePropertyChanged(nameof(ListEmptyText));
                this.RaisePropertyChanged(nameof(ListVisible));
            };
        }
Пример #6
0
        public HomePageViewModel(ConfigurationManager cfg, ServerStatusCache statusCache, Updater updater)
        {
            _cfg         = cfg;
            _statusCache = statusCache;
            _updater     = updater;

            _cfg.FavoriteServers
            .Connect()
            .Subscribe(_ => UpdateFavoritesList());
        }
Пример #7
0
        public HomePageViewModel(MainWindowViewModel mainWindowViewModel)
        {
            MainWindowViewModel = mainWindowViewModel;
            _cfg         = Locator.Current.GetService <DataManager>();
            _statusCache = Locator.Current.GetService <ServerStatusCache>();

            _cfg.FavoriteServers
            .Connect()
            .Subscribe(_ => UpdateFavoritesList());
        }
Пример #8
0
        public HomePageViewModel(MainWindowViewModel mainWindowViewModel, DataManager cfg,
                                 ServerStatusCache statusCache, Updater updater, LoginManager loginMgr)
        {
            MainWindowViewModel = mainWindowViewModel;
            _cfg         = cfg;
            _statusCache = statusCache;
            _updater     = updater;
            _loginMgr    = loginMgr;

            _cfg.FavoriteServers
            .Connect()
            .Subscribe(_ => UpdateFavoritesList());
        }
Пример #9
0
        // Your application's entry point. Here you can initialize your MVVM framework, DI
        // container, etc.
        private static void AppMain(Application app, string[] args)
        {
            var cfg = new DataManager();

            cfg.Load();
            var statusCache = new ServerStatusCache();
            var updater     = new Updater(cfg);

            var viewModel = new MainWindowViewModel(cfg, statusCache, updater);
            var window    = new MainWindow
            {
                DataContext = viewModel
            };

            viewModel.OnWindowInitialized();

            app.Run(window);
        }
Пример #10
0
        public MainWindowViewModel(DataManager cfg, ServerStatusCache statusCache, Updater updater)
        {
            _cfg = cfg;
            var authApi = new AuthApi(cfg);

            _loginMgr = new LoginManager(cfg, authApi);

            ServersTab = new ServerListTabViewModel(cfg, statusCache, updater, _loginMgr);
            NewsTab    = new NewsTabViewModel();
            HomeTab    = new HomePageViewModel(this, cfg, statusCache, updater, _loginMgr);
            OptionsTab = new OptionsTabViewModel(cfg);

            Tabs = new MainWindowTabViewModel[]
            {
                HomeTab,
                ServersTab,
                NewsTab,
                OptionsTab
            };

            AccountDropDown = new AccountDropDownViewModel(this, cfg, authApi, _loginMgr);
            LoginViewModel  = new MainWindowLoginViewModel(cfg, authApi, _loginMgr);

            this.WhenAnyValue(x => x.SelectedIndex).Subscribe(i => Tabs[i].Selected());

            this.WhenAnyValue(x => x._loginMgr.ActiveAccount)
            .Subscribe(s =>
            {
                this.RaisePropertyChanged(nameof(Username));
                this.RaisePropertyChanged(nameof(LoggedIn));
                this.RaisePropertyChanged(nameof(LoginText));
                this.RaisePropertyChanged(nameof(ManageAccountText));
            });

            _cfg.Logins.Connect()
            .Subscribe(_ => { this.RaisePropertyChanged(nameof(AccountDropDownVisible)); });

            // If we leave the login view model (by an account getting selected)
            // we reset it to login state
            this.WhenAnyValue(x => x.LoggedIn)
            .DistinctUntilChanged()     // Only when change.
            .Where(p => !p)
            .Subscribe(x => LoginViewModel.SwitchToLogin());
        }
Пример #11
0
 public ServerEntryViewModel(ServerStatusCache cache, ConfigurationManager cfg, Updater updater,
                             FavoriteServer favorite)
     : this(cache, cfg, updater, favorite.Address)
 {
     Favorite = favorite;
 }
Пример #12
0
 public ServerEntryViewModel(ServerStatusCache cache, DataManager cfg, Updater updater, LoginManager loginMgr,
                             FavoriteServer favorite)
     : this(cache, cfg, updater, loginMgr, favorite.Address)
 {
     Favorite = favorite;
 }