protected override void OnInitialize() { base.OnInitialize(); var sl = this.WhenAnyValue(x => x.ServerList.IsUpdating, x => x.SystemInfo.IsInternetAvailable, (updating, internetAvailable) => !updating && internetAvailable) .ObserveOn(RxApp.MainThreadScheduler); var processingObservable = this.WhenAnyValue(x => x.ServerList.DownloadingServerList, x => x.ServerList.IsUpdating) .ObserveOn(RxApp.MainThreadScheduler); ReactiveUI.ReactiveCommand.CreateAsyncTask(processingObservable.Select(x => !x.Item1 && !x.Item2), async x => await Reload()) .SetNewCommand(this, x => x.ReloadCommand) .Subscribe(); ReactiveUI.ReactiveCommand.CreateAsyncTask(processingObservable.Select(x => x.Item1 || x.Item2), async x => await AbortInternal()) .SetNewCommand(this, x => x.AbortCommand) .Subscribe(); this.SetCommand(x => x.SwitchQuickPlay).Subscribe(SwitchQuickPlayAction); this.SetCommand(x => x.QActionCommand).RegisterAsyncTask(QAction).Subscribe(); this.SetCommand(x => x.AddServerCommand).Subscribe(x => ShowAddServer()); this.SetCommand(x => x.AddServerOKCommand).RegisterAsyncTask(AddServerOK).Subscribe(); this.SetCommand(x => x.AddServerCancelCommand).Subscribe(x => CancelAddServer()); RefreshFilterCommand = ReactiveUI.ReactiveCommand.CreateAsyncTask(x => RefreshFilterWithDelay()); CreateLibrary(DomainEvilGlobal.SelectedGame.ActiveGame); _contentManager.InitialServerSync(true); CgsUpdate = ReactiveUI.ReactiveCommand.CreateAsyncTask(OnCgsUpdate).DefaultSetup("OnCgsUpdate"); CgsUpdate.Subscribe(); var onActivate = ReactiveUI.ReactiveCommand.CreateAsyncTask(x => OnActivateInternal()).DefaultSetup("OnActivate"); onActivate.Subscribe(); var isEnabledQuery = this.WhenAnyValue(x => x.IsActive); isEnabledQuery.Subscribe(x => _settings.AppOptions.ServerListEnabled = x); isEnabledQuery.Where(x => x) .Skip(1) .Subscribe(x => onActivate.Execute(null)); this.WhenAnyValue(x => x.ServerList.ServerQueryQueue.State) .Subscribe(x => ProgressState = x); this.WhenAnyValue(x => x.ServerList.DownloadingServerList) .Subscribe(SwitchProgressState); }
/// <summary> /// This creates a ReactiveCommand that calls several child /// ReactiveCommands when invoked. Its CanExecute will match the /// combined result of the child CanExecutes (i.e. if any child /// commands cannot execute, neither can the parent) /// </summary> /// <param name="canExecute">An Observable that determines whether the /// parent command can execute</param> /// <param name="commands">The commands to combine.</param> public static LegacyRxCmd CreateCombined(IObservable <bool> canExecute, params ReactiveCommand[] commands) { var childrenCanExecute = commands .Select(x => x.CanExecuteObservable) .CombineLatest(latestCanExecute => latestCanExecute.All(x => x != false)); var canExecuteSum = Observable.CombineLatest( canExecute.StartWith(true), childrenCanExecute, (parent, child) => parent && child); var ret = new LegacyRxCmd(canExecuteSum); ret.Subscribe(x => { foreach (var cmd in commands) { cmd.Execute(x); } }); return(ret); }