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")); }
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); }
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); }
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); }
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); }
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); }
//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); }
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); }
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); }
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(); }
// 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); }
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(); }
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(); }
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); }
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); }
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(); }
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(); }
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); }
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(); }
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); }
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); }
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); }
// 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); }
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(); }
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... }
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(); }