Exemplo n.º 1
0
        public ServersViewModel()
        {
            _serverList   = new ServerList();
            _launcher     = new Launcher();
            _popupService = new PopupService();
            _storage      = new JSONStorage();
            if (_storage.Exists("config.json"))
            {
                _configuration = _storage.Read <Configuration>("config.json");
            }
            else
            {
                _configuration = new Configuration();
            }

            _servers     = new KeyedCollection <String, ServerObservable>(SynchronizationContext.Current);
            _serversView = new ServersView(_servers);

            _refresh             = new RelayCommand(_ => true, _ => DoRefresh());
            _pingAll             = new RelayCommand(_ => true, _ => DoPingAll());
            _pingSelected        = new RelayCommand(_ => _selectedServer != null, _ => DoPingOne(_selectedServer));
            _joinSelected        = new RelayCommand(_ => _selectedServer != null, _ => DoJoin(_selectedServer));
            _copyAddressSelected = new RelayCommand(_ => _selectedServer != null, _ => CopyAddress(_selectedServer));

            Mapper.CreateMap <Server, ServerObservable>();
            Mapper.CreateMap <ServerSettings, ServerSettingsObservable>();
            Mapper.CreateMap <ServerObservable, ServerObservable>().ForMember(s => s.Latency, opt => opt.Ignore());
            Mapper.AssertConfigurationIsValid();

            DoRefresh();
            DoCheckUpdate();
        }
        public ServersViewModel()
        {
            _serverList = new ServerList();
            _launcher = new Launcher();
            _popupService = new PopupService();
            _storage = new JSONStorage();
            if (_storage.Exists("config.json"))
                _configuration = _storage.Read<Configuration>("config.json");
            else
                _configuration = new Configuration();

            _servers = new KeyedCollection<String, ServerObservable>(SynchronizationContext.Current);
            _serversView = new ServersView(_servers);

            _refresh = new RelayCommand(_ => true, _ => DoRefresh());
            _pingAll = new RelayCommand(_ => true, _ => DoPingAll());
            _pingSelected = new RelayCommand(_ => _selectedServer != null, _ => DoPingOne(_selectedServer));
            _joinSelected = new RelayCommand(_ => _selectedServer != null, _ => DoJoin(_selectedServer));
            _copyAddressSelected = new RelayCommand(_ => _selectedServer != null, _ => CopyAddress(_selectedServer));

            Mapper.CreateMap<Server, ServerObservable>();
            Mapper.CreateMap<ServerSettings, ServerSettingsObservable>();
            Mapper.CreateMap<ServerObservable, ServerObservable>().ForMember(s => s.Latency, opt => opt.Ignore());
            Mapper.AssertConfigurationIsValid();

            DoRefresh();
            DoCheckUpdate();
        }