Esempio n. 1
0
        static void Main(string[] args)
        {
            Trainer     trainer = new Trainer();
            Subscriber1 sub1    = new Subscriber1();
            Subscriber2 sub2    = new Subscriber2();
            Subscriber3 sub3    = new Subscriber3();

            trainer.Eventce += sub1.Sms;
            trainer.Eventce += sub2.EMail;
            trainer.Eventce += sub3.Fb;
            //dragan.friends += user.nikola;
            //dragan.Post(slika); // nikola ke ja dobie na feed
            List <string> strings = new List <string>()
            {
                "petko", "trajko"
            };
            Func <string, bool> myFunc = x => false;

            strings.Where(myFunc);

            trainer.ComposeMessage("Pero", 4, "Poraka");

            trainer.Eventce += sub1.Sms;
            trainer.Eventce -= sub2.EMail;

            trainer.ComposeMessage("Pero", 4, "Poraka");
            Console.ReadLine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            NotificationOfEvents nOE   = new NotificationOfEvents();
            Subscriber1          subs1 = new Subscriber1();
            Subscriber2          subs2 = new Subscriber2();

            nOE.notifyDelegate += subs1.OnNotified;
            nOE.notifyDelegate += subs2.OnNotified;
            nOE.NotifyMethod(1);
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Publisher   p  = new Publisher();
            Subscriber1 s1 = new Subscriber1();
            Subscriber2 s2 = new Subscriber2();

            p.EventHandler += s1.Subscribe1Process;
            p.EventHandler += s2.Subscribe2Process;

            p.Publish("This is a message.");
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            string      fancyMessage = "This is a very fancy message!";
            Publisher   publisher    = new Publisher();
            Subscriber1 sub1         = new Subscriber1();
            Subscriber2 sub2         = new Subscriber2();

            publisher.DataProcessingHandler += sub1.GetMessage;
            publisher.DataProcessingHandler += sub2.GetMessage;
            publisher.DataProcessingHandler += x =>
                                               Console.WriteLine($"Special handling of message: {x}");

            publisher.ProcessData(fancyMessage);
            Thread.Sleep(3000);
            publisher.DataProcessingHandler -= sub2.GetMessage;
            publisher.ProcessData("NOVA PORAKA");
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            //Console.WriteLine("Hello World!");

            //Javascript - events
            //function doSomething(){//does something};

            //let but = document.getElementByID("btnClick");
            //but.addEventListener("click", doSomething(), false);

            //C# logic of raising events
            //create delegate
            //create event of the delegate type accepting methods with the delegate signature
            //for example: void delegate (string something) => event of this delegate type
            //to assign methods that return nothing and accepts string as a parameter

            string      fancyMessage = "This is a very fancy message";
            Publisher   publisher    = new Publisher();
            Subscriber1 subscriber1  = new Subscriber1();
            Subscriber2 subscriber2  = new Subscriber2();

            publisher.DataProccessingHandler += subscriber1.GetMessage1;
            publisher.DataProccessingHandler += subscriber2.GetMessage2;
            publisher.DataProccessingHandler += x => Console.WriteLine($"Special handling of message: {x}");

            publisher.ProccessData(fancyMessage);

            Console.WriteLine("--------------------------------");

            Thread.Sleep(2000);

            publisher.DataProccessingHandler -= subscriber2.GetMessage2;
            publisher.ProccessData(fancyMessage);

            Console.ReadKey();
        }