Exemplo n.º 1
0
    internal void Dispatch()
    {
        if (!this.IsAlive)
        {
            Destroy();
            return;
        }

        int index = 0;

        while (index < _listenerList.Count)
        {
            ListenerObject listener = _listenerList[index];

            if (listener.IsAlive)
            {
                listener.Callback(this);
                index++;
            }
            else
            {
                UnregisterEventListenerObject(listener);
            }
        }

        if (_listenerList.Count <= 0)
        {
            Destroy();
        }
    }
Exemplo n.º 2
0
 internal void UnregisterEventListenerObject(ListenerObject aListener)
 {
     if (aListener != null && _listenerList.Contains(aListener))
     {
         _listenerList.Remove(aListener);
     }
 }
Exemplo n.º 3
0
    internal void RegisterEventListener(object aListener, Action <EventObject> aMethod, int aPriority = 1)
    {
        ListenerObject listener = new ListenerObject(aListener, aMethod, aPriority);

        _listenerList.Add(listener);
        _listenerList = _listenerList.OrderBy(o => o.Priority).ToList <ListenerObject>();
    }
Exemplo n.º 4
0
    internal void UnregisterEventListener(object aListener, Action <EventObject> aMethod = null)
    {
        int  index        = 0;
        bool eventRemoved = false;

        while (!eventRemoved)
        {
            if (index >= _listenerList.Count)
            {
                break;
            }

            ListenerObject listener = _listenerList[index];
            if ((listener.ObjectReference.Equals(aListener) && aMethod != null && listener.Callback.Equals(aMethod)) ||
                (listener.ObjectReference.Equals(aListener) && aMethod == null))
            {
                UnregisterEventListenerObject(listener);
                eventRemoved = true;
            }
            else
            {
                if (listener.IsAlive)
                {
                    index++;
                }
                else
                {
                    UnregisterEventListenerObject(listener);
                }
            }
        }

        if (!eventRemoved)
        {
            string prefix = "";
            if (aMethod != null)
            {
                prefix += "The method [" + aMethod.ToString() + "] from ";
            }
            Debug.LogWarning("[EventObject.cs] - UnregisterEventListener() - " + prefix + aListener.ToString() + "] doesn't seem to be registered for the event: " + _event + ".");
        }

        if (_listenerList.Count <= 0)
        {
            Destroy();
        }
    }
        public void StopListeningWhenObjectGarbageCollected()
        {
            int value  = 0;
            var events = new EventManager();

            var listener = new ListenerObject(events, v => value = v);

            events.Publish(2);
            value.Should().Be(3);

            listener = null;

            GC.Collect();

            events.Publish(-1);
            value.Should().Be(3);
        }
    public static void Main(string[] args) {
    bool debugOn = false;
    if (args.Length > 0) {
      try {
        debugOn = Convert.ToBoolean(args[0]);
      } catch (Exception) {
        debugOn = false;
      }
    }

    RedBlackTree<PersonKey, Person> tree = new RedBlackTree<PersonKey, Person>(debugOn);
	ListenerObject listener = new ListenerObject();
    CollectionChangedEventManager.AddListener(tree, listener);
    
    Person p1 = new Person("Deekster", "Willis", "Jaybones", Person.Sex.MALE, new DateTime(1966, 02, 19));
    Person p2 = new Person("Knut", "J", "Hampson", Person.Sex.MALE, new DateTime(1972, 04, 23));
    Person p3 = new Person("Katrina", "Kataline", "Kobashar", Person.Sex.FEMALE, new DateTime(1982, 09, 3));
    Person p4 = new Person("Dreya", "Babe", "Weber", Person.Sex.FEMALE, new DateTime(1978, 11, 25));
    Person p5 = new Person("Sam", "\"The Guitar Man\"", "Miller", Person.Sex.MALE, 
                           new DateTime(1988, 04, 16));
    
    try{	
    tree.Add(p1.Key, p1);
    tree.Add(p2.Key, p2);
    tree.Add(p3.Key, p3);
    tree.Add(p4.Key, p4);
    tree.Add(p5.Key, p5);   
   }catch(Exception ex){
     Console.WriteLine(ex);
    }   
  
    tree.PrintTreeStats();
    Console.WriteLine("Original insertion order:");
    Console.WriteLine(p1);
    Console.WriteLine(p2);
    Console.WriteLine(p3);
    Console.WriteLine(p4);
    Console.WriteLine(p5);
  
    Console.WriteLine("-------------------------------------------------");
    Console.WriteLine("Sorted Order:");
    tree.PrintTreeToConsole();
	
	} // end Main()
Exemplo n.º 7
0
	internal void UnregisterEventListenerObject(ListenerObject aListener)
	{
	    if (aListener != null && _listenerList.Contains(aListener))
	    {
	        _listenerList.Remove(aListener);
	    }
	}
Exemplo n.º 8
0
	internal void RegisterEventListener(object aListener, Action<EventObject> aMethod, int aPriority = 1)
	{
	    ListenerObject listener = new ListenerObject(aListener, aMethod, aPriority);
	    _listenerList.Add(listener);
	    _listenerList = _listenerList.OrderBy(o => o.Priority).ToList<ListenerObject>();

	}