コード例 #1
0
		} //	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
コード例 #2
0
		} //	end GetConditionDefinition


		//-
		#endregion

		#region //	Protected Methods
		//---------------------------

		/// <summary>
		///	Adds an existing attribute object to the category internal hashtable
		/// </summary>
		/// <param name="anAttribute"> an already created instance of the attribute</param>
		/// <returns>
		/// S_OK - if succeeded
		/// E_FAIL - if failure
		/// </returns>
		/// <include
		///		file='TBNS.doc.xml'
		///			path='//class[@name="AeCategory"]/
		///			method[@name="AddAttribute.existing"]/doc/*'
		///	/>
		protected virtual int AddAttribute(AeAttribute anAttribute)
		{
			try
			{
				if (anAttribute == null)
				{
					return (int) EnumResultCode.E_FAIL;
				} //	end if

				if (Handle == 0)
				{
					return (int) EnumResultCode.E_FAIL;
				} //	end if

				int result = OTBFunctions.OTSAddEventAttribute(
					this.Handle,
					anAttribute.Id,
					anAttribute.Name,
					ValueQT.GetVartype(anAttribute.DataType));

				if (ResultCode.SUCCEEDED(result))
				{
					Hashtable syncAttributeList = Hashtable.Synchronized(this.m_attributes);
					syncAttributeList.Add(anAttribute.Id, anAttribute);
				} //	end if

				return result;
			}
			catch (Exception e)
			{
				Application.Instance.Trace(EnumTraceLevel.ERR,
				                           EnumTraceGroup.OPCSERVER,
				                           "Category.AddAttribute",
				                           "Exception caught:" + e.ToString());
				return (int) EnumResultCode.E_FAIL;
			} //	end try ... catch
		} //	end AddAttribute
コード例 #3
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;
		}