protected virtual void OnNotificationMessageReceived(MessengerEventArgs eventArgs) { MessengerEventHandler handler = NotificationReceived; if (handler != null) { handler(this, eventArgs); } }
protected virtual void OnAsyncMessageReceived(MessengerEventArgs eventArgs) { MessengerEventHandler handler = AsyncDataReceived; if (handler != null) { handler(this, eventArgs); } }
protected virtual void OnResponseMessageReceived(MessengerEventArgs eventArgs) { MessengerEventHandler handler = ResponseDataReceived; if (handler != null) { handler(this, eventArgs); } }
/// <summary> /// Subscribe class method to a specific message via delegate /// </summary> /// <param name="subscriber">delegate method</param> /// <typeparam name="T">message type</typeparam> public static void Subscribe <T>(MessengerEventHandler <T> subscriber) where T : Message { if (subscriber == null) { throw new System.ArgumentException("subscriber is invalid"); } var key = typeof(T); if (_subscribersDictionary.ContainsKey(key)) { _subscribersDictionary[key] = System.Delegate.Combine(_subscribersDictionary[key], subscriber); } else { _subscribersDictionary.Add(key, subscriber); } }
/// <summary> /// Unsubscribe class to a specific message via delegate /// </summary> /// <param name="subscriber">delegate method</param> /// <typeparam name="T">message type</typeparam> public static void UnSubscribe <T>(MessengerEventHandler <T> subscriber) where T : Message { if (subscriber == null) { throw new System.ArgumentException("Subscriber is invalid"); } var key = typeof(T); if (_subscribersDictionary.ContainsKey(key)) { var value = _subscribersDictionary[key]; value = System.Delegate.Remove(value, subscriber); if (value == null) { _subscribersDictionary.Remove(key); } else { _subscribersDictionary[key] = value; } } }
public static void Prompt(string message, MessageType messageType) { if (prompted == null) prompted = new MessengerEventHandler(messageHandler); prompted(null, new MessengerEventArgs(message, messageType)); }