/// <summary>
        /// Removes the connection to a server.
        /// </summary>
        /// <param name="executionOptions">Specifies the modality of execution for disconnecting from a server.</param>
        /// <returns>The result of disconnecting from a server.</returns>
        /// <include
        ///  file='TBNC.doc.xml'
        ///  path='//class[@name="ObjectSpaceElement"]/method[@name="Disconnect"]/doc/*'
        /// />
        public virtual int Disconnect(ExecutionOptions executionOptions)
        {
            int res = (int)EnumResultCode.E_FAIL;

            try
            {
                OTCExecutionOptions options = new OTCExecutionOptions();

                if (executionOptions != null)
                {
                    options.m_executionType    = (byte)executionOptions.ExecutionType;
                    options.m_executionContext = (uint)executionOptions.ExecutionContext;
                }
                else
                {
                    options.m_executionType    = (byte)EnumExecutionType.SYNCHRONOUS;
                    options.m_executionContext = 0;
                }

                EnumObjectState m_targetState = EnumObjectState.DISCONNECTED;
                OTBFunctions.OTCChangeTargetState(this.Handle, (byte)m_targetState, 1);
                res = OTBFunctions.OTCPerformStateTransition(this.Handle, 1, ref options);
            }
            catch (Exception exc)
            {
                Application.Instance.Trace(
                    EnumTraceLevel.ERR,
                    EnumTraceGroup.CLIENT,
                    "ObjectSpaceElement.Disconnect",
                    exc.ToString());
            }
            return(res);
        }
        /// <summary>
        /// Establishes a connection to a server.
        /// </summary>
        /// <param name="deep">Indicates if connecting to the server should be propagated down to the chlid objects or not.</param>
        /// <param name="active">Indicates if the  <see cref=" ObjectSpaceElement"/> and the server communicate with each other via callbacks. </param>
        /// <param name="executionOptions">Specifies the modality of execution for connecting to a server.</param>
        /// <returns>The result of connecting to a server.</returns>
        /// <include
        ///  file='TBNC.doc.xml'
        ///  path='//class[@name="ObjectSpaceElement"]/method[@name="Connect"]/doc/*'
        /// />
        public virtual int Connect(bool deep, bool active, ExecutionOptions executionOptions)
        {
            int res = (int)EnumResultCode.E_FAIL;

            try
            {
                if (deep == true)
                {
                    if (active == true)
                    {
                        OTBFunctions.OTCChangeTargetState(this.Handle, (byte)EnumObjectState.ACTIVATED, 1);
                        res = PerformStateTransition(deep, executionOptions);
                    }
                    if (active == false)
                    {
                        OTBFunctions.OTCChangeTargetState(this.Handle, (byte)EnumObjectState.CONNECTED, 1);
                        res = PerformStateTransition(deep, executionOptions);
                    }
                }
                if (deep == false)
                {
                    if (active == true)
                    {
                        OTBFunctions.OTCChangeTargetState(this.Handle, (byte)EnumObjectState.ACTIVATED, 0);
                        res = PerformStateTransition(deep, executionOptions);
                    }
                    if (active == false)
                    {
                        OTBFunctions.OTCChangeTargetState(this.Handle, (byte)EnumObjectState.CONNECTED, 0);
                        res = PerformStateTransition(deep, executionOptions);
                    }
                }
            }
            catch (Exception exc)
            {
                Application.Instance.Trace(
                    EnumTraceLevel.ERR,
                    EnumTraceGroup.CLIENT,
                    "ObjectSpaceElement.Connect",
                    exc.ToString());
            }
            return(res);
        }