Exemplo n.º 1
0
    public void FireChangeEvent(ProtocolFeature feature)
    {
        List <Component> listListener;

        if (this.pushEventListener.TryGetValue(feature, out listListener) == false)
        {
            return;
        }

        List <Component> observerToRemove = new List <Component> ();

        foreach (Component observer in listListener)
        {
            if (observer == null)
            {
                observerToRemove.Add(observer);
            }
            else
            {
                observer.SendMessage(EnumUtil.GetString(feature), null, SendMessageOptions.DontRequireReceiver);
            }
        }

        // 删除无用的观察者
        foreach (Component observer in observerToRemove)
        {
            listListener.Remove(observer);
        }
    }
Exemplo n.º 2
0
    public bool RemoveObserver(ProtocolFeature feature, Component observer)
    {
        List <Component> listListener;

        if (this.pushEventListener.TryGetValue(feature, out listListener) == false)
        {
            return(false);
        }

        return(listListener.Remove(observer));
    }
Exemplo n.º 3
0
    public bool AddNotification(ProtocolFeature feature, Component observer)
    {
        List <Component> listListener;

        if (this.pushEventListener.TryGetValue(feature, out listListener) == false)
        {
            listListener = new List <Component> ();
            this.pushEventListener [feature] = listListener;
        }

        if (listListener.Contains(observer))
        {
            return(false);
        }

        listListener.Add(observer);
        return(true);
    }