// Copyright © 2017 Dmitry Sikorsky. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; using System.Linq; using ExtCore.Infrastructure; namespace ExtCore.Events { /// /// Represents an event that can be broadcasted and handled by the corresponding event handlers /// specified by the TEventHandler type parameter. The event handlers /// might be located in this or any other extension and will be resolved automatically by ExtCore. /// /// Defines the type of the event handlers that will handle the event. public static class Event where TEventHandler : IEventHandler { /// /// Broadcasts the event to all the event handlers that are resolved automatically by ExtCore. /// /// Resolved event handlers that have handled the event. public static IEnumerable Broadcast() { IEnumerable eventHandlers = ExtensionManager.GetInstances().OrderBy(eh => eh.Priority); foreach (TEventHandler eventHandler in eventHandlers) eventHandler.HandleEvent(); return eventHandlers; } } /// /// Represents an event that can be broadcasted and handled by the corresponding event handlers /// specified by the TEventHandler type parameter. The event handlers /// might be located in this or any other extension and will be resolved automatically by ExtCore. /// /// Defines the type of the event handlers that will handle the event. /// Defines the type of the argument that will be passed to the event handlers. public static class Event where TEventHandler : IEventHandler { /// /// Broadcasts the event to all the event handlers that are resolved automatically by ExtCore. /// /// The event argument. /// Resolved event handlers that have handled the event. public static IEnumerable Broadcast(TEventArgument argument) { IEnumerable eventHandlers = ExtensionManager.GetInstances().OrderBy(eh => eh.Priority); foreach (TEventHandler eventHandler in eventHandlers) eventHandler.HandleEvent(argument); return eventHandlers; } } /// /// Represents an event that can be broadcasted and handled by the corresponding event handlers /// specified by the TEventHandler type parameter. The event handlers /// might be located in this or any other extension and will be resolved automatically by ExtCore. /// /// /// Defines the type of the event handlers that will handle the event. /// Defines the type of the first argument that will be passed to the event handlers. /// Defines the type of the second argument that will be passed to the event handlers. public static class Event where TEventHandler : IEventHandler { /// /// Broadcasts the event to all the event handlers that are resolved automatically by ExtCore. /// /// The first event argument. /// The second event argument. /// Resolved event handlers that have handled the event. public static IEnumerable Broadcast(TEventArgument1 argument1, TEventArgument2 argument2) { IEnumerable eventHandlers = ExtensionManager.GetInstances().OrderBy(eh => eh.Priority); foreach (TEventHandler eventHandler in eventHandlers) eventHandler.HandleEvent(argument1, argument2); return eventHandlers; } } /// /// Represents an event that can be broadcasted and handled by the corresponding event handlers /// specified by the TEventHandler type parameter. The event handlers /// might be located in this or any other extension and will be resolved automatically by ExtCore. /// /// Defines the type of the event handlers that will handle the event. /// Defines the type of the first argument that will be passed to the event handlers. /// Defines the type of the second argument that will be passed to the event handlers. /// Defines the type of the third argument that will be passed to the event handlers. public static class Event where TEventHandler : IEventHandler { /// /// Broadcasts the event to all the event handlers that are resolved automatically by ExtCore. /// /// The first event argument. /// The second event argument. /// The third event argument. /// Resolved event handlers that have handled the event. public static IEnumerable Broadcast(TEventArgument1 argument1, TEventArgument2 argument2, TEventArgument3 argument3) { IEnumerable eventHandlers = ExtensionManager.GetInstances().OrderBy(eh => eh.Priority); foreach (TEventHandler eventHandler in eventHandlers) eventHandler.HandleEvent(argument1, argument2, argument3); return eventHandlers; } } }