コード例 #1
0
        static void Main(string[] args)
        {
            var encoder = new VideoEncoder();

            encoder.VideoEncoded += Encoder_VideoEncoded;

            encoder.Encode(new Video("Terminator"));
            encoder.Encode(new Video("Rambo"));
            encoder.Encode(new Video("Shining"));
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Nohovich/.NET
        static void Main(string[] args)
        {
            VideoEncoder encode = new VideoEncoder();
            Video        video  = new Video("My cool video");

            // 4 registrating the method to the Publisher
            encode.VideoEncoded += VideoEncodedEventHandler;

            encode.Encode(video);
        }
コード例 #3
0
        static void Main()
        {
            string video        = "Video name";
            var    VideoEncoder = new VideoEncoder(); //publisher
            var    _mailService = new MailService();  //subscriber
            var    _textService = new TextService();

            VideoEncoder.VideoEncoded += _mailService.OnVideoEncoded; //adding it to
            VideoEncoder.VideoEncoded += _textService.OnVideoEncoded; //subscriber list
            VideoEncoder.Encode(video);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: Windwker/CSharp
        static void Main(string[] args)
        {
            var video = new Video();

            video.Title = "Title1";
            var MailService  = new MailService();
            var videoEncoder = new VideoEncoder();

            videoEncoder.VideoEncoded += MailService.OnVideoEncoded;
            videoEncoder.Encode(video);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: jazzAlston/EventsExample
        static void Main(string[] args)
        {
            var video = new Video {
                Title = "Video1"
            };
            var videoEncoder = new VideoEncoder();
            var mailService  = new MailService();

            videoEncoder.VideoEncoded += mailService.OnVideoEncoded;

            videoEncoder.Encode(video);
        }
コード例 #6
0
        static void Main(string[] args)
        {
            Video        video       = new Video("New Video");
            VideoEncoder encoder     = new VideoEncoder(); //Publisher
            var          mailService = new MailService();  //Subscriber 1
            var          textService = new TextService();  //Subscriber 2

            //Adding Subscribers to Notify
            encoder.VideoEncoded += mailService.OnVideoEncoded;
            encoder.VideoEncoded += textService.OnVideoEncoded;
            encoder.Encode(video);
        }
コード例 #7
0
        //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);
        }
コード例 #8
0
        private static void Main(string[] args)
        {
            var video = new Video()
            {
                Title = "Video 1"
            };
            var videoEncoder = new VideoEncoder(); // publisher
            var mailService  = new MailService();  // subscriber

            videoEncoder.VideoEncoded += mailService.OnVideoEncoded;

            videoEncoder.Encode(video);
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: IvanLtsyk/C-EventHndler
        static void Main(string[] args)
        {
            var video = new Video {
                Title = "Test video"
            };
            var videoEncoder   = new VideoEncoder();
            var mailServices   = new MailServicess();
            var messageService = new MessageServicess();

            videoEncoder.VideoEncoded += mailServices.OnVideoEncoded;
            videoEncoder.VideoEncoded += messageService.OnVideoEncoded;
            videoEncoder.Encode(video);
        }
コード例 #10
0
        static void Main(string[] args)
        {
            var videoEncoder = new VideoEncoder();

            //subscribing to the event
            videoEncoder.VideoEncoded += MailService.OnVideoEncoded;

            videoEncoder.VideoEncoded_ += MailService.OnVideoEncoded_;

            videoEncoder.Encode(new Video());

            Console.ReadLine();
        }
コード例 #11
0
        // 1. Define a delegate (Contract)
        // 2. Define a Event based on delegate
        // 3. Rise an Event
        static void Main(string[] args)
        {
            var video = new Video {
                Title = "Video1"
            };
            var videoEncoder   = new VideoEncoder();   //Pusblisher
            var mailService    = new MailService();    //Subsriber
            var messageService = new MessageService(); //Subscriber

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

            videoEncoder.Encode(video);
        }
コード例 #12
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();
        }
コード例 #13
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();
        }
コード例 #14
0
        static void Main(string[] args)
        {
            Video video = new Video {
                Title = "Gladiator"
            };
            VideoEncoder videoEncoder = new VideoEncoder();

            MailService      mailService      = new MailService();
            MessagingService messagingService = new MessagingService();

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

            videoEncoder.Encode(video);
        }
コード例 #15
0
        static void Main(string[] args)
        {
            var video = new Video()
            {
                Title = "New Video"
            };
            var videoEncoder     = new VideoEncoder();   //publisher
            var mailService      = new MailService();    //subcriber
            var messengerService = new MessageService(); //subscriber

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

            videoEncoder.Encode(video);
        }
コード例 #16
0
ファイル: Program.cs プロジェクト: wanasak/csharp-adv-demo
        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();
        }
コード例 #17
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();
        }
コード例 #18
0
ファイル: Program.cs プロジェクト: m-michalek/UdemyCSharp
        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);
        }
コード例 #19
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();
        }
コード例 #20
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);
        }
コード例 #21
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);
        }
コード例 #22
0
ファイル: Program.cs プロジェクト: zaekeon/csharp2
        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);
        }
コード例 #23
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);
        }
コード例 #24
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();
        }
コード例 #25
0
ファイル: Program.cs プロジェクト: inblack67/C-Sharp
        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...
        }
コード例 #26
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();
        }