} // end GetParent /// <summary> /// Returns a list of children. This list is empty in case of an error or if no children are there to be delivered /// </summary> /// <returns> /// List of this element's children. If the element has no children, the list is empty /// </returns> /// <include /// file='TBNS.doc.xml' /// path='//class[@name="DaAddressSpaceElement"]/ /// method[@name="GetChildren"]/doc/*' /// /> public override ArrayList GetChildren() { ArrayList children = new ArrayList(); IntPtr ptrData = IntPtr.Zero; int count = 0; int res = OTBFunctions.OTSGetChildren(m_objectHandle, (byte) EnumAddressSpaceElementType.DA, out count, out ptrData); if (ResultCode.SUCCEEDED(res)) { if (count > 0) { int size = Marshal.SizeOf(typeof (OTObjectData)); lock (Application.Instance.DaAddressSpaceRoot.ElementSyncRoot) { for (int i = 0; i < count; i++) { IntPtr currentPtr = new IntPtr(ptrData.ToInt64() + size*i); OTObjectData myData = (OTObjectData) Marshal.PtrToStructure(currentPtr, typeof (OTObjectData)); children.Add( Application.Instance.DaAddressSpaceRoot.GetElementFromArray(myData.m_userData) as DaAddressSpaceElement); } // end for } } // end if OTBFunctions.OTFreeMemory(ptrData); } // end if return children; } // end GetChildren
public void Release() { if (this.m_tpCredentialsNumber > 0) { for (int index = 0; index < m_tpCredentialsNumber; index++) { IntPtr stringPointer = Marshal.ReadIntPtr( m_tpUsers, index*Marshal.SizeOf(typeof (IntPtr))); OTBFunctions.OTFreeMemory(stringPointer); stringPointer = Marshal.ReadIntPtr( m_tpPasswords, index*Marshal.SizeOf(typeof (IntPtr))); OTBFunctions.OTFreeMemory(stringPointer); } // end for m_tpCredentialsNumber = 0; m_tpUsers = IntPtr.Zero; m_tpPasswords = IntPtr.Zero; } // end if } // end Release
public void Release() { OTBFunctions.OTFreeMemory(this.m_definition); if (this.m_subConditionCount > 0) { for (int index = 0; index < m_subConditionCount; index++) { IntPtr stringPointer = Marshal.ReadIntPtr( m_subConditionDefinitions, index*Marshal.SizeOf(typeof (IntPtr))); OTBFunctions.OTFreeMemory(stringPointer); stringPointer = Marshal.ReadIntPtr( m_subConditionDescriptions, index*Marshal.SizeOf(typeof (IntPtr))); OTBFunctions.OTFreeMemory(stringPointer); } // end for OTBFunctions.OTFreeMemory(this.m_subConditionDefinitions); OTBFunctions.OTFreeMemory(this.m_subConditionDescriptions); OTBFunctions.OTFreeMemory(this.m_subConditionSeverities); } // end if } // end Release
//- #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); }
//- #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; }
/// <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); }
//- #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); }