Beispiel #1
0
    /// <summary>
    /// Remove the specified observer.
    /// </summary>
    public void RemoveObserver(IObserver observer)
    {
        if (observer == null || _observers.Count == 0)
        {
            return;
        }

        var enumerator = _observers.GetEnumerator();

        while (enumerator.MoveNext())
        {
            R.Id message = enumerator.Current.Key;
            List <WeakReference> observers = _observers[message];
            if ((observers == null || observers.Count == 0) == false)
            {
                observers.RemoveAll(IsExpiredObserver);

                for (int i = 0; i < observers.Count; i++)
                {
                    WeakReference weakReference = observers[i];
                    if (IsEquals(weakReference, observer))
                    {
                        observers.RemoveAt(i);
                        break;
                    }
                }
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// Remove the specified observer.
    /// </summary>
    public void RemoveObserver(IObserver observer, R.Id message)
    {
        if (observer == null || !_observers.ContainsKey(message))
        {
            return;
        }

        List <WeakReference> observers = _observers[message];

        if ((observers == null || observers.Count == 0) == false)
        {
            for (int i = 0; i < observers.Count; i++)
            {
                WeakReference weakReference = observers[i];
                if (IsEquals(weakReference, observer))
                {
                    observers.RemoveAt(i);
                    break;
                }
            }

            if (observers.Count == 0)
            {
                _observers.Remove(message);
            }
        }
    }
Beispiel #3
0
    public static Notification Create(R.Id id)
    {
        Notification notification = Create();

        notification.id = id;
        return(notification);
    }
Beispiel #4
0
    public static Notification Create(R.Id id, float data)
    {
        Notification notification = Create();

        notification.id         = id;
        notification.floatExtra = data;
        return(notification);
    }
Beispiel #5
0
    public static Notification Create(R.Id id, long data)
    {
        Notification notification = Create();

        notification.id        = id;
        notification.longExtra = data;
        return(notification);
    }
Beispiel #6
0
    public static Notification Create(R.Id id, bool data)
    {
        Notification notification = Create();

        notification.id        = id;
        notification.boolExtra = data;
        return(notification);
    }
Beispiel #7
0
    public static Notification Create(R.Id id, object data)
    {
        Notification notification = Create();

        notification.id        = id;
        notification.dataExtra = data;
        return(notification);
    }
Beispiel #8
0
 public Notification()
 {
     this.id     = R.Id.None;
     intExtra    = 0;
     floatExtra  = 0f;
     stringExtra = string.Empty;
     longExtra   = 0;
     boolExtra   = false;
     dataExtra   = null;
 }
Beispiel #9
0
 public void Clear()
 {
     id          = R.Id.None;
     intExtra    = 0;
     floatExtra  = 0f;
     stringExtra = string.Empty;
     longExtra   = 0;
     boolExtra   = false;
     dataExtra   = null;
 }
Beispiel #10
0
 public Notification(R.Id id, object data)
 {
     this.id     = id;
     intExtra    = 0;
     floatExtra  = 0f;
     stringExtra = string.Empty;
     longExtra   = 0;
     boolExtra   = false;
     dataExtra   = data;
 }
Beispiel #11
0
 public Notification(R.Id id, bool data)
 {
     this.id     = id;
     intExtra    = 0;
     floatExtra  = 0f;
     stringExtra = string.Empty;
     longExtra   = 0;
     boolExtra   = data;
     dataExtra   = null;
 }
Beispiel #12
0
 public Notification(R.Id id, string data)
 {
     this.id     = id;
     intExtra    = 0;
     floatExtra  = 0f;
     stringExtra = data;
     longExtra   = 0;
     boolExtra   = false;
     dataExtra   = null;
 }
Beispiel #13
0
    private void InteralAddObserver(ref Dictionary <R.Id, List <WeakReference> > container
                                    , IObserver observer, R.Id message)
    {
        if (!container.ContainsKey(message))
        {
            container[message] = new List <WeakReference>();
        }

        List <WeakReference> observers = container[message];
        bool isContains = IsContains(observers, observer);

        if (isContains == false)
        {
            container[message].Add(new WeakReference(observer));
        }
    }
Beispiel #14
0
    private void RemoveObserver(ref Dictionary <R.Id, List <WeakReference> > container
                                , R.Id message)
    {
        if (container == null || !container.ContainsKey(message))
        {
            return;
        }

        List <WeakReference> observers = container[message];

        if ((observers == null || observers.Count == 0) == false)
        {
            observers.Clear();
            observers = null;
        }

        container.Remove(message);
    }
Beispiel #15
0
 /// <summary>
 /// Add a disposable observer for the specific message.
 /// </summary>
 public void AddDisposableObserver(IObserver observer, R.Id message)
 {
     InteralAddObserver(ref _disposableObservers, observer, message);
 }
Beispiel #16
0
 public static void PostDelayed(R.Id id)
 {
     PostDelayed(Notification.Create(id));
 }
Beispiel #17
0
 public static void Post(R.Id id)
 {
     Instance.InternalPost(Notification.Create(id));
 }
Beispiel #18
0
 /// <summary>
 /// Add an observer for the specific message.
 /// </summary>
 public void AddObserver(IObserver observer, R.Id message)
 {
     InteralAddObserver(ref _observers, observer, message);
 }
Beispiel #19
0
 public static void Post(R.Id id, object data)
 {
     Instance.InternalPost(Notification.Create(id, data));
 }