Ejemplo n.º 1
0
        public StartBootstrapper()
        {
            _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            _settings = (Settings)_config.Sections["settings"];
            Locator.CurrentMutable.RegisterConstant(_settings, typeof(Settings));

            _customObservable2 = new CustomObservable2();
            var schedulerProvider = new SchedulerProvider();
            if (_settings.IsFakeService)
            {
                _client = new FakeServiceClientHelper();
            }
            else
            {
                _client = new MainServiceClientHelper(_settings.ServiceUrl);
            }
            _trayIconManager = new TrayIconManager();
            _trayIconManager.Init();

            Locator.CurrentMutable.RegisterConstant(_customObservable2, typeof(ICustomObservable2));
            Locator.CurrentMutable.RegisterConstant(schedulerProvider, typeof(ISchedulerProvider));
            Locator.CurrentMutable.RegisterConstant(_config, typeof(Configuration));
            Locator.CurrentMutable.RegisterConstant(_client, typeof(IMainServiceClientHelper));
            Locator.CurrentMutable.RegisterConstant(_trayIconManager, typeof(TrayIconManager));
            _timerProvider = new TimerProvider();
            Locator.CurrentMutable.RegisterConstant(_timerProvider, typeof (ITimerProvider));
            Locator.CurrentMutable.RegisterConstant(new CheckingVersionView(), typeof(IViewFor<CheckingVersionViewModel>));
            Locator.CurrentMutable.RegisterConstant(new CheckingVersionErrorRetryingView(), typeof(IViewFor<CheckingVersionErrorRetryingViewModel>));
            Locator.CurrentMutable.RegisterConstant(new CheckingUserKeyView(), typeof(IViewFor<CheckingUserKeyViewModel>));
            Locator.CurrentMutable.RegisterConstant(new NewUserKeyView(), typeof(IViewFor<NewUserKeyViewModel>));
            Locator.CurrentMutable.RegisterConstant(new CheckingUserKeyErrorRetryingView(), typeof(IViewFor<CheckingUserKeyErrorRetryingViewModel>));
            Locator.CurrentMutable.RegisterConstant(new SuspendedView(), typeof(IViewFor<SuspendedViewModel>));
            Locator.CurrentMutable.RegisterConstant(new UnknownErrorView(), typeof(IViewFor<UnknownErrorViewModel>));
            Locator.CurrentMutable.RegisterConstant(new UnsupportedVersionView(), typeof(IViewFor<UnsupportedVersionViewModel>));

            NewUserKeyViewModel.Submit.Subscribe(_ =>
            {
                NewUserKeyViewModel.CanSubmit = false;
                ViewModel = CheckingUserKeyViewModel;
                HandleTryCheckUserKey(NewUserKeyViewModel.UserKey);

            });
            ViewModel = CheckingVersionViewModel;
            TryCheckVersion().Subscribe(a =>
            {
                if (a == CheckingVersionErrorRetryingViewModel)
                {
                    _trayIconManager.SetIconType(NotifyIconType.Warning);
                }
                else if (a == UnknownErrorViewModel || a == UnsupportedVersionViewModel)
                {
                    _trayIconManager.SetIconType(NotifyIconType.Error);
                }
                else
                {
                    _trayIconManager.SetIconType(NotifyIconType.Idle);
                }
                ViewModel = a;
                if (a == CheckingUserKeyViewModel)
                {
                    HandleTryCheckUserKey(_settings.UserKey);
                }
            });
        }
Ejemplo n.º 2
0
        public MainViewModel()
        {
            _settings = Locator.CurrentMutable.GetService<Settings>();
            _customObservable2 = Locator.CurrentMutable.GetService<ICustomObservable2>();
            _schedulerProvider = Locator.CurrentMutable.GetService<ISchedulerProvider>();
            _client = Locator.CurrentMutable.GetService<IMainServiceClientHelper>();
            _timerProvider = Locator.CurrentMutable.GetService<ITimerProvider>();

            GameEnvironments = GetGameEnvironmentItems();
            SelectedGameEnvironment = GameEnvironments.First();
            LoadingScripts();
            LoadingServers();
            MatchOrdersRouting();
            AddingRemovingMatchOrderItems();
            SelectingScriptWhenServerIsSelected();
            ClearingServerWhenScriptIsEditedOrSelected();
            SubmittingCancellingMatchOrder();

            RefreshMatchOrdersSummary =
                this.WhenAny(x => x.MatchOrdersSummaryViewModelBase.IsLoading, x => !x.Value).ToCommand();

            this.WhenAnyValue(x => x.SelectedGameEnvironment).Subscribe(_ =>
            {
                ScriptPart = null;
                Script = null;
                GameServerLoginPart = null;
                GameServer = null;
                PlayersMinCount = null;
                MatchOrdersSummaryViewModel.MatchOrdersSummaryItems.Clear();
                MatchOrdersSummaryViewModelBase = MatchOrdersSummaryViewModel;
            });

            LoadingMatchOrdersSummary();
            LoadingScriptMatchOrdersSummary();
            LoadingServerFilterMatchOrdersSummary();

            IsJoinMatchesAutomatically = _settings.IsJoinMatchesAutomatically;
            this.WhenAnyValue(x => x.IsJoinMatchesAutomatically)
                .Subscribe(_ =>
                {
                    if (IsJoinMatchesAutomatically && string.IsNullOrWhiteSpace(_settings.GameFilePath))
                    {
                        IsJoinMatchesAutomatically = false;
                        MessageBus.Current.SendMessage(new BrowseGameFileEvent());
                    }
                    _settings.IsJoinMatchesAutomatically = IsJoinMatchesAutomatically;
                });

            _gameServerLoginPartDirectChangeObservable
                .Subscribe(_ => GameServer = null);
        }