static void Main(string[] args) { TimeOfCame t1 = new TimeOfCame { TimeCame = DateTime.Parse("6:00") }; TimeOfCame t2 = new TimeOfCame { TimeCame = DateTime.Parse("9:00") }; TimeOfCame t3 = new TimeOfCame { TimeCame = DateTime.Parse("12:00") }; TimeOfCame t4 = new TimeOfCame { TimeCame = DateTime.Parse("19:00") }; Person john = new Person { Name = "Egor", TimeCame = t1 }; Person bill = new Person { Name = "Albina", TimeCame = t2 }; Person hugo = new Person { Name = "Kirill", TimeCame = t3 }; Person ivan = new Person { Name = "Bulat", TimeCame = t4 }; john.Came += Handler1; john.MyMethod1(); bill.Came += Handler1; bill.MyMethod1(); hugo.Came += Handler1; hugo.MyMethod1(); bill.Leave += Handler2; bill.MyMethod2(); ivan.Came += Handler1; ivan.MyMethod1(); hugo.Leave += Handler2; hugo.MyMethod2(); ivan.Leave += Handler2; ivan.MyMethod2(); john.Leave += Handler2; john.MyMethod2(); Console.ReadKey(); }
public virtual void OnCame(Person p, TimeOfCame t) { if (p.Came != null) { p.Came(p, t); } }
public virtual void OnLeave(Person p) { if (p.Leave != null) { p.Leave(p); } }
static void Main(string[] args) { Office Office1 = new Office(); Person john = new Person { Name = "John"}; Person bill = new Person { Name = "Bill"}; Person hugo = new Person { Name = "Hugo"}; Person ivan = new Person { Name = "Ivan"}; TimeOfCame t1 = new TimeOfCame { TimeCame = DateTime.Parse("7:00") }; TimeOfCame t2 = new TimeOfCame { TimeCame = DateTime.Parse("11:00") }; TimeOfCame t3 = new TimeOfCame { TimeCame = DateTime.Parse("14:00") }; TimeOfCame t4 = new TimeOfCame { TimeCame = DateTime.Parse("22:00") }; Office1.ComePerson(john, t1); Office1.ComePerson(bill, t2); Office1.ComePerson(hugo, t3); Office1.LeavePerson(bill); Office1.ComePerson(ivan,t4); Office1.LeavePerson(hugo); Office1.LeavePerson(ivan); Office1.LeavePerson(john); Console.ReadKey(); }
static void LeaveHandler(Person p) { if (Part != null) { Part(p); } }
static void CameHandler(Person p, TimeOfCame t) { if (Greet != null) { Greet(p, t); } }
static void Handler2(Person p) { if (Part != null) { Console.WriteLine("[{0} ушел домой]\n", p.Name); Part(p); } else { Console.WriteLine("[{0} ушел домой]\n", p.Name); } }
static void Handler1(Person p, TimeOfCame t) { if (Greet != null) { Console.WriteLine("[{0} пришел на работу]\n", p.Name); Greet(p, p.TimeCame); } else { Console.WriteLine("[{0} пришел на работу]\n", p.Name); } }
public void Greeting(Person anotherPerson, TimeOfCame t) { if (t.TimeCame.Hour < 12) { Console.WriteLine("Доброе утро, {0}! - сказал {1}", anotherPerson.Name, Name); } else if (t.TimeCame.Hour > 17) { Console.WriteLine("Добрый вечер, {0}! - сказал {1}", anotherPerson.Name, Name); } else { Console.WriteLine("Добрый день, {0}! - сказал {1}", anotherPerson.Name, Name); } }
public void Greeting(Person anotherPerson, TimeOfCame t) { if (t.TimeCame.Hour < 12) { Console.WriteLine("Good morning, {0}! - said {1}", anotherPerson.Name, Name); } else if (t.TimeCame.Hour > 17) { Console.WriteLine("Good evening, {0}! - said {1}", anotherPerson.Name, Name); } else { Console.WriteLine("Good afternoon, {0}! - said {1}", anotherPerson.Name, Name); } }
public void LeavePerson(Person p) { Console.WriteLine("[{0} gone to home]\n", p.Name); ListPerson.Remove(p); foreach (var elem in ListPerson) { MessageLeave part = new MessageLeave(elem.Parting); Part += part; } p.Leave += LeaveHandler; p.OnLeave(p); foreach (var elem in ListPerson) { MessageLeave part = new MessageLeave(elem.Parting); Part -= part; } }
public void ComePerson(Person p, TimeOfCame TimeCame) { Console.WriteLine("[{0} came to work]\n", p.Name); foreach (var elem in ListPerson) { MessageCome greet = new MessageCome(elem.Greeting); Greet += greet; } p.Came += CameHandler; p.OnCame(p, TimeCame); foreach (var elem in ListPerson) { MessageCome greet = new MessageCome(elem.Greeting); Greet -= greet; } ListPerson.Add(p); }
public void Parting(Person anotherPerson) { Console.WriteLine("Досвидания, {0}! - сказал {1}", anotherPerson.Name, Name); }
public void LeaveHandler(Person p) { MessageLeave part = new MessageLeave(this.Parting); part(p); }
public void CameHandler(Person p, TimeOfCame t) { MessageCome greet = new MessageCome(this.Greeting); greet(p, t); }
public void Parting(Person anotherPerson) { Console.WriteLine("Good bye, {0}! - said {1}", anotherPerson.Name, Name); }