private ControlOutput Trigger(Flow flow) { if (eventType == null) { return(exit); } var eventInstance = System.Activator.CreateInstance(eventType); for (var i = 0; i < inputPorts.Count; i++) { var inputPort = inputPorts[i]; var key = inputPort.key; var value = flow.GetValue(inputPort); if (Info.reflectedFields.ContainsKey(key)) { var reflectedField = Info.reflectedFields[key]; reflectedField.SetValue(eventInstance, value); } else if (Info.reflectedProperties.ContainsKey(key)) { var reflectedProperty = Info.reflectedProperties[key]; reflectedProperty.SetValue(eventInstance, value); } } GlobalDefinedEventNode.Trigger(eventInstance); return(exit); }
/// <summary> /// Registers a C# listener for an event globally. This is the scripting /// equivalent to the Global Defined Event unit. Notice the IDisposable return /// value, which allows you to end the subscription for the event (via calling /// the .Dispose() method). /// </summary> /// <typeparam name="T">The type to listen for.</typeparam> /// <param name="onEvent">The action or method to call when the event occurs</param> /// <returns>A disposable that, when .Dispose is called, will unsubscribe from the /// event, essentially cancelling the call to RegisterListener.</returns> public static IDisposable RegisterGlobalListener <T>(Action <T> onEvent) { return(GlobalDefinedEventNode.RegisterListener <T>(onEvent)); }
/// <summary> /// Triggers Defined Event units listening for the passed eventData globally. Note that triggering an event /// globally will not trigger events listening for the event on a particular object. /// This is the scripting quivalent to the Trigger Global Defined Event unit. /// </summary> /// <param name="eventData">This is a filled object of the type of event you want to trigger.</param> public static void TriggerGlobal(object eventData) { GlobalDefinedEventNode.Trigger(eventData); }