/// <summary> /// Adds an action to the list of actions. /// </summary> /// <param name="action">The action to add.</param> internal void add(NSFVoidAction <ContextType> action) { lock (delegateListMutex) { actions += action; } }
/// <summary> /// Removes an action from the list of actions. /// </summary> /// <param name="action">The action to remove.</param> internal void remove(NSFVoidAction <ContextType> action) { lock (delegateListMutex) { actions -= action; } }
/// <summary> /// Sets the exception action to call if a delegate throws an exception during invocation. /// </summary> /// <param name="action">The exception action.</param> internal void setExceptionAction(NSFVoidAction <NSFExceptionContext> action) { lock (delegateListMutex) { exceptionAction = action; } }
/// <summary> /// Creates an operating system thread in the .Net environment. /// </summary> /// <param name="name">The name for the thread.</param> /// <param name="executionAction">The action executed by the thread.</param> /// <param name="priority">The priority of the thread.</param> /// <returns>The new thread.</returns> /// <remarks> /// The thread execution action is typically an execution loop. /// When the action returns, the thread is terminated. /// </remarks> public NSFOSThread(NSFString name, NSFVoidAction <NSFContext> executionAction, int priority) : base(name) { action = executionAction; thread = new Thread(new ThreadStart(threadEntry)); thread.Name = name; Priority = priority; OSThreadId = 0; // set later on entry }
/// <summary> /// Creates an operating system thread in the .Net environment. /// </summary> /// <param name="name">The name for the thread.</param> /// <param name="executionAction">The action executed by the thread.</param> /// <param name="priority">The priority of the thread.</param> /// <returns>The new thread.</returns> /// <remarks> /// The thread execution action is typically an execution loop. /// When the action returns, the thread is terminated. /// </remarks> public NSFOSThread(NSFString name, NSFVoidAction<NSFContext> executionAction, int priority) : base(name) { action = executionAction; thread = new Thread(new ThreadStart(threadEntry)); thread.Name = name; Priority = priority; OSThreadId = 0; // set later on entry }
/// <summary> /// Removes a reaction to a specified event. /// </summary> /// <param name="nsfEvent">The event causing the action.</param> /// <param name="action">The action taken as a result of the event.</param> public void removeEventReaction(NSFEvent nsfEvent, NSFVoidAction <NSFEventContext> action) { lock (eventHandlerMutex) { if (eventReactions.ContainsKey(nsfEvent.Id)) { eventReactions[nsfEvent.Id].remove(action); } } }
/// <summary> /// Adds a reaction to a specified event. /// </summary> /// <param name="nsfEvent">The event causing the action.</param> /// <param name="action">The action taken as a result of the event.</param> public void addEventReaction(NSFEvent nsfEvent, NSFVoidAction <NSFEventContext> action) { lock (eventHandlerMutex) { if (!eventReactions.ContainsKey(nsfEvent.Id)) { eventReactions.Add(nsfEvent.Id, new NSFVoidActions <NSFEventContext>()); eventReactions[nsfEvent.Id].setExceptionAction(handleEventReactionException); } eventReactions[nsfEvent.Id].add(action); } }
/// <summary> /// Creates a local transition. /// </summary> /// <param name="name">User assigned name for transition.</param> /// <param name="source">Transition source.</param> /// <param name="target">Transition target.</param> /// <param name="trigger">Transition trigger.</param> /// <param name="guard">Transition guard.</param> /// <param name="action">Transition action.</param> public NSFLocalTransition(NSFString name, NSFCompositeState source, NSFState target, NSFEvent trigger, NSFBoolGuard<NSFStateMachineContext> guard, NSFVoidAction<NSFStateMachineContext> action) : base(name, source, target, trigger, guard, action) { compositeSource = source; // Target must be substate of source or the source itself if ((!Source.isParent(Target)) && (Source != Target)) { throw new Exception(Name + " invalid local transition, source is neither parent of nor equal to target"); } Source.addOutgoingTransition(this); }
/// <summary> /// Creates a scheduled action. /// </summary> /// <param name="name">The name of the scheduled action.</param> /// <param name="action">The action to execute.</param> /// <param name="eventThread">The thread on which the action will execute.</param> /// <remarks> /// Use null or String.Empty for the name if no name is desired. /// The action will be logged in the trace if the name is anything other than null or String.Empty. /// </remarks> public NSFScheduledAction(NSFString name, NSFVoidAction <NSFContext> action, NSFEventThread eventThread) : base(name) { Actions += action; Actions.setExceptionAction(handleActionException); eventHandler = new NSFEventHandler(Name, eventThread); executeActionsEvent = new NSFEvent(Name, this, eventHandler); eventHandler.LoggingEnabled = false; eventHandler.addEventReaction(executeActionsEvent, executeActions); eventHandler.startEventHandler(); }
/// <summary> /// Creates a state. /// </summary> /// <param name="name">The name of the state.</param> /// <param name="parentRegion">The parent region of the state.</param> /// <param name="entryAction">The actions to be performed upon entry to the state.</param> /// <param name="exitAction">The actions to be performed upon exit of the state.</param> public NSFState(NSFString name, NSFRegion parentRegion, NSFVoidAction <NSFStateMachineContext> entryAction, NSFVoidAction <NSFStateMachineContext> exitAction) : base(name) { this.parentRegion = parentRegion; EntryActions += entryAction; ExitActions += exitAction; if (parentRegion != null) { parentRegion.addSubstate(this); } EntryActions.setExceptionAction(handleEntryActionException); ExitActions.setExceptionAction(handleExitActionException); }
/// <summary> /// Creates a state. /// </summary> /// <param name="name">The name of the state.</param> /// <param name="parentRegion">The parent region of the state.</param> /// <param name="entryAction">The actions to be performed upon entry to the state.</param> /// <param name="exitAction">The actions to be performed upon exit of the state.</param> public NSFState(NSFString name, NSFRegion parentRegion, NSFVoidAction<NSFStateMachineContext> entryAction, NSFVoidAction<NSFStateMachineContext> exitAction) : base(name) { this.parentRegion = parentRegion; EntryActions += entryAction; ExitActions += exitAction; if (parentRegion != null) { parentRegion.addSubstate(this); } EntryActions.setExceptionAction(handleEntryActionException); ExitActions.setExceptionAction(handleExitActionException); }
/// <summary> /// Creates a transition. /// </summary> /// <param name="name">User assigned name for transition.</param> /// <param name="source">Transition source.</param> /// <param name="target">Transition target.</param> /// <param name="trigger">Transition trigger.</param> /// <param name="guard">Transition guard.</param> /// <param name="action">Transition action.</param> /// <remarks>Deprecated - Use NSFExternalTransition or NSFLocalTransition</remarks> protected NSFTransition(NSFString name, NSFState source, NSFState target, NSFEvent trigger, NSFBoolGuard<NSFStateMachineContext> guard, NSFVoidAction<NSFStateMachineContext> action) : base(name) { this.source = source; this.target = target; Guards += guard; Actions += action; addTrigger(trigger); // Validity check if ((source == target) && (triggers.Count == 0) && Guards.isEmpty()) { throw new Exception(Name + " invalid self-transition with no trigger or guard"); } target.addIncomingTransition(this); // Outgoing transitions must be added by concrete classes Guards.setExceptionAction(handleGuardException); Actions.setExceptionAction(handleActionException); }
/// <summary> /// Creates an external transition. /// </summary> /// <param name="name">User assigned name for transition.</param> /// <param name="source">Transition source.</param> /// <param name="target">Transition target.</param> /// <param name="trigger">Transition trigger.</param> /// <param name="guard">Transition guard.</param> /// <param name="action">Transition action.</param> public NSFExternalTransition(NSFString name, NSFState source, NSFState target, NSFEvent trigger, NSFBoolGuard<NSFStateMachineContext> guard, NSFVoidAction<NSFStateMachineContext> action) : base(name, source, target, trigger, guard, action) { Source.addOutgoingTransition(this); }
/// <summary> /// Creates an operating system thread. /// </summary> /// <param name="name">The name for the thread.</param> /// <param name="executionAction">The action executed by the thread.</param> /// <returns>The new thread.</returns> /// <remarks> /// The thread execution action is typically an execution loop. /// When the action returns, the thread is terminated. /// </remarks> public NSFOSThread(NSFString name, NSFVoidAction<NSFContext> executionAction) : this(name, executionAction, MediumPriority) { }
/// <summary> /// Creates an operating system thread. /// </summary> /// <param name="name">The name for the thread.</param> /// <param name="executionAction">The action executed by the thread.</param> /// <param name="priority">The priority of the thread.</param> /// <returns>The new thread.</returns> /// <remarks> /// The thread execution action is typically an execution loop. /// When the action returns, the thread is terminated. /// This method is included for interface compatibility with other language implementations. /// </remarks> public static NSFOSThread create(NSFString name, NSFVoidAction<NSFContext> executionAction, int priority) { return new NSFOSThread(name, executionAction, priority); }
/// <summary> /// Adds a reaction to a specified event. /// </summary> /// <param name="nsfEvent">The event causing the action.</param> /// <param name="action">The action taken as a result of the event.</param> public void addEventReaction(NSFEvent nsfEvent, NSFVoidAction<NSFEventContext> action) { lock (eventHandlerMutex) { if (!eventReactions.ContainsKey(nsfEvent.Id)) { eventReactions.Add(nsfEvent.Id, new NSFVoidActions<NSFEventContext>()); eventReactions[nsfEvent.Id].setExceptionAction(handleEventReactionException); } eventReactions[nsfEvent.Id].add(action); } }
/// <summary> /// Creates an operating system thread. /// </summary> /// <param name="name">The name for the thread.</param> /// <param name="executionAction">The action executed by the thread.</param> /// <returns>The new thread.</returns> /// <remarks> /// The thread execution action is typically an execution loop. /// When the action returns, the thread is terminated. /// </remarks> public NSFOSThread(NSFString name, NSFVoidAction <NSFContext> executionAction) : this(name, executionAction, MediumPriority) { }
/// <summary> /// Creates an operating system thread. /// </summary> /// <param name="name">The name for the thread.</param> /// <param name="executionAction">The action executed by the thread.</param> /// <param name="priority">The priority of the thread.</param> /// <returns>The new thread.</returns> /// <remarks> /// The thread execution action is typically an execution loop. /// When the action returns, the thread is terminated. /// This method is included for interface compatibility with other language implementations. /// </remarks> public static NSFOSThread create(NSFString name, NSFVoidAction <NSFContext> executionAction, int priority) { return(new NSFOSThread(name, executionAction, priority)); }
/// <summary> /// Creates an internal transition. /// </summary> /// <param name="state">Transition state.</param> /// <param name="trigger">Transition trigger.</param> /// <param name="guard">Transition guard.</param> /// <param name="action">Transition action.</param> /// <remarks>The default name for the transition is [state.Name]ReactionsTo[trigger.Name]</remarks> public NSFInternalTransition(NSFState state, NSFEvent trigger, NSFBoolGuard<NSFStateMachineContext> guard, NSFVoidAction<NSFStateMachineContext> action) : this(state.Name + "ReactionsTo" + trigger.Name, state, trigger, guard, action) { }
/// <summary> /// Creates an internal transition. /// </summary> /// <param name="state">Transition state.</param> /// <param name="trigger">Transition trigger.</param> /// <param name="guard">Transition guard.</param> /// <param name="action">Transition action.</param> /// <remarks>The default name for the transition is [state.Name]ReactionsTo[trigger.Name]</remarks> public NSFInternalTransition(NSFState state, NSFEvent trigger, NSFBoolGuard <NSFStateMachineContext> guard, NSFVoidAction <NSFStateMachineContext> action) : this(state.Name + "ReactionsTo" + trigger.Name, state, trigger, guard, action) { }
/// <summary> /// Creates a local transition. /// </summary> /// <param name="source">Transition source.</param> /// <param name="target">Transition target.</param> /// <param name="trigger">Transition trigger.</param> /// <param name="guard">Transition guard.</param> /// <param name="action">Transition action.</param> public NSFLocalTransition(NSFCompositeState source, NSFState target, NSFEvent trigger, NSFBoolGuard<NSFStateMachineContext> guard, NSFVoidAction<NSFStateMachineContext> action) : this(source.Name + "To" + target.Name, source, target, trigger, guard, action) { }
/// <summary> /// Removes a reaction to a specified event. /// </summary> /// <param name="nsfEvent">The event causing the action.</param> /// <param name="action">The action taken as a result of the event.</param> public void removeEventReaction(NSFEvent nsfEvent, NSFVoidAction<NSFEventContext> action) { lock (eventHandlerMutex) { if (eventReactions.ContainsKey(nsfEvent.Id)) { eventReactions[nsfEvent.Id].remove(action); } } }
/// <summary> /// Creates a state. /// </summary> /// <param name="name">The name of the state.</param> /// <param name="parentState">The parent state of the state.</param> /// <param name="entryAction">The actions to be performed upon entry to the state.</param> /// <param name="exitAction">The actions to be performed upon exit of the state.</param> public NSFState(NSFString name, NSFCompositeState parentState, NSFVoidAction<NSFStateMachineContext> entryAction, NSFVoidAction<NSFStateMachineContext> exitAction) : this(name, parentState.getDefaultRegion(), entryAction, exitAction) { }
/// <summary> /// Creates a transition between two fork-joins. /// </summary> /// <param name="name">User assigned name for transition.</param> /// <param name="source">Transition source.</param> /// <param name="target">Transition target.</param> /// <param name="region">Transition region.</param> /// <param name="action">Transition action.</param> /// <remarks> /// This class is an extension to UML 2.x. It allows a transition to be made between two fork-joins, /// optionally specifying a region associated with the transition. If a region is specified, its /// active substate will be the target fork-join after the transition is taken. If a NULL region is /// specified, then no region's active substate will be the target fork-join as a result of taking /// this transition. This latter case, where the associated region is NULL, is equivalent to using /// an external transition between the two fork-joins. /// </remarks> public NSFForkJoinTransition(NSFString name, NSFForkJoin source, NSFForkJoin target, NSFRegion region, NSFVoidAction <NSFStateMachineContext> action) : base(name, source, target, null, null, action) { ForkJoinRegion = region; }
/// <summary> /// Creates a transition between two fork-joins. /// </summary> /// <param name="name">User assigned name for transition.</param> /// <param name="source">Transition source.</param> /// <param name="target">Transition target.</param> /// <param name="region">Transition region.</param> /// <param name="action">Transition action.</param> /// <remarks> /// This class is an extension to UML 2.x. It allows a transition to be made between two fork-joins, /// optionally specifying a region associated with the transition. If a region is specified, its /// active substate will be the target fork-join after the transition is taken. If a NULL region is /// specified, then no region's active substate will be the target fork-join as a result of taking /// this transition. This latter case, where the associated region is NULL, is equivalent to using /// an external transition between the two fork-joins. /// </remarks> public NSFForkJoinTransition(NSFString name, NSFForkJoin source, NSFForkJoin target, NSFRegion region, NSFVoidAction<NSFStateMachineContext> action) : base(name, source, target, null, null, action) { ForkJoinRegion = region; }
/// <summary> /// Creates a composite state. /// </summary> /// <param name="name">The name of the composite state.</param> /// <param name="parentState">The parent state of the composite state.</param> /// <param name="entryAction">The actions to be performed upon entry to the composite state.</param> /// <param name="exitAction">The actions to be performed upon exit of the composite state.</param> public NSFCompositeState(NSFString name, NSFCompositeState parentState, NSFVoidAction<NSFStateMachineContext> entryAction, NSFVoidAction<NSFStateMachineContext> exitAction) : base(name, parentState, entryAction, exitAction) { }
/// <summary> /// Creates a local transition. /// </summary> /// <param name="source">Transition source.</param> /// <param name="target">Transition target.</param> /// <param name="trigger">Transition trigger.</param> /// <param name="guard">Transition guard.</param> /// <param name="action">Transition action.</param> public NSFLocalTransition(NSFCompositeState source, NSFState target, NSFEvent trigger, NSFBoolGuard <NSFStateMachineContext> guard, NSFVoidAction <NSFStateMachineContext> action) : this(source.Name + "To" + target.Name, source, target, trigger, guard, action) { }
/// <summary> /// Creates a local transition. /// </summary> /// <param name="name">User assigned name for transition.</param> /// <param name="source">Transition source.</param> /// <param name="target">Transition target.</param> /// <param name="trigger">Transition trigger.</param> /// <param name="guard">Transition guard.</param> /// <param name="action">Transition action.</param> public NSFLocalTransition(NSFString name, NSFCompositeState source, NSFState target, NSFEvent trigger, NSFBoolGuard <NSFStateMachineContext> guard, NSFVoidAction <NSFStateMachineContext> action) : base(name, source, target, trigger, guard, action) { compositeSource = source; // Target must be substate of source or the source itself if ((!Source.isParent(Target)) && (Source != Target)) { throw new Exception(Name + " invalid local transition, source is neither parent of nor equal to target"); } Source.addOutgoingTransition(this); }
/// <summary> /// Creates a state. /// </summary> /// <param name="name">The name of the state.</param> /// <param name="parentState">The parent state of the state.</param> /// <param name="entryAction">The actions to be performed upon entry to the state.</param> /// <param name="exitAction">The actions to be performed upon exit of the state.</param> public NSFState(NSFString name, NSFCompositeState parentState, NSFVoidAction <NSFStateMachineContext> entryAction, NSFVoidAction <NSFStateMachineContext> exitAction) : this(name, parentState.getDefaultRegion(), entryAction, exitAction) { }
/// <summary> /// Creates a transition. /// </summary> /// <param name="name">User assigned name for transition.</param> /// <param name="source">Transition source.</param> /// <param name="target">Transition target.</param> /// <param name="trigger">Transition trigger.</param> /// <param name="guard">Transition guard.</param> /// <param name="action">Transition action.</param> /// <remarks>Deprecated - Use NSFExternalTransition or NSFLocalTransition</remarks> protected NSFTransition(NSFString name, NSFState source, NSFState target, NSFEvent trigger, NSFBoolGuard <NSFStateMachineContext> guard, NSFVoidAction <NSFStateMachineContext> action) : base(name) { this.source = source; this.target = target; Guards += guard; Actions += action; addTrigger(trigger); // Validity check if ((source == target) && (triggers.Count == 0) && Guards.isEmpty()) { throw new Exception(Name + " invalid self-transition with no trigger or guard"); } target.addIncomingTransition(this); // Outgoing transitions must be added by concrete classes Guards.setExceptionAction(handleGuardException); Actions.setExceptionAction(handleActionException); }
/// <summary> /// Creates an internal transition. /// </summary> /// <param name="name">User assigned name for transition.</param> /// <param name="state">Transition state.</param> /// <param name="trigger">Transition trigger.</param> /// <param name="guard">Transition guard.</param> /// <param name="action">Transition action.</param> public NSFInternalTransition(NSFString name, NSFState state, NSFEvent trigger, NSFBoolGuard <NSFStateMachineContext> guard, NSFVoidAction <NSFStateMachineContext> action) : base(name, state, state, trigger, guard, action) { Source.addOutgoingTransition(this); }
/// <summary> /// Creates a composite state. /// </summary> /// <param name="name">The name of the composite state.</param> /// <param name="parentState">The parent state of the composite state.</param> /// <param name="entryAction">The actions to be performed upon entry to the composite state.</param> /// <param name="exitAction">The actions to be performed upon exit of the composite state.</param> public NSFCompositeState(NSFString name, NSFCompositeState parentState, NSFVoidAction <NSFStateMachineContext> entryAction, NSFVoidAction <NSFStateMachineContext> exitAction) : base(name, parentState, entryAction, exitAction) { }