public int JoinTheParty(string guestName) { // Subscribe the guest to the beer inventory IBeerInventoryCallback guest = OperationContext.Current.GetCallbackChannel <IBeerInventoryCallback>(); if (!_callbackList.Contains(guest)) { _callbackList.Add(guest); } _callbackList.ForEach(delegate(IBeerInventoryCallback callback) { callback.NotifyGuestJoinedParty(guestName); }); return(_beerInventory); }
public void LeaveTheParty(string guestName) { // Unsubscribe the guest from the beer inventory IBeerInventoryCallback guest = OperationContext.Current.GetCallbackChannel <IBeerInventoryCallback>(); if (_callbackList.Contains(guest)) { _callbackList.Remove(guest); } // Notify everyone that guest has arrived. // Use an anonymous delegate and generics to do our dirty work. _callbackList.ForEach(delegate(IBeerInventoryCallback callback) { callback.NotifyGuestLeftParty(guestName); }); }