//Definition of events
        //A mechanism for communication btw objects
        //Used in building Loosely coupled apps
        //Helps extending apps

        //Usage
        // event publisher => event receiver/handler

        //Delegates
        //Agreement/contract btw Publisher and Subscriber
        //Determines the signature of the event handler method in Subscriber
        static void Main(string[] args)
        {
            var video = new Video() { Title = "Video 1" };
            var videoEncoder = new VideoEncoder();//publisher
            var mailService = new MailService();//subscriber
            var messageService = new MessageService(); // subscriber

            videoEncoder.VideoEncoded += mailService.OnVideoEncoded;
            videoEncoder.VideoEncoded += messageService.OnVideoEncoded;

            videoEncoder.Encode(video);
        }
Пример #2
0
        //Lesson 4 : Events
        static void Main(string[] args)
        {
            var video = new Video()
            {
                Title = "Video 1"
            };
            var videoEncoder   = new VideoEncoder();
            var mailService    = new MailService();
            var messageService = new MessageService();

            videoEncoder.VideoEncoded += mailService.OnVideoEncoded;
            videoEncoder.VideoEncoded += messageService.OnVideoEncoded;

            videoEncoder.Encode(video);
        }
Пример #3
0
        static void Main(string[] args)
        {
            var order = new ForexOrder {
                AccountNumber = "1574078"
            };
            var mailService     = new MailService();
            var documentService = new DocumentService();

            order.OnForexOrderSave += mailService.HandleOrderSaveEvent;
            order.OnForexOrderSave += documentService.HandleOrderSaveEvent;

            order.Save();

            Console.ReadLine();
        }
Пример #4
0
        static void Main(string[] args)
        {
            var video = new Video()
            {
                Titile = "Iron Man"
            };
            var videoEncoder = new VideoEncoder();
            var mailService  = new MailService();
            var smsService   = new SmsService();

            videoEncoder.VideoEnCoded += mailService.OnVideoEncoded;
            videoEncoder.VideoEnCoded += smsService.OnVideoEncoded;
            videoEncoder.Encode(video);
            Console.ReadLine();
        }
Пример #5
0
        private static void Main(string[] args)
        {
            var video = new Video()
            {
                Title = "V1"
            };
            var videoEncoder = new VideoEncoder(); // Publisher
            var mailService  = new MailService();
            var smsService   = new SmsService();

            videoEncoder.VideoEncoded += mailService.OnVideoEncoder;
            videoEncoder.VideoEncoded += smsService.OnVideoEncoder;
            videoEncoder.Encode(video);
            Console.ReadLine();
        }
Пример #6
0
        static void Main(string[] args)
        {
            var video = new Video {
                Title = "Harry Potter"
            };
            var videoEncoder = new VideoEncoder(); // publisher
            var mailService  = new MailService();  // subscriber
            var textService  = new TextService();  // subscriber

            videoEncoder.VideoEncoded += mailService.OnVideoEncoded;
            videoEncoder.VideoEncoded += textService.OnVideoEncoded;

            videoEncoder.Encode(video);

            Console.ReadKey();
        }
Пример #7
0
        public static void Main(string[] args)
        {
            var video = new Video {
                Title = "A funny video"
            };
            var mailService  = new MailService();
            var smsService   = new SmsService();
            var videoEncoder = new VideoEncoder();

            Console.WriteLine("[Program] Register events...");
            videoEncoder.VideoEncoded += mailService.OnVideoEncoded;
            videoEncoder.VideoEncoded += smsService.OnVideoEncoded;
            videoEncoder.VideoEncodedWithoutArguments += mailService.OnVideoEncoded_WithoutArguments;
            videoEncoder.VideoEncodedWithoutArguments += smsService.OnVideoEncoded_WithoutArguments;

            videoEncoder.Encode(video);
        }
Пример #8
0
        static void Main(string[] args)
        {
            var video = new Video()
            {
                Title = "Video 1"
            };
            var videoEncoder   = new VideoEncoder();   //publisher
            var mailService    = new MailService();    //subscriber
            var messageService = new MessageService(); //subscriber

            videoEncoder.VideoEncoded += mailService.OnVideoEncoded;
            videoEncoder.VideoEncoded += messageService.OnVideEncoded;
            videoEncoder.Encode(video);

            Console.WriteLine("Encoded");
            Console.ReadLine();
        }
Пример #9
0
        static void Main(string[] args)
        {
            Video video = new Video()
            {
                Title = "Video 1"
            };
            VideoEncoder videoEncoder = new VideoEncoder();
            MailService  mailService  = new MailService();
            TextMessage  textMessage  = new TextMessage();

            videoEncoder.VideoEncoded += mailService.OnVideoEncoded;
            videoEncoder.VideoEncoded += textMessage.OnVideoEncoded;

            videoEncoder.Encode(video);

            Console.ReadKey();
        }
Пример #10
0
        static void Main(string[] args)
        {
            /*
             * Events is a mechanism for communication between objects, it helps building loosely coupled apps and helps extending them.
             *
             */

            var video = new Video()
            {
                Title = "Video 1"
            };
            var videoEncoder   = new VideoEncoder();                 // <- publisher
            var mailService    = new MailService();                  // <- subscriber
            var messageService = new MessageService();               // <- subscriber

            videoEncoder.VideoEncoded += mailService.OnVideoEncoded; // <- handler
            videoEncoder.VideoEncoded += messageService.OnVideoEncoded;
            videoEncoder.Encode(video);
        }
Пример #11
0
        static void Main(string[] args)
        {
            // 1 - Define a delegate
            // 2 - Define an event based on that delegate
            // 3 - Raise an event


            var video = new Video()
            {
                Title = "Video 1"
            };
            var videoEncoder   = new VideoEncoder();   // publisher
            var mailService    = new MailService();    // subscriber
            var messageService = new MessageService(); //subscriber

            videoEncoder.VideoEncoded += mailService.OnVideoEncoded;
            videoEncoder.VideoEncoded += messageService.OnVideoEncoded;
            videoEncoder.Encode(video);
        }
Пример #12
0
        static void Main(string[] args)
        {
            //EVENTS

            //a mechanism for communication between objects...it can notify objects something has happened.
            //used in building loosely coupled applications
            //helps extending applications

            var video = new Video() { Title = "Video 1" };
            var videoEncoder = new VideoEncoder();  //this is the publisher
            var mailService = new MailService(); //this is the subscriber
            var messageService = new MessageService();

            //call and create the subscription
            videoEncoder.VideoEncoded += mailService.OnVideoEncoded;
            videoEncoder.VideoEncoded += messageService.OnVideoEncoded;

            videoEncoder.Encode(video);
        }
Пример #13
0
        // Events: Mechanism for communication between objects
        // Used in building loosely coupled applications
        // Helps with extending applications

        // Delegate: Agreement or Contract between a Publisher and Subscriber
        // Determines the signature of the event handler method in the subscriber

        static void Main(string[] args)
        {
            var video = new Video()
            {
                Title = "Video 1"
            };
            var videoEncoder   = new VideoEncoder();   //publisher
            var mailService    = new MailService();    //subscriber
            var messageService = new MessageService(); //subscriber

            // subscribing
            videoEncoder.VideoEncoded += mailService.OnVideoEncoded; // no bracket or parens, indicating that this is a pointer to a method (i.e. a delegate)
            // videoEncoder = publisher
            // .VideoEncoded = desired event
            // +=  =  subscribing
            // messageService = subscriber
            // .OnVideoEncoded = pointer
            videoEncoder.VideoEncoded += messageService.OnVideoEncoded;

            videoEncoder.Encode(video);
        }
Пример #14
0
        static void Main(string[] args)
        {
            var video = new Video {
                Title = "Video 1"
            };
            var videoEncoder   = new VideoEncoder();   //publisher
            var mailService    = new MailService();    //subscriber
            var messageService = new MessageService(); //another subscriber

            videoEncoder.VideoEncoded += mailService.OnVideoEncoded;
            videoEncoder.VideoEncoded += messageService.OnVideoEncoded;

            videoEncoder.Encode(video);

            var videoEncoderDotNetDelegate = new VideoEncoderDotNetDelegate();

            videoEncoderDotNetDelegate.VideoEncoded += mailService.OnVideoEncoded;
            videoEncoderDotNetDelegate.Encode(video);

            Console.ReadLine();
        }
Пример #15
0
        static void Main(string[] args)
        {
            var video = new Video()
            {
                Title = "Video 1"
            };
            var videoEncoder   = new VideoEncoder(); // publisher
            var mailService    = new MailService();  // subscriber
            var messageService = new MessageService();

            // making the subscription first
            videoEncoder.VideoEncoded += mailService.OnVideoEncoded;    // not calling, just a reference

            // making another subscription
            videoEncoder.VideoEncoded += messageService.OnVideoEncoded;


            videoEncoder.Encode(video);

            // subscribers added without making single change in VE class

            // must send the data...
        }
Пример #16
0
        static void Main(string[] args)
        {
            var video = new Video()
            {
                Title = "Home Alone"
            };
            var encoder        = new VideoEncoader(); //publisher
            var mailService    = new MailService();   //subscriber
            var messageService = new Messanger();

            // VideoEncoding subscriber
            var preProcessor = new PreProcessor();

            //registering subscriptpion on event

            //encodING event
            encoder.VideoEncoding += preProcessor.OnVideoEncoding;

            //EncodeED event
            encoder.VideoEncoded += mailService.OnVideoEncoded;
            encoder.VideoEncoded += messageService.OnVideoEncoded;
            encoder.VideoEncoded += Dorefactor;
            encoder.Encode(video);
        }
Пример #17
0
        private static void Main(string[] args)
        {
            // Fill class video with a name value
            var video = new Video {
                Name = "DelegatesAndEvents.mp4"
            };

            // Publish
            var videoEncoder = new VideoEncoder();

            // Subscribers
            var messageService = new MessageService();
            var mailService    = new MailService();

            // Sign the event
            videoEncoder.VideoEncoded += messageService.OnVideoEncoded;
            videoEncoder.VideoEncoded += mailService.OnVideoEncoded;

            // Call to method that encode the video
            videoEncoder.Encode(video);

            // Wait for some character in console application
            Console.Read();
        }