Example #1
0
        public async Task SelectManyTest()
        {
            var emulator     = new ClicksEmulator();
            var emulatorTask = emulator.Start();

            var cts             = new CancellationTokenSource();
            var cancelationTask = Task.Run(async() =>
            {
                await Task.Delay(5000);
                cts.Cancel();
            });

            var clicks = emulator
                         .Clicks()
                         .OnNext(item => Log($"Original: {item.Button} {item.X} {item.Y}"))
                         .CollectEnumerable(cts.Token)
                         .Select(click => click.Button == ClicksEmulator.Button.Left
                    ? Flow <ClicksEmulator.ClickEventArgs>(collector => collector.Emit(click))
                    : Flow <ClicksEmulator.ClickEventArgs>(async collector =>
            {
                var changedClick =
                    new ClicksEmulator.ClickEventArgs(click.X, click.Y, ClicksEmulator.Button.Left);
                await collector.Emit(changedClick);
                await Task.Delay(200);
                await collector.Emit(changedClick);
            })
                                 )
                         .SelectMany(flow => flow.CollectEnumerable());

            await foreach (var click in clicks)
            {
                Log($"Changed: {click.Button} {click.X} {click.Y}");
            }
        }
Example #2
0
        public Task FromEventHandlerTest()
        {
            var emulator     = new ClicksEmulator();
            var emulatorTask = emulator.Start();

            var cts             = new CancellationTokenSource();
            var cancelationTask = Task.Run(async() =>
            {
                await Task.Delay(5000);
                cts.Cancel();
            });

            return(emulator
                   .Clicks()
                   .Collect(item => Log($"{item.Button} {item.X} {item.Y}"), cts.Token));
        }
Example #3
0
        public Task MapAndOnNextTest()
        {
            var emulator     = new ClicksEmulator();
            var emulatorTask = emulator.Start();

            var cts             = new CancellationTokenSource();
            var cancelationTask = Task.Run(async() =>
            {
                await Task.Delay(5000);
                cts.Cancel();
            });

            return(emulator
                   .Clicks()
                   .OnNext(item => Log($"{item.Button} {item.X} {item.Y}"))
                   .Map(click => click.Button == ClicksEmulator.Button.Left ? 0 : 1)
                   .Collect(item => Log($"{item}"), cts.Token));
        }
Example #4
0
        public async Task AsyncEnumerableTest()
        {
            var emulator     = new ClicksEmulator();
            var emulatorTask = emulator.Start();

            var cts             = new CancellationTokenSource();
            var cancelationTask = Task.Run(async() =>
            {
                await Task.Delay(5000);
                cts.Cancel();
            });

            var clicks = emulator
                         .Clicks()
                         .OnNext(item => Log($"{item.Button} {item.X} {item.Y}"))
                         .CollectEnumerable(cts.Token)
                         .Where(click => click.Button == ClicksEmulator.Button.Right)
                         .Select(click => click.Y < 540 ? "TOP" : "LEFT");

            await foreach (var click in clicks)
            {
                Log($"Clicked at: {click}");
            }
        }