public void queueEvent(NSFEvent nsfEvent) { lock (eventHandlerMutex) { // Do not allow events to be queued if terminating or terminated (i.e. not ready) if (TerminationStatus != NSFEventHandlerTerminationStatus.EventHandlerReady) { return; } // Handle special case of terminate event by setting status and queuing a single terminate event. // Terminate event must be the last event queued to guarantee safe deletion when it is handled. if (nsfEvent == terminateEvent) { if (TerminationStatus == NSFEventHandlerTerminationStatus.EventHandlerReady) { TerminationStatus = NSFEventHandlerTerminationStatus.EventHandlerTerminating; } } nsfEvent.Destination = this; EventThread.queueEvent(nsfEvent, false, LoggingEnabled); } }
/// <summary> /// Handles an event. /// </summary> /// <param name="nsfEvent">The event to handle.</param> /// <returns>Status indicating if the event was handled or not.</returns> /// <remarks> /// This method is for use only by the North State Framework's internal logic. /// It calls the actions associated with the event, if any. /// </remarks> public NSFEventStatus handleEvent(NSFEvent nsfEvent) { // Handle status changing events if ((nsfEvent == startEvent)) { RunStatus = NSFEventHandlerRunStatus.EventHandlerStarted; } else if (nsfEvent == stopEvent) { RunStatus = NSFEventHandlerRunStatus.EventHandlerStopped; } else if (nsfEvent == terminateEvent) { TerminationStatus = NSFEventHandlerTerminationStatus.EventHandlerTerminated; EventThread.removeEventHandler(this); return NSFEventStatus.NSFEventHandled; } // Don't process events if stopped if (RunStatus == NSFEventHandlerRunStatus.EventHandlerStopped) { return NSFEventStatus.NSFEventUnhandled; } // Process the event bool actionsToExecute = false; lock (eventHandlerMutex) { if (eventReactions.ContainsKey(nsfEvent.Id)) { actionsToExecute = true; } } if (actionsToExecute) { eventReactions[nsfEvent.Id].execute(new NSFEventContext(this, nsfEvent)); return NSFEventStatus.NSFEventHandled; } else { return NSFEventStatus.NSFEventUnhandled; } }