Exemplo n.º 1
0
        public static ReactiveCommand <TOut> SetNewCommand <T, TOut>(this ReactiveCommand <TOut> command, T target,
                                                                     Expression <Func <T, ReactiveCommand <TOut> > > memberLamda)
            where T : class
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (memberLamda == null)
            {
                throw new ArgumentNullException(nameof(memberLamda));
            }

            var memberSelectorExpression = memberLamda.Body as MemberExpression;

            if (memberSelectorExpression == null)
            {
                throw new Exception("Not a member expression? " + target);
            }
            var property = memberSelectorExpression.Member as PropertyInfo;

            if (property == null)
            {
                throw new Exception("Not a property? " + target);
            }
            command.DefaultSetup(target.GetCallerName(property));
            property.SetValue(target, command, null);
            return(command);
        }
Exemplo n.º 2
0
        static ReactiveCommand CreateCommand(string name = null)
        {
            var command = new ReactiveCommand();

            command.DefaultSetup(name);
            return(command);
        }
Exemplo n.º 3
0
        /// <summary>
        /// RegisterAsyncTask registers an TPL/Async method that runs when a
        /// Command gets executed and returns no result.
        /// </summary>
        /// <param name="calculationFunc">The function to be run in the
        /// background.</param>
        /// <returns>An Observable that signals when the Task completes, on
        /// the UI thread.</returns>
        public static IObservable <Unit> RegisterAsyncTask(this LegacyRxCmd This, Func <object, Task> calculationFunc)
        {
            Contract.Requires(calculationFunc != null);

            // NB: This PermaRef isn't exactly correct, but the people using
            // this method probably are Doing It Wrong, so let's let them
            // continue to do so.
            return(This.RegisterAsync(x => calculationFunc(x).ToObservable())
                   .Publish().PermaRef());
        }
Exemplo n.º 4
0
        /// <summary>
        /// RegisterAsyncFunction registers an asynchronous method that returns a result
        /// to be called whenever the Command's Execute method is called.
        /// </summary>
        /// <param name="calculationFunc">The function to be run in the
        /// background.</param>
        /// <param name="scheduler"></param>
        /// <returns>An Observable that will fire on the UI thread once per
        /// invoecation of Execute, once the async method completes. Subscribe to
        /// this to retrieve the result of the calculationFunc.</returns>
        public static IObservable <TResult> RegisterAsyncFunction <TResult>(this LegacyRxCmd This,
                                                                            Func <object, TResult> calculationFunc,
                                                                            IScheduler scheduler = null)
        {
            Contract.Requires(calculationFunc != null);

            var asyncFunc = calculationFunc.ToAsync(scheduler ?? RxApp.TaskpoolScheduler);

            return(This.RegisterAsync(asyncFunc));
        }
Exemplo n.º 5
0
        public override async void Start()
        {
            base.Start();

            var canExecute = this.WhenAny(model => model.DistrictSetting.SelectedDistrict, change => change.Value != null);
            this.Continue =
                new ReactiveCommand(canExecute);
            
            this.Continue.Subscribe(o => this.ShowViewModel<PersonalFeedsViewModel>());
        }
Exemplo n.º 6
0
        /// <summary>
        /// RegisterAsyncAction registers an asynchronous method that runs
        /// whenever the Command's Execute method is called and doesn't return a
        /// result.
        /// </summary>
        /// <param name="calculationFunc">The function to be run in the
        /// background.</param>
        public static IObservable <Unit> RegisterAsyncAction(this LegacyRxCmd This,
                                                             Action <object> calculationFunc,
                                                             IScheduler scheduler = null)
        {
            Contract.Requires(calculationFunc != null);

            // NB: This PermaRef isn't exactly correct, but the people using
            // this method probably are Doing It Wrong, so let's let them
            // continue to do so.
            return(This.RegisterAsyncFunction(x => { calculationFunc(x); return new Unit(); }, scheduler)
                   .Publish().PermaRef());
        }
Exemplo n.º 7
0
        public static ReactiveCommand CreateCommand(string name, bool allowMultiple, bool initialCondition = true)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            var command = new ReactiveCommand(null, allowMultiple, null, initialCondition);

            command.DefaultSetup(name);
            return(command);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        static ReactiveCommand CreateCommand(IObservable <bool> ena, string name, bool initialCondition = true)
        {
            if (ena == null)
            {
                throw new ArgumentNullException(nameof(ena));
            }
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            var command = new ReactiveCommand(ena, initialCondition);

            command.DefaultSetup(name);
            return(command);
        }
Exemplo n.º 10
0
        /// <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);
        }
Exemplo n.º 11
0
 /// <summary>
 /// RegisterAsyncTask registers an TPL/Async method that runs when a
 /// Command gets executed and returns the result
 /// </summary>
 /// <returns>An Observable that will fire on the UI thread once per
 /// invoecation of Execute, once the async method completes. Subscribe to
 /// this to retrieve the result of the calculationFunc.</returns>
 public static IObservable <TResult> RegisterAsyncTask <TResult>(this LegacyRxCmd This, Func <object, Task <TResult> > calculationFunc)
 {
     Contract.Requires(calculationFunc != null);
     return(This.RegisterAsync(x => calculationFunc(x).ToObservable()));
 }
Exemplo n.º 12
0
 public CommentViewModel()
 {
     SaveCommand = new ReactiveUI.Legacy.ReactiveCommand(this.WhenAnyValue(x => x.Comment).Select(x => !string.IsNullOrEmpty(x)));
 }
Exemplo n.º 13
0
 public CommentViewModel()
 {
     SaveCommand = new ReactiveUI.Legacy.ReactiveCommand(this.WhenAnyValue(x => x.Comment).Select(x => !string.IsNullOrEmpty(x)));
 }