public void task() { var hatchery = new Hatchery(); //publisher while (true) { var buyingService = new BuyingService(); Console.WriteLine(" For Rui - 1\n For Katla - 2\n For Ilish - 3\n"); int fishNo = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter amount to buy - "); int amount = Convert.ToInt32(Console.ReadLine()); if (fishNo == 1) { hatchery.FishEvent += buyingService.OnRuiBuy; hatchery.RaiseEvent(amount); hatchery.FishEvent -= buyingService.OnRuiBuy; } if (fishNo == 2) { hatchery.FishEvent += buyingService.OnKatlaBuy; hatchery.RaiseEvent(amount); hatchery.FishEvent -= buyingService.OnKatlaBuy; } if (fishNo == 3) { hatchery.FishEvent += buyingService.OnIlishBuy; hatchery.RaiseEvent(amount); hatchery.FishEvent -= buyingService.OnIlishBuy; } Console.WriteLine("Available Fish -\n Rui - {0}\n Katla - {1}\n Ilish - {2}\n", FishTank.rui, FishTank.katla, FishTank.ilish); } }
static void Main(string[] args) { var hatchery = new Hatchery(); //publisher var sellService = new SellingService(); //subscriber var buyService = new BuyingService(); Console.WriteLine("For Customer (To decrease Fish) Application press - 1"); Console.WriteLine("For Owner (To increase Fish) Application press - 2"); int userType = Convert.ToInt32(Console.ReadLine()); if (userType == 1) { Customer customer = new Customer(); customer.task(); } if (userType == 2) { Owner owner = new Owner(); owner.task(); } }