public void AddEvent(ICherryEvent ce) { if (this.events.ContainsKey(ce.Name)) { var message = string.Format("The event named '{0}' is already registered.", ce.Name); throw new PluginException(message); } this.events[ce.Name] = ce; }
public void AddEvent(ICherryEvent ce) { if (this.events.ContainsKey(ce.Name)) { var message = string.Format("The event named '{0}' is already registered.", ce.Name); throw new PluginException(message); } this.events[ce.Name] = ce; }
/// <summary> /// Subscribes the listener to a its event. /// </summary> /// <param name="listener"> /// The listener object which knows what to subscribe to and the action to perform. /// </param> /// <param name="throwException">Should PluginException be thrown in case there is no such event.</param> /// <returns>True if subscription succeeded; otherwise - false.</returns> public bool Subscribe(ICherryEventListener listener, bool throwException = true) { ICherryEvent ce = null; if (this.events.TryGetValue(listener.ListenTo, out ce)) { return(ce.AddListener(listener)); } if (throwException) { throw new PluginException(string.Format("'{0}' event not found.", listener.ListenTo)); } else { return(false); } }