示例#1
0
        /// <summary>
        /// Bind each TCD_Interface node to separate TCDSimulator.
        /// </summary>
        protected override NodeState AddBehaviourToPredefinedNode(ISystemContext context, NodeState predefinedNode)
        {
            BaseObjectState passiveNode = predefinedNode as BaseObjectState;

            if (passiveNode != null)
            {
                NodeId typeId = passiveNode.TypeDefinitionId;
                if (IsNodeIdInNamespace(typeId) && typeId.IdType == IdType.Numeric && (uint)typeId.Identifier == ObjectTypes.TCD_Interface)
                {
                    // Found a TCD_Interface. If it is not already an active node, then replace it with one.
                    TCD_InterfaceState activeNode = passiveNode as TCD_InterfaceState;
                    if (activeNode == null)
                    {
                        activeNode = new TCD_InterfaceState(passiveNode.Parent);
                        activeNode.Create(context, passiveNode);
                        if (passiveNode.Parent != null)
                        {
                            passiveNode.Parent.ReplaceChild(context, activeNode);
                        }
                    }

                    // Now that we have an active node, bind it to a simulator.
                    TCDSimulator simulator = CreateSimulatorForNode(activeNode);
                    if (simulator != null)
                    {
                        simulator.AddListener(activeNode);
                        simulator.SetLogger(m_Logger);
                        simulator.StartSimulation();
                        m_Simulators.Add(simulator);    // Prevent it from being disposed
                    }
                    return(activeNode);
                }
            }
            return(predefinedNode);
        }