static void Main(string[] args) { var video = new Video() {Title = "Video1" }; var videoEncoder = new VideoEncoder(); // Publisher var mailService = new MailService(); // Subscriber var messageService = new MessageService(); // Subscriber videoEncoder.VideoEncoded += mailService.OnVideoEncoded; // Adding the method pointer to the delegate. videoEncoder.VideoEncoded += messageService.OnVideoEncoded; // This is what populates the VideoEncodedEventHandler. This is a subscription. videoEncoder.VideoEncoding += mailService.OnVideoEncoding; videoEncoder.VideoEncoding += messageService.OnVideoEncoding; 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.OnVideoEncoded; videoEncoder.Encode(video); }
static void Main(string[] args) { Video video = new Video { Title = "Video Title" }; VideoEncoder encoder = new VideoEncoder(); // Publisher MailService mailService = new MailService(); // Subscriber MessageService messageService = new MessageService(); encoder.VideoEncoded += mailService.OnVideoEncoded; encoder.VideoEncoded += messageService.OnVideoEncoded; encoder.Encode(video); }
static void Main(string[] args) { var video = new Video { Title = "Titlu film" }; var videoEncoder = new VideoEncoder(); // acesta este publisher-ul nostru, ce va comunica si va trimite info catre subscriberi var mailService = new MailService(); // acesta este un subscriber la publisher-ul de mai sus var messageService = new MessageService(); //7. subscribtia ce sa va produce va fi reprezentata in felul de mai jos: videoEncoder.videoEncoded += mailService.OnVideoEncoded;//mai intai facem subscritia si chemama metoda folosind [+= ] ca sa inregistram handlerul la event !! nosta nu avem paranteze petru ca nu chemama metoda din MailService doar ne legam de ea facem o referinta un pointer videoEncoder.videoEncoded += messageService.OnVideoEncoded; videoEncoder.Encode(video); Console.ReadLine(); }
static void Main(string[] args) { var video = new Video() { Title = "MyVideo" }; var videoEncoder = new VideoEncoder(); //Publisher var mailService = new MailService(); //Subscriber var messageService = new MessageService(); //Subscriber //Need to Subscribe to the Event videoEncoder.VideoEncoded += mailService.onVideoEncoded; 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 textService = new TextService(); videoEncoder.VideoEncoded += mailService.OnVideoEncoded; //subscribing to the method videoEncoder.VideoEncoded += textService.OnVideoEncoded; videoEncoder.Encode(video); Console.ReadLine(); }
static void Main(string[] args) { var video = new Video { Title = "VideoTitle", Duration = "120" }; var videoEncoder = new VideoEncoder(); MessageService messageService = new MessageService(); MailService mailService = new MailService(); videoEncoder.VideoEncoded += messageService.OnVideoEncoded; videoEncoder.VideoEncoded += mailService.OnVideoEncoded; videoEncoder.Encoder(); }
static void Main(string[] args) { var video = new Video() { Title = "Lambhorgini" }; var videoEncoder = new VideoEncoder(); //publisher var mailService = new MailService(); //subscriber var smsService = new SmsService(); //subscriber videoEncoder.VideoEncoded += mailService.OnVideoEncoded; videoEncoder.VideoEncoded += smsService.OnVideoEncoded; videoEncoder.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(); //subscriber videoEncoder.RegisterEvent(mailService.OnVideoEncoded); videoEncoder.RegisterEvent(messageService.OnVideoEncoded); videoEncoder.Encode(video); Console.ReadLine(); }
static void Main(string[] args) { var video = new Video() { Title = "Naslov" }; var videoEncoder = new VideoEncoder(); var mailService = new MailService(); MessageService messageService = new MessageService(); videoEncoder.VideoEncoded += messageService.OnVideoEncoded; videoEncoder.VideoEncoded += mailService.OnVideoEncoded; videoEncoder.Encode(video); Console.ReadLine(); }
{ //events are list of pointers to methods static void Main(string[] args) { var ourVideo = new Video() { Title = "Video 1" }; var videoEncoder = new VideoEncoder(); //publisher var mailService = new MailService(); //subscriber var messageService = new MessageService(); //subscriber videoEncoder.VideoEncoded += mailService.OnVideoEncoded; //+= registers Event Handler (mandatory) //Uses raised event (OnVideoEncoded) videoEncoder.VideoEncoded += messageService.OnVideoEncoded; //no brackets() NOT CALLING METHOD AT ALL, just a reference or pointer videoEncoder.Encode(ourVideo); }
static void Main(string[] args) { VideoEncoder vduEnc = new VideoEncoder(); Video vdu = new Video("MyVideo"); // publisher MailService mailService = new MailService(); // subscriber MessageService msgService = new MessageService(); vduEnc.VideoEncoded += mailService.OnVideoEncoded; vduEnc.VideoEncoded += msgService.OnVideoEncoded; vduEnc.VideoEncoded += (object source, VideoEventArgs e) => { Console.WriteLine("From lambda " + e.Video.Title); }; vduEnc.VideoStartEncoding += (object source, VideoEventArgs e) => { Console.WriteLine("Start video encoding."); }; vduEnc.Encode(vdu); }
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); Console.WriteLine("press any key"); Console.ReadLine(); }
public void Main(string [] args) { var video = new Video() { Title = "Video 1" }; // Publisher var videoEncoder = new VideoEncoder(); // Subscriber var mailService = new MailService(); // OnVideoEncoded is the handler videoEncoder.VideoEncoded += mailService.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 massageService = new MessageService(); //subscriber //reference here not calling videoEncoder.VideoEncoded += mailService.OnVideoEncoded; videoEncoder.VideoEncoded += massageService.OnVideoEncoded; videoEncoder.Encode(video); Console.ReadLine(); }
static void Main(string[] args) { var video = new Video() { Title = "Video1" }; var videoEncoder = new VideoEncoder(); // publisher var mailService = new MailService(); // subscriber var messageService = new MessageService(); // subscriber videoEncoder.VideoEncoded += mailService.OnVideoEncoded; // registering a handler to the event(which is OnVideoEncoded (event handler) in mail service) videoEncoder.VideoEncoded += messageService.OnVideoEncoded; // registering a handler to the event(which is OnVideoEncoded (event handler) in message service) videoEncoder.Encode(video); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); Vedio vd = new Vedio() { tittle = "Vedio1" }; VedioEncoder vdEncoder = new VedioEncoder(); // Publisher MailService mailSer = new MailService(); //Subscriber MessageService msgSer = new MessageService(); //Subscriber //Subscription // += means register the handler vdEncoder.VedioEncoded += mailSer.OnVedioEnCoded; //I m not using any [OnVedioEnCoded()] bracket here.. name of the method. [mailSer.OnVedioEnCoded;] means ref for a pointer to that method vdEncoder.VedioEncoded += msgSer.OnMessageEncoded; vdEncoder.Encode(vd); }
static void Main(string[] args) { var video = new Video() { Title = "The Lonely Shepherd" }; var videoEncoder = new VideoEncoder(); // Publisher var mailService = new MailService(); // Subscriber var messageService = new MessageService(); // Subscriber videoEncoder.VideoEnconded += mailService.OnVideoEnconded; // Add method *event reference videoEncoder.VideoEnconded += messageService.OnVideoEncoded; // Add another method *event reference /* This way, we have to make changes to VideoEncoder class? * We do not net to change that class anymore, the only thing we have to do * does not need recompilation and redeployment. * We can add another class, nothing will be affected in the VideoEncoder class. */ videoEncoder.Encode(video); }
static void Main(string[] args) { Video video = new Video() { Title = "Around the World in ..." }; VideoEncoder encoder = new VideoEncoder(); var mailservice = new MailService(); var messageService = new MessageService(); var rssService = new RssService(); encoder.VideoEncoded += mailservice.OnVideoEncoded; encoder.VideoEncoded += messageService.OnVideoEncoded; encoder.VideoEncoding += messageService.OnVideoEncoding; encoder.VideoEncoded += rssService.OnVideoEncoded; encoder.VideoEncrypted += mailservice.OnVideoEncrypted; encoder.Encode(video); encoder.Encrypt(video); }
static void Main(string[] args) { var video = new Video() { Title = "Video Exemplo" }; //var videoEncoder = new VideoEncoderNormal(); var videoEncoder = new VideoEncoderUsingEvents(); // publisher var mailService = new MailService(); // subscriber var messageService = new MessageService(); // subscriber videoEncoder.VideoEncoded += mailService.OnVideoEncoded; videoEncoder.VideoEncoded += messageService.OnVideoEncoded; videoEncoder.Encode(video); Console.WriteLine("Press a key to close..."); Console.ReadKey(); }
static void Main(string[] args) { var geek = new Geek() { Name = "Dachi", Mail = "*****@*****.**", Phone = "123456789", WebSite = "soydachi.com" }; var contacts = new Contacts(); // publisher var mailService = new MailService(); // subscriber var messageService = new MessageService(); // suscriber contacts.ContactEventHandler += mailService.OnSendMailToGeek; contacts.ContactEventHandler += messageService.OnSendMessageToGeek; contacts.GetAGeek(geek); Console.ReadLine(); }
//get an event name from xml static void Main(string[] args) { var video = new Video { Title = "video 1" }; var mailService = new MailService(); var a = typeof(MailService).GetMethod("OnVideoEncoded", new Type[] { typeof(VideoEventArgs) }); //a.MakeGenericMethod var del = Delegate.CreateDelegate(typeof(Action <MailService, VideoEventArgs>), a); Action <object, object> caller = (instance, param) => del.DynamicInvoke(instance, param); caller(mailService, new VideoEventArgs { Video = video }); // EventAggregator.Subscribe<VideoEventArgs>(caller); var msgService = new MessageService(); var temp = new TempService(); var videoEncoder = new VideoEncoder(); //videoEncoder.VideoEncoded += mailService.OnVideoEncoded; videoEncoder.Encode(video); Console.ReadKey(); }
static void Main(string[] args) { // instantiate the video object. This one's Ariel aww! var ariel = new Video() { Title = "Ariel" }; // instantiate the encoder object. this is the EVENT PUBLISHER var videoEncoder = new VideoEncoder(); // instantiate a new mail service an a new messag service. // This is the EVENT SUBSCRIBER var mailService = new MailService(); var messageService = new MessageService(); // before we encode a video, we have to start the subscription. We didn't have to // change anything about the VideoEncoder! Wejust added a new class up there MessageService // whi hhas inside it an OnVideoEncoded method videoEncoder.VideoEncoded += mailService.OnVideoEncoded; videoEncoder.VideoEncoded += messageService.OnVideoEncoded; // call Encode method on your new encoder, passing in the Ariel video as parameter videoEncoder.Encode(ariel); Console.ReadKey(); // publisher /event sender; subscriber/ event receiver // an EVENT is a method that notifies the subscribers /*A DELEGATE is a contract between the publisher and the subscriber bitlike an * interface * */ }
static void Main(string[] args) { // Create video and encoder var video = new Video() { Title = "Video 1" }; var videoEncoder = new VideoEncoder(); // publisher // Create mail and message service var mailService = new MailService(); // subscriber var messageService = new MessageService(); // subscriber // Subscribe by adding reference to mailService function // Note: no brackets videoEncoder.VideoEncoded += mailService.OnVideoEncoded; videoEncoder.VideoEncoded += messageService.OnVideoEncoded; // Encode video videoEncoder.Encode(video); // Wait to show output Console.ReadLine(); }
static void Main(string[] args) { var video = new Video() { Title = "The Lonely Shepherd" }; var videoEncoder = new VideoEncoder(); // Publisher var mailService = new MailService(); // Subscriber var messageService = new MessageService(); // Subscriber videoEncoder.VideoEnconded += mailService.OnVideoEnconded; // Add method *event reference videoEncoder.VideoEnconded += messageService.OnVideoEncoded; // Add another method *event reference /* This way, we have to make changes to VideoEncoder class? We do not net to change that class anymore, the only thing we have to do does not need recompilation and redeployment. We can add another class, nothing will be affected in the VideoEncoder class. */ videoEncoder.Encode(video); }