Ejemplo n.º 1
0
    public override void Unsubscribe <TEvent>(Func <TEvent, Task> action)
    {
        Check.NotNull(action, nameof(action));

        GetOrCreateHandlerFactories(typeof(TEvent))
        .Locking(factories =>
        {
            factories.RemoveAll(
                factory =>
            {
                if (!(factory is SingleInstanceHandlerFactory singleInstanceFactory))
                {
                    return(false);
                }

                if (!(singleInstanceFactory.HandlerInstance is ActionEventHandler <TEvent> actionHandler))
                {
                    return(false);
                }

                return(actionHandler.Action == action);
            });
        });

        Rebus.Unsubscribe(typeof(TEvent));
    }
Ejemplo n.º 2
0
    protected async override Task PublishToEventBusAsync(Type eventType, object eventData)
    {
        if (AbpRebusEventBusOptions.Publish != null)
        {
            await AbpRebusEventBusOptions.Publish(Rebus, eventType, eventData);

            return;
        }

        await Rebus.Publish(eventData);
    }
Ejemplo n.º 3
0
    public override void Unsubscribe(Type eventType, IEventHandler handler)
    {
        GetOrCreateHandlerFactories(eventType)
        .Locking(factories =>
        {
            factories.RemoveAll(
                factory =>
                factory is SingleInstanceHandlerFactory handlerFactory &&
                handlerFactory.HandlerInstance == handler
                );
        });

        Rebus.Unsubscribe(eventType);
    }
Ejemplo n.º 4
0
    public override IDisposable Subscribe(Type eventType, IEventHandlerFactory factory)
    {
        var handlerFactories = GetOrCreateHandlerFactories(eventType);

        if (factory.IsInFactories(handlerFactories))
        {
            return(NullDisposable.Instance);
        }

        handlerFactories.Add(factory);

        if (handlerFactories.Count == 1) //TODO: Multi-threading!
        {
            Rebus.Subscribe(eventType);
        }

        return(new EventHandlerFactoryUnregistrar(this, eventType, factory));
    }
Ejemplo n.º 5
0
    protected virtual async Task PublishAsync(
        Type eventType,
        object eventData,
        Guid?eventId = null,
        Dictionary <string, string> headersArguments = null)
    {
        if (AbpRebusEventBusOptions.Publish != null)
        {
            await AbpRebusEventBusOptions.Publish(Rebus, eventType, eventData);

            return;
        }

        headersArguments ??= new Dictionary <string, string>();
        if (!headersArguments.ContainsKey(Headers.MessageId))
        {
            headersArguments[Headers.MessageId] = (eventId ?? GuidGenerator.Create()).ToString("N");
        }

        await Rebus.Publish(eventData, headersArguments);
    }
Ejemplo n.º 6
0
        /// <summary>
        /// Convert a bidimensional int array into a <see cref="List{<see cref="Rebus"/>}"/>
        /// </summary>
        /// <param name="matrix"></param>
        /// <param name="xmax"></param>
        /// <param name="ymax"></param>
        public void Test(int[,] matrix, int xmax, int ymax)
        {
            int i = 1, x, y;
            Rebus temp;

            //horizontal

            for (x = 0; x < xmax; x++)
            {
                y = 0;
                while (y < ymax - 1)
                {
                    if (matrix[x, y] != 0)
                    {
                        if (matrix[x, y + 1] != 0)
                        {
                            temp = new Rebus { length = 0, xorigin = x, yorigin = y, Id = i, orient = Orientation.Horizontal, intersects = new List<Intersect>() };
                            do
                            {
                                temp.length++;
                                matrix[x, y] = i;
                                y++;
                            } while (y < ymax && matrix[x, y] != 0);
                            arr.Add(temp);
                            i++;
                        }
                        else
                            y++;
                    }
                    else y++;
                }
            }

            //vertical
            for (y = 0; y < ymax; y++)
            {
                x = 0;
                while (x < xmax - 1)
                {
                    if (matrix[x, y] != 0)
                    {
                        if (matrix[x + 1, y] != 0)
                        {
                            temp = new Rebus { length = 0, xorigin = x, yorigin = y, Id = i, orient = Orientation.Vertical, intersects = new List<Intersect>() };
                            do
                            {
                                temp.length++;
                                if (matrix[x, y] != -1)
                                {
                                    arr[matrix[x, y] - 1].intersects.Add(new Intersect() { xIntersect = x, yIntersect = y, IntersectId = i });
                                    temp.intersects.Add(new Intersect() { xIntersect = x, yIntersect = y, IntersectId = matrix[x, y] });
                                }
                                matrix[x, y] = i;
                                x++;
                            } while (x < xmax && matrix[x, y] != 0);
                            arr.Add(temp);
                            i++;
                        }
                        else
                            x++;
                    }
                    else
                        x++;
                }
            }
        }
Ejemplo n.º 7
0
 public override void UnsubscribeAll(Type eventType)
 {
     GetOrCreateHandlerFactories(eventType).Locking(factories => factories.Clear());
     Rebus.Unsubscribe(eventType);
 }
Ejemplo n.º 8
0
 public override void Unsubscribe(Type eventType, IEventHandlerFactory factory)
 {
     GetOrCreateHandlerFactories(eventType).Locking(factories => factories.Remove(factory));
     Rebus.Unsubscribe(eventType);
 }