Ejemplo n.º 1
0
        private void NotifyImmediately(T name, IEventBusArgs arg = null)
        {
            isNotifying = true;
            CommitCallbackChanges();
            var success = _callbacks.TryGetValue(name, out var callbacks);

            if (success)
            {
                for (var i = 0; i < callbacks.Count; i++)
                {
                    callbacks[i].Invoke(arg);
                }
            }
            CommitCallbackChanges();
            isNotifying = false;
        }
Ejemplo n.º 2
0
 public void Notify(T name, IEventBusArgs arg = null)
 {
     //NotifyImmediately(name, arg);
     if (isNotifying)
     {
         _toNotify.Add(new Tuple <T, IEventBusArgs>(name, arg));
     }
     else
     {
         NotifyImmediately(name, arg);
         while (_toNotify.Count > 0)
         {
             NotifyImmediately(_toNotify[0].Item1, _toNotify[0].Item2);
             _toNotify.RemoveAt(0);
         }
     }
 }
Ejemplo n.º 3
0
        void _publish(IEventBusArgs <TEvent> args)
        {
            var unsubs = new List <Guid>();

            var invokeSub = new Action <Subscriber>(sub =>
            {
                if (!sub.Reference.IsAlive)
                {
                    unsubs.Add(sub.Id);
                    return;
                }

                try
                {
                    sub.Action.Invoke(args);
                }
                catch (Exception ex)
                {
                    OnError?.Invoke(this, new EventBusHandlerArgs <EventBusException>(new EventBusException(_errorSubscriberInvoke, ex)));
                }
            });

            lock (_locker)
            {
                foreach (var anySub in _anyEventSubs)
                {
                    invokeSub(anySub.Value);
                }

                if (_eventSubs.ContainsKey(args.Event))
                {
                    foreach (var eventSub in _eventSubs[args.Event])
                    {
                        invokeSub(eventSub.Value);
                    }
                }
            }

            if (unsubs.Count > 0)
            {
                _unsubscribe(unsubs);
            }
        }
Ejemplo n.º 4
0
 public void OnPublish(IEventBusArgs <Event> e)
 {
     Console.WriteLine($"{e.Event}: {e.Data.FirstOrDefault()} ({this.GetType().Name})");
 }
Ejemplo n.º 5
0
 public void OnPublish(IEventBusArgs <Event> e)
 {
     Console.WriteLine($"{e.Event}: {e.Data.FirstOrDefault()} ({this.GetType().Name})");
     _eventBus.Value.Publish(this, Event.E3, "test3");
 }
Ejemplo n.º 6
0
 public void OnPublish(IEventBusArgs <Event> e)
 {
     Console.WriteLine($"{e.Event}: {e.Data.FirstOrDefault()} ({this.GetType().Name})");
     //e.Host.Publish(this, Event.E1, "retest 1");
 }