/// <summary>
 /// Finds the child with the specified browse name.
 /// </summary>
 /// <param name="context">The context for the system being accessed.</param>
 /// <param name="browseName">The browse name of the children to add.</param>
 /// <param name="createOrReplace">if set to <c>true</c> and the child could exist then the child is created.</param>
 /// <param name="replacement">The replacement to use if createOrReplace is true.</param>
 /// <returns>The child.</returns>
 protected virtual BaseInstanceState FindChild(ISystemContext context, QualifiedName browseName, bool createOrReplace, BaseInstanceState replacement)
 {
     if (QualifiedName.IsNull(browseName))
     {
         return(null);
     }
     for (int ii = 0; ii < m_children.Count; ii++)
     {
         BaseInstanceState child = m_children[ii];
         if (browseName == child.BrowseName)
         {
             if (createOrReplace && replacement != null)
             {
                 m_children[ii] = child = replacement;
             }
             return(child);
         }
     }
     if (createOrReplace)
     {
         if (replacement != null)
         {
             AddChild(replacement);
         }
     }
     return(null);
 }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SemanticDataSetSource"/> class.
        /// </summary>
        /// <param name="parent">The parent collecting all variables to be captured by this instance.</param>
        /// <param name="rootBrowseName">The name of the semantic data set source.</param>
        public SemanticDataSetSource(BaseInstanceState parent)
        {
            SemanticDataSetRootBrowseName = parent.BrowseName.ToString();
            List <BaseInstanceState> _myComponents = new List <BaseInstanceState>();

            parent.GetChildren(_myComponents);
            for (int ii = 0; ii < _myComponents.Count; ii++)
            {
                List <BaseInstanceState> _hasComponentPath = new List <BaseInstanceState>();
                _myComponents[ii].RegisterVariable(_hasComponentPath, (x, y) => { if (x is IVariable)
                                                                                  {
                                                                                      m_Variables.Add(string.Join(m_JoiningChar, y), (IVariable)x);
                                                                                  }
                                                   });
            }
        }
        /// <summary>
        /// Finds the child with the specified browse path.
        /// </summary>
        /// <param name="context">The context to use.</param>
        /// <param name="browsePath">The browse path.</param>
        /// <param name="index">The current position in the browse path.</param>
        /// <returns>The target if found. Null otherwise.</returns>
        public virtual BaseInstanceState FindChild(ISystemContext context, IList <QualifiedName> browsePath, int index)
        {
            if (index < 0 || index >= Int32.MaxValue)
            {
                throw new ArgumentOutOfRangeException("index");
            }
            BaseInstanceState instance = FindChild(context, browsePath[index], false, null);

            if (instance != null)
            {
                if (browsePath.Count == index + 1)
                {
                    return(instance);
                }
                return(instance.FindChild(context, browsePath, index + 1));
            }
            return(null);
        }
 /// <summary>
 /// Adds a child to the node.
 /// </summary>
 internal void AddChild(BaseInstanceState child)
 {
     m_children.Add(child);
     ChangeMasks |= NodeStateChangeMasks.Children;
 }