Opc.Ua.Server.StateMachine.ConstructMachineFromType C# (CSharp) Method

ConstructMachineFromType() protected method

Contructs the machine by reading the address space.
protected ConstructMachineFromType ( NodeId typeDefinitionId ) : void
typeDefinitionId NodeId
return void
        protected void ConstructMachineFromType(NodeId typeDefinitionId)
        {
            lock (DataLock)
            {
                m_initialStateName = null;
                m_states = new Dictionary<QualifiedName,State>();
                m_transitions = new List<Transition>();

                // find all components.
                foreach (ILocalNode source in NodeManager.GetInstanceDeclarations(typeDefinitionId, null))
                {
                    if (Server.TypeTree.IsTypeOf(source.TypeDefinitionId, ObjectTypes.StateType))
                    {
                        State state = new State(source);

                        m_states.Add(state.BrowseName, state);
                        
                        if (Server.TypeTree.IsTypeOf(source.TypeDefinitionId, ObjectTypes.InitialStateType))
                        {
                            m_initialStateName = state;
                        }

                        IVariable stateNumber = NodeManager.GetTargetNode(
                            source.NodeId, 
                            ReferenceTypes.HasProperty, 
                            false,
                            true, 
                            BrowseNames.StateNumber) as IVariable;
                        
                        if (stateNumber != null && typeof(uint).IsInstanceOfType(stateNumber.Value))
                        {
                            state.StateNumber = (uint)stateNumber.Value;
                        }

                        continue;
                    }
                    
                    if (Server.TypeTree.IsTypeOf(source.TypeDefinitionId, ObjectTypes.TransitionType))
                    {
                        AddTransition(source);
                        continue;
                    }
                }

                // set the initial state if none provided.
                if (m_initialStateName == null)
                {
                    uint stateNumber = UInt32.MaxValue;

                    foreach (State state in m_states.Values)
                    {
                        if (state.StateNumber < stateNumber)
                        {
                            stateNumber = state.StateNumber;
                            m_initialStateName = state;
                        }
                    }
                }
            }
        }