//------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //------------------------------------------------------------------------------ namespace System.Activities.Statements { using System; using System.Activities; using System.ComponentModel; using System.Collections.ObjectModel; using System.Runtime.Collections; using System.Windows.Markup; /// /// This class represents a State in a StateMachine. /// public sealed class State { InternalState internalState; Collection transitions; NoOp nullTrigger; Collection variables; /// /// Gets or sets DisplayName of the State. /// public string DisplayName { get; set; } /// /// Gets or sets entry action of the State. It is executed when the StateMachine enters the State. /// It's optional. /// [DefaultValue(null)] public Activity Entry { get; set; } /// /// Gets or sets exit action of the State. It is executed when the StateMachine leaves the State. /// It's optional. /// [DependsOn("Entry")] [DefaultValue(null)] public Activity Exit { get; set; } /// /// Gets Transitions collection contains all outgoing Transitions from the State. /// [DependsOn("Exit")] public Collection Transitions { get { if (this.transitions == null) { this.transitions = new ValidatingCollection { // disallow null values OnAddValidationCallback = item => { if (item == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("item")); } }, }; } return this.transitions; } } /// /// Gets Variables which can be used within the scope of State and its Transitions collection. /// [DependsOn("Transitions")] public Collection Variables { get { if (this.variables == null) { this.variables = new ValidatingCollection { // disallow null values OnAddValidationCallback = item => { if (item == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("item")); } }, }; } return this.variables; } } /// /// Gets or sets a value indicating whether the State is a final State. /// [DefaultValue(false)] public bool IsFinal { get; set; } /// /// Gets Internal activity representation of state. /// internal InternalState InternalState { get { if (this.internalState == null) { this.internalState = new InternalState(this); } return this.internalState; } } /// /// Gets or sets PassNumber is used to detect re-visiting when traversing states in StateMachine. /// internal uint PassNumber { get; set; } /// /// Gets or sets a value indicating whether state can be reached via transitions. /// internal bool Reachable { get; set; } /// /// Gets or sets StateId is unique within a StateMachine. /// internal string StateId { get; set; } /// /// Gets or sets the display name of the parent state machine of the state. /// Used for tracking purpose only. /// internal string StateMachineName { get; set; } /// /// Clear internal state. /// internal void ClearInternalState() { this.internalState = null; } internal NoOp NullTrigger { get { if (this.nullTrigger == null) { this.nullTrigger = new NoOp { DisplayName = "Null Trigger" }; } return this.nullTrigger; } } internal sealed class NoOp : CodeActivity { protected override void Execute(CodeActivityContext context) { } } } }