/// <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>
        /// Updates some object attributes to the server.
        /// </summary>
        /// <param name="whatAttributes">A list with all the object attributes to be updated to the server.</param>
        /// <param name="results">A list with the result of the update for each object attribute. </param>
        /// <param name="executionOptions">Specifies the modality of execution for updating attributes to a server.</param>
        /// <returns>The result of updating attributes to a server.</returns>
        /// <include
        ///  file='TBNC.doc.xml'
        ///  path='//class[@name="ObjectSpaceElement"]/method[@name="SetAttributesToServer"]/doc/*'
        /// />
        public virtual int SetAttributesToServer(
            EnumObjectAttribute[] whatAttributes,
            out int[] results,
            ExecutionOptions executionOptions)
        {
            int res = (int)EnumResultCode.E_FAIL;

            results = null;
            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;
                }

                int    count = whatAttributes.Length;
                uint[] whatAttributesToChange = new uint[count];
                for (int i = 0; i < whatAttributes.Length; i++)
                {
                    whatAttributesToChange[i] = (uint)whatAttributes[i];
                }
                results = new int[count];
                res     = OTBFunctions.OTCUpdateAttributes(
                    this.Handle,
                    0,
                    (uint)count,
                    whatAttributesToChange,
                    results,
                    ref options);
            }
            catch (Exception exc)
            {
                Application.Instance.Trace(
                    EnumTraceLevel.ERR,
                    EnumTraceGroup.CLIENT,
                    "ObjectSpaceElement.SetAttributesToServer",
                    exc.ToString());
            }
            return(res);
        }
        //-
        #endregion

        /// <summary>
        /// Performs the transition from the current state to the target state.
        /// </summary>
        /// <param name="deep">Indicates if changing the target state should be propagated down to the child objects or not.</param>
        /// <param name="executionOptions">Specifies the modality of execution for state transition.</param>
        /// <returns>The result of performing the state transition.</returns>
        /// <include
        ///  file='TBNC.doc.xml'
        ///  path='//class[@name="ObjectSpaceElement"]/method[@name="PerformStateTransition"]/doc/*'
        /// />
        public virtual int PerformStateTransition(bool deep, 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;
                }

                if (deep == false)
                {
                    // performs the state transition for the object itself
                    res = OTBFunctions.OTCPerformStateTransition(this.Handle, 0, ref options);
                }
                if (deep == true)
                {
                    // performs the state transition for the whole subtree of the object
                    res = OTBFunctions.OTCPerformStateTransition(this.Handle, 1, ref options);
                }
            }
            catch (Exception exc)
            {
                Application.Instance.Trace(
                    EnumTraceLevel.ERR,
                    EnumTraceGroup.CLIENT,
                    "ObjectSpaceElement.PerformStateTransition",
                    exc.ToString());
            }
            return(res);
        }
        //-
        #endregion

        /// <summary>
        /// Browses all the servers that support a specified interface specification.
        ///	The server information to be returned after browsing is specified using the <see cref="EnumServerBrowserData"/> object.
        /// After browsing, a list of <see cref="ServerBrowserData"/> objects that contain the requested information will be returned.
        /// </summary>
        /// <param name="whatOPCspecification">An OPC specification.</param>
        /// <param name="whatServerData">Indicates what information about the server to be returned.</param>
        /// <param name="serverData">A list with requested information about the available servers on the computer.</param>
        /// <param name="someExecutionOptions">Specifies the modality of execution for browsing servers on the computer.</param>
        /// <returns>The result of browsing servers on the computer.
        /// </returns>
        /// <include
        ///  file='TBNC.doc.xml'
        ///  path='//class[@name="ServerBrowser"]/method[@name="Browse"]/doc/*'
        /// />
        public virtual int Browse(
            EnumOPCSpecification whatOPCspecification,
            EnumServerBrowserData whatServerData,
            out ServerBrowserData[] serverData,
            ExecutionOptions someExecutionOptions)
        {
            int res = (int)EnumResultCode.E_FAIL;

            serverData = null;
            try
            {
                byte   whatSpecification = (byte)whatOPCspecification;
                byte   whatData          = (byte)whatServerData;
                uint   serverDataCount   = 0;
                IntPtr pServerData       = new IntPtr();

                OTCExecutionOptions options = new OTCExecutionOptions();

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

                res = OTBFunctions.OTCBrowseServer(
                    m_ipAddress,
                    whatSpecification,
                    whatData,
                    ref serverDataCount,
                    out pServerData,
                    ref options);
                if (someExecutionOptions.ExecutionType == EnumExecutionType.SYNCHRONOUS)
                {
                    if (ResultCode.SUCCEEDED(res))
                    {
                        uint dataCount = serverDataCount;
                        serverData = new ServerBrowserData[dataCount];
                        OTCServerData[] serverDataOTC    = new OTCServerData[dataCount];
                        OTCServerData   typeOfServerData = new OTCServerData();
                        for (int i = 0; i < dataCount; i++)
                        {
                            int           structSize = Marshal.SizeOf(typeOfServerData);
                            OTCServerData myData     =
                                (OTCServerData)
                                Marshal.PtrToStructure(OTBFunctions.GetIntPtrOffset(pServerData, structSize * i), typeof(OTCServerData));
                            serverData[i] = new ServerBrowserData(
                                Marshal.PtrToStringUni(myData.m_clsid),
                                Marshal.PtrToStringUni(myData.m_progId),
                                Marshal.PtrToStringUni(myData.m_description),
                                Marshal.PtrToStringUni(myData.m_vProgId),
                                (EnumOPCSpecification)myData.m_opcSpecification,
                                Marshal.PtrToStringUni(myData.m_url));

                            OTBFunctions.OTFreeMemory(myData.m_clsid);

                            OTBFunctions.OTFreeMemory(myData.m_progId);

                            OTBFunctions.OTFreeMemory(myData.m_description);

                            OTBFunctions.OTFreeMemory(myData.m_vProgId);

                            OTBFunctions.OTFreeMemory(myData.m_url);
                        }                         //	end for

                        OTBFunctions.OTFreeMemory(pServerData);
                    }             //	end if
                }                 //	end if
            }
            catch (Exception exc)
            {
                Application.Instance.Trace(
                    EnumTraceLevel.ERR,
                    EnumTraceGroup.CLIENT,
                    "ServerBrowser.Browse",
                    exc.ToString());
            }
            return(res);
        }
Exemple #5
0
		//-
		#endregion

		#region	//	Public Methods
		//---------------------------------

		/// <summary>
		/// Browses the Data Access Server`s address space starting from the element`s position in the address space.
		/// </summary>
		/// <param name="browseOptions">Specifies the options of the browsing.</param>
		/// <param name="addressSpaceElements">A list with the element`s children.</param>
		/// <param name="executionOptions">Specifies the modality of execution for browsing the server's address space.</param>
		/// <returns>The result of browsing the address space.</returns>
		/// <include
		///  file='TBNC.doc.xml'
		///  path='//class[@name="DaAddressSpaceElement"]/method[@name="Browse"]/doc/*'
		/// />
		public int Browse(
			DaAddressSpaceElementBrowseOptions browseOptions,
			out DaAddressSpaceElement[] addressSpaceElements,
			ExecutionOptions executionOptions)
		{
			addressSpaceElements = null;
			OTCAddressSpaceBrowseOptions OTCBrowseOptions = new OTCAddressSpaceBrowseOptions();
			OTCBrowseOptions.m_accessRightsFilter = 0;
			int res = (int) EnumResultCode.E_FAIL;

			if (this.Session == null)
			{
				Application.Instance.Trace(
					EnumTraceLevel.ERR,
					EnumTraceGroup.CLIENT,
					"DaAddressSpaceElement.Browse",
					"The Session property of the AddressSpaceElement cannot be null! Set the property to a value before calling Browse!");
				return res;
			}
			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;
				}

				IntPtr pOTCaddressSpaceElements = new IntPtr();
				uint addressSpaceElementDataCount = 0;

				OTCBrowseOptions.m_type = (byte) browseOptions.ElementTypeFilter;
				OTCBrowseOptions.m_elementNameFilter = Marshal.StringToCoTaskMemUni(browseOptions.ElementNameFilter);
				OTCBrowseOptions.m_vendorFilter = Marshal.StringToCoTaskMemUni(browseOptions.VendorFilter);
				OTCBrowseOptions.m_accessRightsFilter = (uint) browseOptions.AccessRightsFilter;
				OTCBrowseOptions.m_dataTypeFilter = ValueQT.GetVartype(browseOptions.DataTypeFilter);
				OTCBrowseOptions.m_maxElements = browseOptions.MaxElements;
				OTCBrowseOptions.m_retrieveItemID = (byte) (browseOptions.RetrieveItemId ? 1 : 0);
				OTCBrowseOptions.m_retrieveProperties = (byte) (browseOptions.ReturnProperties ? 1 : 0);
				OTCBrowseOptions.m_retrievePropertyValues = (byte) (browseOptions.ReturnPropertyValues ? 1 : 0);
				OTCBrowseOptions.m_forceBrowseUp = (byte) (browseOptions.ForceBrowseUp ? 1 : 0);
				OTCBrowseOptions.m_continuationPoint = OTBFunctions.AllocateOTBString(browseOptions.ContinuationPoint);

				res = OTBFunctions.OTCBrowseAddressSpace(
					this.Session.Handle,
					this.m_objectElementHandle,
					this.ItemId,
					this.m_itemPath,
					ref OTCBrowseOptions,
					ref addressSpaceElementDataCount,
					out pOTCaddressSpaceElements,
					ref options);

				addressSpaceElements = new DaAddressSpaceElement[addressSpaceElementDataCount];

				if (options.m_executionType == (byte) EnumExecutionType.SYNCHRONOUS)
				{
					if (ResultCode.SUCCEEDED(res))
					{
						OTCAddressSpaceElementData typeOfAddressSpaceElement = new OTCAddressSpaceElementData();
						for (int i = 0; i < addressSpaceElementDataCount; i++)
						{
							int structSize = Marshal.SizeOf(typeOfAddressSpaceElement);
							OTCAddressSpaceElementData myData =
								(OTCAddressSpaceElementData)
								Marshal.PtrToStructure(OTBFunctions.GetIntPtrOffset(pOTCaddressSpaceElements, structSize*i),
								                       typeof (OTCAddressSpaceElementData));
							addressSpaceElements[i] = new DaAddressSpaceElement(
								(EnumAddressSpaceElementType) myData.m_type,
								Marshal.PtrToStringUni(myData.m_name),
								Marshal.PtrToStringUni(myData.m_itemID),
								Marshal.PtrToStringUni(myData.m_itemPath),
								myData.m_objectHandle,
								this.Session);
							OTBFunctions.OTFreeMemory(myData.m_itemID);
							OTBFunctions.OTFreeMemory(myData.m_name);
							OTBFunctions.OTFreeMemory(myData.m_itemPath);
						}
						if (pOTCaddressSpaceElements != IntPtr.Zero)
						{
							OTBFunctions.OTFreeMemory(pOTCaddressSpaceElements);
						}
						browseOptions.ContinuationPoint = Marshal.PtrToStringUni(OTCBrowseOptions.m_continuationPoint);
					}
					else
					{
						Application.Instance.Trace(
							EnumTraceLevel.ERR,
							EnumTraceGroup.CLIENT,
							"DaAddressSpaceElement.Browse",
							"Browsing failed! Result: " + res);
					}
				} //	if executionOptions Synchronous
				Marshal.FreeCoTaskMem(OTCBrowseOptions.m_elementNameFilter);
				Marshal.FreeCoTaskMem(OTCBrowseOptions.m_vendorFilter);
				OTBFunctions.OTFreeMemory(OTCBrowseOptions.m_continuationPoint);
			}
			catch (Exception exc)
			{
				Application.Instance.Trace(
					EnumTraceLevel.ERR,
					EnumTraceGroup.CLIENT,
					"DaAddressSpaceElement.Browse",
					exc.ToString());
			}
			return res;
		}
Exemple #6
0
        /// <summary>
        /// Gives the sub-condition names which are associated with a specified condition name.
        /// The condition must be supported by the event server for the current category.
        /// </summary>
        /// <param name="conditionName">A condition name, as returned by the <see cref="QueryAeConditionNames"/> method.</param>
        /// <param name="subConditionNames">A list with the sub-condition names associated with the specified condition.</param>
        /// <param name="executionOptions">Specifies the modality of execution for quering the sub-condition names.</param>
        /// <returns>The result of quering the sub-condition names.</returns>
        /// <include
        ///  file='TBNC.doc.xml'
        ///  path='//class[@name="AeCategory"]/method[@name="QueryAeSubConditionNames"]/doc/*'
        /// />
        public virtual int QueryAeSubConditionNames(
            string conditionName,
            out string[] subConditionNames,
            ExecutionOptions executionOptions)
        {
            int res = (int)EnumResultCode.E_FAIL;

            subConditionNames = new string[0];

            if (this.Session == null)
            {
                Application.Instance.Trace(
                    EnumTraceLevel.ERR,
                    EnumTraceGroup.CLIENT,
                    "AeCategory.QueryAeSubConditionNames",
                    "The Session property of the Category cannot be null! Set the property to a value before calling QueryAeSubConditionNames!");
                return(res);
            }
            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;
                }

                uint   count = 0;
                IntPtr pSubConditionNames = IntPtr.Zero;

                res = OTBFunctions.OTCQueryAESubConditions(
                    this.Session.Handle,
                    conditionName,
                    out count,
                    out pSubConditionNames,
                    ref options);

                if (ResultCode.SUCCEEDED(res))
                {
                    if (options.m_executionType == (byte)EnumExecutionType.SYNCHRONOUS)
                    {
                        subConditionNames = new string[count];
                        int ptrSize = Marshal.SizeOf(typeof(IntPtr));
                        for (int i = 0; i < count; i++)
                        {
                            IntPtr subConditionName =
                                (IntPtr)Marshal.PtrToStructure(OTBFunctions.GetIntPtrOffset(pSubConditionNames, i * ptrSize), typeof(IntPtr));
                            subConditionNames[i] = Marshal.PtrToStringUni(subConditionName);
                            OTBFunctions.OTFreeMemory(subConditionName);
                        }                 //	end for
                        OTBFunctions.OTFreeMemory(pSubConditionNames);
                    }                     //	end if
                }
                else
                {
                    Application.Instance.Trace(
                        EnumTraceLevel.ERR,
                        EnumTraceGroup.CLIENT,
                        "AeCategory.QueryAeSubConditionNames",
                        " Quering sub condition names failed! Result: " + res);
                }
            }
            catch (Exception exc)
            {
                Application.Instance.Trace(
                    EnumTraceLevel.ERR,
                    EnumTraceGroup.CLIENT,
                    "AeCategory.QueryAeSubConditionNames",
                    exc.ToString());
            }
            return(res);
        }
Exemple #7
0
        //-
        #endregion

        /// <summary>
        /// Gives information about the vendor-specific attributes the server can provide as part of an event
        /// notification for an event within the current event category.
        /// </summary>
        /// <param name="attributes">A list with the vendor-specific event attributes associated with the current event category.</param>
        /// <param name="executionOptions">Specifies the modality of execution for quering the attributes associated with the current event category.</param>
        /// <returns>The result of quering the attributes associated with the current event category.</returns>
        /// <include
        ///  file='TBNC.doc.xml'
        ///  path='//class[@name="AeCategory"]/method[@name="QueryAeAttributes"]/doc/*'
        /// />
        public virtual int QueryAeAttributes(
            out AeAttribute[] attributes,
            ExecutionOptions executionOptions)
        {
            attributes = new AeAttribute[0];
            int res = (int)EnumResultCode.E_FAIL;

            if (this.Session == null)
            {
                Application.Instance.Trace(
                    EnumTraceLevel.ERR,
                    EnumTraceGroup.CLIENT,
                    "AeCategory.QueryAeAttributes",
                    "The Session property of the Category cannot be null! Set the property to a value before calling QueryAEAttributes!");
                return(res);
            }

            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;
                }

                uint   attributesCount       = 0;
                IntPtr attributeIDs          = IntPtr.Zero;
                IntPtr attributeDescriptions = IntPtr.Zero;
                IntPtr attributeDataTypes    = IntPtr.Zero;

                res = OTBFunctions.OTCQueryAEAttributes(
                    this.Session.Handle,
                    this.Id,
                    out attributesCount,
                    out attributeIDs,
                    out attributeDescriptions,
                    out attributeDataTypes,
                    ref options);

                if (ResultCode.SUCCEEDED(res))
                {
                    if (options.m_executionType == (byte)EnumExecutionType.SYNCHRONOUS)
                    {
                        attributes = new AeAttribute[attributesCount];

                        int uintSize   = Marshal.SizeOf(typeof(uint));
                        int ptrSize    = Marshal.SizeOf(typeof(IntPtr));
                        int ushortSize = Marshal.SizeOf(typeof(ushort));

                        for (int i = 0; i < attributesCount; i++)
                        {
                            uint attributeID =
                                (uint)Marshal.PtrToStructure(OTBFunctions.GetIntPtrOffset(attributeIDs, i * uintSize), typeof(uint));
                            ushort attributeDataType =
                                (ushort)Marshal.PtrToStructure(OTBFunctions.GetIntPtrOffset(attributeDataTypes, i * ushortSize), typeof(ushort));
                            IntPtr attributeDescription =
                                (IntPtr)Marshal.PtrToStructure(OTBFunctions.GetIntPtrOffset(attributeDescriptions, i * ptrSize), typeof(IntPtr));
                            attributes[i] = new AeAttribute(
                                attributeID,
                                Marshal.PtrToStringUni(attributeDescription),
                                ValueQT.GetSysType(attributeDataType));

                            OTBFunctions.OTFreeMemory(attributeDescription);
                        }                         //	end for

                        OTBFunctions.OTFreeMemory(attributeIDs);
                        OTBFunctions.OTFreeMemory(attributeDescriptions);
                        OTBFunctions.OTFreeMemory(attributeDataTypes);
                    }                     //	end if
                }
                else
                {
                    Application.Instance.Trace(
                        EnumTraceLevel.ERR,
                        EnumTraceGroup.CLIENT,
                        "AeCategory.QueryAeAttributes",
                        "Quering AeAttributes failed! Result: " + res);
                }
            }
            catch (Exception exc)
            {
                Application.Instance.Trace(
                    EnumTraceLevel.ERR,
                    EnumTraceGroup.CLIENT,
                    "AeCategory.QueryAeAttributes",
                    exc.ToString());
            }
            return(res);
        }