Exemplo n.º 1
0
        private void SetupObservableFinished()
        {
            RandomizerService.IRandomizer svc = new RandomizerService.RandomizerClient();
            var svcObserver = Observable.FromAsyncPattern <int, int>(svc.BeginRoll, svc.EndRoll);

            var rollDetected = Observable.FromEvent <RoutedEventArgs>(RollButton, "Click")
                               .Select(_ => new Unit())
                               .Merge(ShakeObserver.GetShakeObserver(accel))
                               .Merge(App.ViewModel.SideCountDataSource.Select(_ => new Unit()))
                               .Throttle(TimeSpan.FromMilliseconds(250))
            ;

            var query =
                from roll in rollDetected
                from die in App.ViewModel.Items.ToObservable()
                .Where(die => !die.Frozen)
                .ObserveOnDispatcher()
                .Do(die => die.DotCount = null)
                //.ObserveOn(Scheduler.ThreadPool)
                from result in svcObserver(App.ViewModel.DiceCount)
                .TakeUntil(rollDetected)
                select new { die, rolledDots = result };

            _diceObserver = query.ObserveOnDispatcher()
                            .Subscribe(result => result.die.DotCount = result.rolledDots,
                                       err => ErrorBlock.Text        = err.Message);
        }
Exemplo n.º 2
0
        private void SetupObservableService()
        {
            var buttonObservable = Observable.FromEvent <RoutedEventArgs>(RollButton, "Click");

            RandomizerService.IRandomizer proxy = new RandomizerService.RandomizerClient();
            var serviceObservable = Observable.FromAsyncPattern <int, int>(proxy.BeginRoll, proxy.EndRoll);

            var rollRequested = (from buttonClick in buttonObservable
                                 select new Unit())
                                .Merge(ShakeObserver.GetShakeObserver(accel))
                                .Merge(App.ViewModel.DiceCountDataSource.Select(_ => new Unit()));


            var query = from roll in rollRequested.Throttle(TimeSpan.FromMilliseconds(400))
                        from dice in App.ViewModel.Items.ToObservable()
                        .Where(die => !die.Frozen)
                        .ObserveOnDispatcher()
                        .Do(die => die.DotCount = null)
                        .Zip(Observable.Interval(TimeSpan.FromMilliseconds(250)),
                             (die, _) => die)
                        from serviceResult in serviceObservable.Invoke(App.ViewModel.SideCount)
                        .TakeUntil(rollRequested)
                        select new { source = dice, result = serviceResult };

            _diceObserver = query.ObserveOnDispatcher().Subscribe(val => val.source.DotCount = val.result,
                                                                  er => this.ErrorBlock.Text = er.Message);
        }
Exemplo n.º 3
0
        private void SetupObservableFinished()
        {
            RandomizerService.IRandomizer proxy = new RandomizerService.RandomizerClient();
            var serviceObservable = Observable.FromAsyncPattern <int, int>(proxy.BeginRoll, proxy.EndRoll);

            var RollObserved = Observable.FromEvent <RoutedEventArgs>(RollButton, "Click").Select(_ => new Unit())
                               //.Merge(App.ViewModel.SideCountDataSource.Select(_ => new Unit()))
                               .Merge(ShakeObserver.GetShakeObserver(accel))
                               .Throttle(TimeSpan.FromMilliseconds(200)).ObserveOnDispatcher();

            var roll = from unfrozenDie in
                       (from click in RollObserved
                        from die in App.ViewModel.Items.ToObservable()
                        where !die.Frozen
                        select die)
                       .Do(die => die.DotCount = null)
                       .Zip(Observable.Interval(TimeSpan.FromMilliseconds(250)), (die, _) => die)
                       //.ObserveOn(Scheduler.ThreadPool)
                       from result in serviceObservable(App.ViewModel.SideCount)
                       .TakeUntil(RollObserved)
                       select new { unfrozenDie, rollValue = result };

            _diceObserver = roll.ObserveOnDispatcher().Subscribe(
                result => result.unfrozenDie.DotCount = result.rollValue,
                err => this.ErrorBlock.Text           = err.Message);
        }
Exemplo n.º 4
0
        //private void RollClick(object sender, RoutedEventArgs e)
        private void SetupObservable()
        {
            RandomizerService.IRandomizer proxy = new RandomizerService.RandomizerClient();
            var svcObservable = Observable.FromAsyncPattern <int, int>(proxy.BeginRoll, proxy.EndRoll);

            var rollDetected = Observable.FromEvent <RoutedEventArgs>(RollButton, "Click").Select(_ => new Unit())
                               .Merge(App.ViewModel.DiceCountDataSource.Select(_ => new Unit()))
                               .Merge(ShakeObserver.GetShakeObserver(accel));

            var roll =
                from detected in rollDetected.Throttle(TimeSpan.FromMilliseconds(400))
                from die in App.ViewModel.Items.ToObservable()
                .Where(die => !die.Frozen)
                .ObserveOnDispatcher()
                .Do(die => die.DotCount = null)
                from result in Randomizer.RollAsync(App.ViewModel.SideCount).ToObservable()
                select new { die, rolledDots = result };

            _diceObserver = roll.ObserveOnDispatcher().Subscribe(
                result => result.die.DotCount = result.rolledDots,
                err => this.ErrorBlock.Text   = err.Message);
        }