Ejemplo n.º 1
0
        static void Main()
        {
            var observableProvider   = new ObservableProvider();
            var observableGenerator1 = GeneratorFactory.CreateGenerator(0, 100, 1, 100);
            var observableGenerator2 = GeneratorFactory.CreateGenerator(1000, 2000, 2, 600);
            var observableGenerator3 = GeneratorFactory.CreateGenerator(10000, 15000, 51, 1000);

            Console.WriteLine("Press any keys, enter to end ConsoleKey stream.");

            var observableMerge1 = Observable.Merge(
                observableProvider.ConsoleKey.Select(x => (int)x.Key),
                observableGenerator1,
                observableGenerator2,
                observableGenerator3
                );

            var consoleKeySubscribent = observableProvider.ConsoleKey.Subscribe(
                key =>
            {
                if (key.Key != ConsoleKey.Enter)
                {
                    return;
                }

                observableProvider.ConsoleKey.Stop();

                Console.WriteLine("Press any key to stop program.");
            });

            var subscribent1 = observableMerge1.Subscribe(
                item =>
            {
                Console.WriteLine($"Merge1: {item}");
            },
                exception => Console.WriteLine(exception));


            var observableMerge2 = GeneratorFactory.CreateGenerator(-1000, 0, 1, 10);

            observableMerge2
            .Merge(observableGenerator1)
            .Merge(observableGenerator2)
            .Merge(observableGenerator3);

            var subscribent2 = observableMerge2.Subscribe(
                item =>
            {
                Console.WriteLine($"Merge2: {item}");
            },
                exception => Console.WriteLine(exception));

            observableProvider.ConsoleKey.Start();

            Console.ReadKey();

            subscribent1.Dispose();
            subscribent2.Dispose();
            consoleKeySubscribent.Dispose();
            observableProvider.Dispose();
        }
Ejemplo n.º 2
0
        static void Main()
        {
            var observableStream1  = GeneratorFactory.CreateGenerator(0, 100, 1, 500);
            var observableStream2  = GeneratorFactory.CreateGenerator(1000, 1100, 1, 2000);
            var observableStream3  = GeneratorFactory.CreateGenerator(10000, 11000, 1, 250);
            var observableProvider = new ObservableProvider();

            observableProvider.ConsoleKey.BreakWhenKey(ConsoleKey.Enter);

            var combineLatestStream = observableStream1.CombineLatest(
                observableStream2,
                observableStream3,
                observableProvider.ConsoleKey,
                (a, b, c, d) => new
            {
                A = a,
                B = b,
                C = c,
                D = d.Key
            });

            var combineLatestSubscribent = combineLatestStream.DefaultPrint("CombineLatest");

            Console.WriteLine("Pres any key to show results.");

            observableProvider.ConsoleKey.Start();

            observableProvider.Dispose();
            combineLatestSubscribent.Dispose();
        }
Ejemplo n.º 3
0
        static void Main()
        {
            var observableStream1  = GeneratorFactory.CreateGenerator(0, 100, 1, 100);
            var observableStream2  = GeneratorFactory.CreateGenerator(0, 100, 1, 60);
            var observableStream3  = GeneratorFactory.CreateGenerator(0, 100, 1, 120);
            var observableProvider = new ObservableProvider();

            observableProvider.ConsoleKey.BreakWhenKey(ConsoleKey.Enter);

            var whenAndThenSequence = Observable.When(observableStream1
                                                      .And(observableStream2)
                                                      .And(observableStream3)
                                                      .And(observableProvider.ConsoleKey)
                                                      .And(observableProvider.TimeCounter)
                                                      .Then((first, second, third, consoleKey, time) =>
                                                            new {
                One   = first,
                Two   = second,
                Three = third,
                Key   = consoleKey.Key,
                Time  = time
            })
                                                      );

            Console.WriteLine("Pres any key to show results.");
            var whenAndThenSubscribent = whenAndThenSequence.DefaultPrint("WhenAndThen");

            observableProvider.ConsoleKey.Start();

            observableProvider.Dispose();
            whenAndThenSubscribent.Dispose();
        }
Ejemplo n.º 4
0
        static void Main()
        {
            var observableProvider = new ObservableProvider();

            observableProvider.ConsoleKey
            .Subscribe(consoleKey =>
            {
                Console.WriteLine(consoleKey.Key);

                if (consoleKey.Key == ConsoleKey.Enter)
                {
                    observableProvider.ConsoleKey.Stop();
                }
            });

            observableProvider.ConsoleKey.Start();

            observableProvider.Dispose();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            InitializeGenerators();

            AddSkipLastSubscribent();

            AddSkipSubscribent();

            AddSkipWhileSubscribent();

            AddSkipUntilSubscribent();

            AddAllItemSubscribent();

            Console.ReadKey();

            _observableProvider.Dispose();
            _skipLastSubscribent.Dispose();
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            var observableProvider = new ObservableProvider();

            observableProvider.TimeCounter.Subscribe(time =>
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine(time);
            });

            observableProvider.ValentinesDay.Subscribe(valentinesDayMessage =>
            {
                Console.ForegroundColor = valentinesDayMessage.Color;
                Console.WriteLine(valentinesDayMessage.Message);
            });

            Console.ReadKey();

            observableProvider.Dispose();
        }