} // end ctr //- #endregion #region // Public Methods //------------------------ /// <summary> /// Adds a namespace element as child to a namespace element /// </summary> /// <param name="aChild">Child to be added. Checks if the child provided is a <see cref="DaAddressSpaceElement"/></param> /// <returns> /// <line>true - Child successfully. </line> /// <line>false - Child was not added. If fails, the Child should be released by the user.</line> /// </returns> /// <include /// file='TBNS.doc.xml' /// path='//class[@name="DaAddressSpaceElement"]/ /// method[@name="AddChild"]/doc/*' /// /> public override bool AddChild(AddressSpaceElement aChild) { if (!HasChildren) { Application.Instance.Trace( EnumTraceLevel.WRN, EnumTraceGroup.OPCSERVER, "DaAddressSpaceElement.AddChild", "This element does not allow childred"); return false; } // end if DaAddressSpaceElement child = aChild as DaAddressSpaceElement; if (child == null) { Application.Instance.Trace( EnumTraceLevel.WRN, EnumTraceGroup.OPCSERVER, "DaAddressSpaceElement.AddChild", "Invalid child provided"); return false; } // end if // only add the child if no handle assigned if (child.ObjectHandle == 0) { OTSAddressSpaceElementData data = new OTSAddressSpaceElementData(); data.m_name = Marshal.StringToCoTaskMemUni(child.Name); data.m_itemID = Marshal.StringToCoTaskMemUni( Name + Application.Instance.AddressSpaceDelimiter + child.Name); data.m_accessRights = (byte) child.AccessRights; data.m_ioMode = (byte) child.IoMode; data.m_datatype = ValueQT.GetVartype(child.Datatype); data.m_hasChildren = Convert.ToByte(child.HasChildren); data.m_isBrowsable = Convert.ToByte(child.IsBrowsable); data.m_elementType = (byte) EnumAddressSpaceElementType.DA; data.m_userData = child.UserData; Application.Instance.DaAddressSpaceRoot.AddElementToArray(child); int result = OTBFunctions.OTSAddAddressSpaceElement(m_objectHandle, data, out child.m_objectHandle); Marshal.FreeCoTaskMem(data.m_name); Marshal.FreeCoTaskMem(data.m_itemID); if (!ResultCode.SUCCEEDED(result)) { result = Application.Instance.DaAddressSpaceRoot.RemoveElementFromArray(child); System.Diagnostics.Debug.Assert(ResultCode.SUCCEEDED(result), "RemoveElementFromArray has failed"); return false; } // end if ... else } else { Application.Instance.DaAddressSpaceRoot.AddElementToArray(child); } // end if ... else // end if return base.AddChild(aChild); } // end AddChild