Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var client = new Client();
            var numberGenerator = new NumberGenerator();

            numberGenerator.Subscribe((x) =>
            {
                client.HandleOutput(x);
            }, (x) =>
            {
                return x % 2 == 0; 
            });
            //client.lst.ForEach((x) => Console.WriteLine(x));

            Console.WriteLine(client.lst.Count);
            List<Func<Int32, bool>> myFilters = new List<Func<Int32, bool>>();
            myFilters.Add(x => x % 2 == 0);
            myFilters.Add(x => x % 3 == 0);
            myFilters.Add(x => x % 255 == 0);
            var client2 = new Client();
            numberGenerator.Subscribe((x) =>
            {
                client2.HandleOutput(x);
            }, 
            myFilters);
            Console.WriteLine(client2.lst.Count);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            NumberGenerator numGen = new NumberGenerator(100);

            Client client1 = new Client("client 1");
            Client client2 = new Client("client 2");

            //subscribe with one filter
            numGen.Subscribe((x) =>
            {
                client1.HandleOutput(x);
            },
                             (x) =>
            {
                return(x % 8 == 0);
            });

            //subscribe with several filters
            numGen.Subscribe((x) =>
            {
                client2.HandleOutput(x);
            },
                             new List <Func <int, bool> >
            {
                (x) => { return(x * x < 1000); },
                (x) => { return(x % 10 == 0); }
            });

            Console.ReadKey();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            NumberGenerator generator = new NumberGenerator();

            Console.WriteLine("Every 10th number:");
            generator.Subscribe((x) =>
            {
                // should be even only
                generator.GetNumber(x);
            }, (x) =>
            {
                return(x % 10 == 0);// declare rule for even.
            });
            Console.WriteLine("Every > 99 and %5 number:");
            generator.Subscribe((x) =>
            {
                // should be even only
                generator.GetNumber(x);
            }, (x) =>
            {
                return((x % 5 == 0) & (x > 99));// declare rule for even.
            });
            Console.ReadKey();
        }