Пример #1
0
    protected virtual void OnNotificationMessageReceived(MessengerEventArgs eventArgs)
    {
        MessengerEventHandler handler = NotificationReceived;

        if (handler != null)
        {
            handler(this, eventArgs);
        }
    }
Пример #2
0
    protected virtual void OnAsyncMessageReceived(MessengerEventArgs eventArgs)
    {
        MessengerEventHandler handler = AsyncDataReceived;

        if (handler != null)
        {
            handler(this, eventArgs);
        }
    }
Пример #3
0
    protected virtual void OnResponseMessageReceived(MessengerEventArgs eventArgs)
    {
        MessengerEventHandler handler = ResponseDataReceived;

        if (handler != null)
        {
            handler(this, eventArgs);
        }
    }
Пример #4
0
    /// <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);
        }
    }
Пример #5
0
    /// <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;
            }
        }
    }
Пример #6
0
 public static void Prompt(string message, MessageType messageType)
 {
     if (prompted == null)
         prompted = new MessengerEventHandler(messageHandler);
     prompted(null, new MessengerEventArgs(message, messageType));
 }