}//	Data

		//-
		#endregion

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

		/// <summary>
		/// Returns the string representation of a <see cref="ValueData"/> object.
		/// </summary>
		/// <returns>A string that represents the textual representation of a <see cref="ValueData"/> object.</returns>
		/// <include
		///  file='TBN.doc.xml'
		///  path='//class[@name="ValueData"]/method[@name="ToString"]/doc/*'
		/// />
		public override string ToString()
		{
			if (Data == null)
			{
				return string.Empty;
			} //	end if

			IntPtr pData = Marshal.AllocCoTaskMem(ValueQT.VARIANT_SIZE);
			Marshal.GetNativeVariantForObject(Data, pData);

			IntPtr pInput = Marshal.AllocCoTaskMem(Marshal.SystemDefaultCharSize*(int) MAX_LENGTH_OF_VARIANT_TO_STRING);

			IntPtr pOutput = OTBFunctions.OTVariantToString(
				pData,
				MAX_LENGTH_OF_VARIANT_TO_STRING,
				pInput);

			string output = Marshal.PtrToStringUni(pOutput);

			Marshal.FreeCoTaskMem(pInput);
			OTBFunctions.OTVariantClear(pData);
			Marshal.FreeCoTaskMem(pData);

			return output;
		} //	end ToString()
		/// <summary>
		/// retrieves the parent from a handle
		/// </summary>
		internal AddressSpaceElement GetParent(uint aHandle)
		{
			if (aHandle == 0)
			{
				return m_root;
			} //	end if

			OTObjectData parent = new OTObjectData();
			IntPtr pParent = Marshal.AllocCoTaskMem(Marshal.SizeOf(parent));
			Marshal.StructureToPtr(parent, pParent, false);

			if ((uint) EnumResultCode.S_OK != OTBFunctions.OTSGetParent(aHandle, pParent))
			{
				return null;
			} //	end if

			parent = (OTObjectData) Marshal.PtrToStructure(pParent, typeof (OTObjectData));
			Marshal.FreeCoTaskMem(pParent);

			AddressSpaceElement elementParent = GetElementFromArray(parent.m_userData);
			if (elementParent == null)
			{
				return m_root;
			} //	end if

			return elementParent;
		} //	end getParent
Exemple #3
0
		} //	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
Exemple #4
0
		} //	end RemoveChild


		/// <summary>
		/// Gets the current value in the element's cache
		/// </summary>
		/// <param name="aValue">out parameter to be filled in with the <see cref="ValueQT"/> instance of the cache value</param>
		/// <returns>
		/// returns a result code that should be checked for success. If S_OK, the value provided is valid.
		/// </returns>
		/// <include
		///		file='TBNS.doc.xml'
		///		path='//class[@name="DaAddressSpaceElement"]/
		///		method[@name="GetCacheValue"]/doc/*'
		///	/>
		public virtual int GetCacheValue(ref ValueQT aValue)
		{
			aValue = null;
			int result = (int) EnumResultCode.E_FAIL;

			if (m_objectHandle != 0 && IoMode != EnumIoMode.NONE)
			{
				OTValueData valueData = new OTValueData();

				//	Allocate space and reset the reserved space
				valueData.m_value = Marshal.AllocCoTaskMem(ValueQT.VARIANT_SIZE);
				Marshal.GetNativeVariantForObject(null, valueData.m_value);

				result = OTBFunctions.OTSGetCacheValue(this.m_objectHandle, ref valueData);

				if (ResultCode.SUCCEEDED(result))
				{
					aValue = new ValueQT(ref valueData);
				} //	end if

				OTBFunctions.OTVariantClear(valueData.m_value);
				Marshal.FreeCoTaskMem(valueData.m_value);
			} //	end if

			return result;
		} //	end GetCacheValue
        /// <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);
        }
Exemple #6
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
Exemple #7
0
		/// <summary>
		/// Releases the resources used by the <see cref="AddressSpaceElement"/> object.
		/// </summary>
		/// <include
		///  file='TBNC.doc.xml'
		///  path='//class[@name="AddressSpaceElement"]/method[@name="Dispose"]/doc/*'
		/// />
		public void Dispose()
		{
			if (m_objectElementHandle != 0)
			{
				OTBFunctions.OTCReleaseAddressSpaceElement(m_objectElementHandle, 0);
			}
		}
Exemple #8
0
		} //	end SetTraceOptions

		//-
		#endregion

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

		/// <summary>
		/// Writes a given message, of a given level, assigned to a given group in the current trace file.
		/// </summary>
		/// <param name="level">The level of tracing. It can be one of the EnumTraceLevel values.</param>
		/// <param name="mask">The group to be traced. It can be one of the EnumTraceGroup values.</param>
		/// <param name="objectID">The identifier for the traced object. (it could be the name of the method
		/// where the trace message is inserted).</param>
		/// <param name="message">The tracing message. It is a free text and denotes the reason of the trace.</param>
		/// <include
		///  file='TBN.doc.xml'
		///  path='//class[@name="Trace"]/method[@name="WriteLine_1"]/doc/*'
		/// />
		public static void WriteLine(
			byte level,
			uint mask,
			string objectID,
			string message)
		{
			string FormattedString = message;
			OTBFunctions.OTTrace(level, mask, objectID, FormattedString);
		} //	end WriteLine
		} //	end ctr


		/// <summary>
		/// AddressSpaceRoot constructor:  Used to build a specialised root type
		/// </summary>
		/// <param name="anAddressSpaceType">
		/// The type of address space
		/// </param>
		/// <param name="aRoot">
		/// An address space element to impersonate the root. This element is not visible in the namespace
		/// </param>
		/// <include
		///		file='TBNS.doc.xml'
		///		path='//class[@name="AddressSpaceRoot"]/
		///		ctor[@name="AddressSpaceRoot.typed"]/doc/*'
		///	/>
		protected AddressSpaceRoot(
			EnumAddressSpaceType anAddressSpaceType,
			AddressSpaceElement aRoot)
		{
			this.m_root = aRoot;
			m_root.HasChildren = true;
			m_namespaceType = anAddressSpaceType;
			int result = OTBFunctions.OTSInitAddressSpace((byte) this.m_namespaceType);
		} //	end ctr
Exemple #10
0
		} //	end WriteLine

		/// <summary>
		/// Writes a given message, of a given level, assigned to a given group in the current trace file.
		/// The line is written based on a given text format.
		/// </summary>
		/// <param name="level">The level of tracing. It can be one of the EnumTraceLevel values.</param>
		/// <param name="mask">The group to be traced. It can be one of the EnumTraceGroup values.</param>
		/// <param name="objectID">The identifier for the traced object. (it could be the name of the method
		/// where the trace message is inserted).</param>
		/// <param name="message">The tracing message. It is a free text and denotes the reason of the trace.</param>
		/// <param name="args">Parameter list for formatted message string.</param>
		/// <include
		///  file='TBN.doc.xml'
		///  path='//class[@name="Trace"]/method[@name="WriteLine_2"]/doc/*'
		/// />
		public static void WriteLine(
			byte level,
			uint mask,
			string objectID,
			string message,
			params object[] args)
		{
			string FormattedString = String.Format(message, args);
			OTBFunctions.OTTrace(level, mask, objectID, FormattedString);
		} //	end WriteLine
		} //	end GetConditionDefinition


		/// <summary>
		/// Adds a subcondition to a condition in the AeCategory.
		/// </summary>
		/// <param name="aConditionName">The existing condition.</param>
		/// <param name="aSubconditionName">New subcondition name.</param>
		/// <returns>
		/// S_OK - if succeeded
		/// E_FAIL - if failure
		/// </returns>
		/// <include
		///		file='TBNS.doc.xml'
		///			path='//class[@name="AeCategory"]/
		///			method[@name="AddSubConditionDefinition"]/doc/*'
		///	/>
		public virtual int AddSubConditionDefinition(
			string aConditionName,
			string aSubconditionName)
		{
			try
			{
				if (aConditionName.Length == 0 || aSubconditionName.Length == 0)
				{
					return (int) EnumResultCode.E_FAIL;
				} //	end if

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

				System.Diagnostics.Debug.Assert(Handle != 0, "Called for Null handle");

				Hashtable syncConditions = Hashtable.Synchronized(this.m_conditions);

				int result = (int) EnumResultCode.S_OK;

				AeConditionDefinition condition = syncConditions[aConditionName] as AeConditionDefinition;
				if (condition == null)
				{
					result = AddConditionDefinition(aConditionName);
					syncConditions = Hashtable.Synchronized(this.m_conditions);
					condition = syncConditions[aConditionName] as AeConditionDefinition;
				} //	end if

				if (ResultCode.SUCCEEDED(result))
				{
					//	at this time the condition should have been be registered
					result = OTBFunctions.OTSAddSubCondition(this.Handle, aConditionName, aSubconditionName);
					if (ResultCode.SUCCEEDED(result))
					{
						result = condition.AddSubConditonData(aSubconditionName);
					} //	end if
				} //	end if

				return result;
			}
			catch (Exception e)
			{
				Application.Instance.Trace(EnumTraceLevel.ERR,
				                           EnumTraceGroup.OPCSERVER,
				                           "Category.AddCondition",
				                           "Exception caught:" + e.ToString());
				return (int) EnumResultCode.E_FAIL;
			} //	end try ... catch
		} //	end AddSubConditionDefinition
Exemple #12
0
		} //	end AddChild


		/// <summary>
		/// Removes the child if there is any. The entire branch of the aChild will be removed as well from the address space.
		/// </summary>
		/// <param name="aChild">AddressSpaceElement child to be removed from this instance</param>
		/// <returns>
		/// true	- aChild removed
		/// false	- aChild was not removed
		/// </returns>
		/// <include
		///		file='TBNS.doc.xml'
		///		path='//class[@name="DaAddressSpaceElement"]/
		///		method[@name="RemoveChild"]/doc/*'
		///	/>
		public override bool RemoveChild(AddressSpaceElement aChild)
		{
			if (!HasChildren)
			{
				//	just log a warning, but proceed then with the removal attempt
				Application.Instance.Trace(
					EnumTraceLevel.WRN, EnumTraceGroup.OPCSERVER,
					"DaAddressSpaceElement.RemoveChild", "This element does not allow childred");
			} //	end if

			DaAddressSpaceElement child = aChild as DaAddressSpaceElement;

			if (child == null)
			{
				Application.Instance.Trace(EnumTraceLevel.WRN, EnumTraceGroup.OPCSERVER,
				                           "DaAddressSpaceElement.RemoveChild", "Invalid child provided");
				return false;
			} //	end if

			if (child.HasChildren)
			{
				//	Remove the clildren of the child
				ArrayList otherChildren = child.GetChildren();

				foreach (AddressSpaceElement element in otherChildren)
				{
					child.RemoveChild(element);
				} //	end for
			} //	end if

			int result = OTBFunctions.OTSRemoveAddressSpaceElement(child.ObjectHandle);
			if (!ResultCode.SUCCEEDED(result))
			{
				Application.Instance.Trace(EnumTraceLevel.WRN, EnumTraceGroup.OPCSERVER,
				                           "DaAddressSpaceElement.RemoveChild",
				                           "OTSRemoveAddressSpaceElement has failed with code" + result.ToString());
				return false;
			} //	end if

			result = Application.Instance.DaAddressSpaceRoot.RemoveElementFromArray(child);
			if (!ResultCode.SUCCEEDED(result))
			{
				Application.Instance.Trace(EnumTraceLevel.WRN, EnumTraceGroup.OPCSERVER,
				                           "DaAddressSpaceElement.RemoveChild",
				                           "RemoveElementFromArray has failed with code" + result.ToString());
				return false;
			} //	end if

			return base.RemoveChild(aChild);
		} //	end RemoveChild
        /// <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);
        }
Exemple #14
0
		} //	end GetSubConditionDefinition


		/// <summary>
		/// CreateOTSConditionDefinitionData
		/// </summary>
		internal OTSConditionDefinitionData CreateOTSConditionDefinitionData()
		{
			OTSConditionDefinitionData conditionDefinitionData = new OTSConditionDefinitionData();
			conditionDefinitionData.m_definition = OTBFunctions.AllocateOTBString(this.m_definition);

			Hashtable syncSubconditions = Hashtable.Synchronized(m_subconditions);

			conditionDefinitionData.m_subConditionCount = (uint) syncSubconditions.Count;
			if (syncSubconditions.Count > 0)
			{
				conditionDefinitionData.m_subConditionDefinitions =
					OTBFunctions.OTAllocateMemory(syncSubconditions.Count*Marshal.SizeOf(typeof (IntPtr)));

				conditionDefinitionData.m_subConditionDescriptions =
					OTBFunctions.OTAllocateMemory(syncSubconditions.Count*Marshal.SizeOf(typeof (IntPtr)));

				conditionDefinitionData.m_subConditionSeverities =
					OTBFunctions.OTAllocateMemory(syncSubconditions.Count*Marshal.SizeOf(typeof (uint)));

				int index = 0;

				foreach (AeSubConditionDefinition subCondition in syncSubconditions.Values)
				{
					IntPtr definitionPointer = OTBFunctions.AllocateOTBString(subCondition.Definition);
					Marshal.WriteIntPtr(
						conditionDefinitionData.m_subConditionDefinitions,
						index*Marshal.SizeOf(typeof (IntPtr)),
						definitionPointer);

					IntPtr descriptionPointer = OTBFunctions.AllocateOTBString(subCondition.Description);
					Marshal.WriteIntPtr(
						conditionDefinitionData.m_subConditionDescriptions,
						index*Marshal.SizeOf(typeof (IntPtr)),
						descriptionPointer);

					Marshal.WriteInt32(conditionDefinitionData.m_subConditionSeverities,
					                   index*Marshal.SizeOf(typeof (uint)),
					                   (int) subCondition.Severity);
					index++;
				} //	end foreach
			} //	end if

			return conditionDefinitionData;
		} //	end CreateOTSConditionDefinitionData
Exemple #15
0
		public IntPtr m_pEventAttrs = IntPtr.Zero; //	array with all event attributes

		public void Release()
		{
			Marshal.FreeCoTaskMem(this.m_sourcePath);
			Marshal.FreeCoTaskMem(this.m_message);
			Marshal.FreeCoTaskMem(this.m_actorID);

			if (this.m_eventAttrCount != 0 &&
			    this.m_pEventAttrs != IntPtr.Zero)
			{
				IntPtr currentPointer = this.m_pEventAttrs;
				for (int index = 0; index < this.m_eventAttrCount; index++)
				{
					OTBFunctions.OTVariantClear(currentPointer);
					currentPointer = new IntPtr(currentPointer.ToInt64() + ValueQT.VARIANT_SIZE);
				} //	end for

				Marshal.FreeCoTaskMem(this.m_pEventAttrs);
			} //	end if
		} //	end Release
        /// <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);
        }
Exemple #17
0
		} //	end QueryProperties


		/// <summary>
		/// Changes value cache value of this element instance
		/// </summary>
		/// <param name="aNewValue"></param>
		/// <returns>
		/// E_INVALIDARG - Invalid valueQT was passed
		/// S_OK - Value changed
		/// OTS_E_EXCEPTION - Unexpected error occurred
		/// </returns>
		/// <include
		///		file='TBNS.doc.xml'
		///		path='//class[@name="DaAddressSpaceElement"]/
		///		method[@name="ValueChanged"]/doc/*'
		///	/>
		public virtual int ValueChanged(ValueQT aNewValue)
		{
			if (this.ObjectHandle == 0)
			{
				return (int) EnumResultCode.E_FAIL;
			} //	end if

			OTValueData valueData = new OTValueData();
			valueData.m_quality = (ushort) aNewValue.Quality;
			valueData.m_timestamp = new OTDateTime(aNewValue.TimeStamp);

			valueData.m_value = Marshal.AllocCoTaskMem(ValueQT.VARIANT_SIZE);
			Marshal.GetNativeVariantForObject(aNewValue.Data, valueData.m_value);

			int result = OTBFunctions.OTSValuesChanged(1, new uint[1] {ObjectHandle}, new OTValueData[1] {valueData});

			OTBFunctions.OTVariantClear(valueData.m_value);
			Marshal.FreeCoTaskMem(valueData.m_value);
			return result;
		} //	end ValueChanged
		//-----------------------------

		/// <summary>
		/// Default public constructor
		/// </summary>
		/// <include
		///		file='TBNS.doc.xml'
		///		path='//class[@name="DaRequest"]/
		///		ctor[@name="DaRequest"]/doc/*'
		///	/>
		public DaRequest(
			EnumTransactionType aTransactionType,
			uint aSessionHandle,
			DaAddressSpaceElement anElement,
			int aPropertyId,
			uint aRequestHandle)
		{
			m_transactionType = aTransactionType;
			m_sessionHandle = aSessionHandle;
			m_requestHandle = aRequestHandle;
			m_propertyId = aPropertyId;
			m_addressSpaceElement = anElement;
			m_transactionKey = 0;
			m_result = EnumResultCode.E_NOTIMPL;
			m_requestState = EnumRequestState.CREATED;

			if (m_addressSpaceElement != null)
			{
				OTBFunctions.OTSAckRequestElement(m_addressSpaceElement.ObjectHandle);
			}
		} //	end ctr
        //-
        #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);
        }
		} //	end AddAttribute


		/// <summary>
		/// adds a new condition definition object with the name provided as aConditionDefinition
		/// </summary>
		/// <param name="aConditionName">the condition name</param>
		/// <returns>
		/// S_OK - if succeeded
		/// E_FAIL - if failure
		/// </returns>
		/// <include
		///		file='TBNS.doc.xml'
		///			path='//class[@name="AeCategory"]/
		///			method[@name="AddConditionDefinition"]/doc/*'
		///	/>
		public virtual int AddConditionDefinition(string aConditionName)
		{
			try
			{
				if (aConditionName.Length == 0)
				{
					return (int) EnumResultCode.E_FAIL;
				} //	end if

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

				int result = OTBFunctions.OTSAddCondition(this.Handle, aConditionName);

				if (ResultCode.SUCCEEDED(result))
				{
					Hashtable syncConditions = Hashtable.Synchronized(this.m_conditions);

					//	Check for a duplicate condition
					AeConditionDefinition condition = syncConditions[aConditionName] as AeConditionDefinition;
					if (condition == null)
					{
						condition = new AeConditionDefinition(aConditionName);
						syncConditions.Add(aConditionName, condition);
					} //	end if
				} //	end if

				return result;
			}
			catch (Exception e)
			{
				Application.Instance.Trace(EnumTraceLevel.ERR,
				                           EnumTraceGroup.OPCSERVER,
				                           "Category.AddCondition",
				                           "Exception caught:" + e.ToString());
				return (int) EnumResultCode.E_FAIL;
			} //	enc try ... catch
		} //	end AddConditionDefinition
Exemple #21
0
		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
Exemple #22
0
		} //	end QueryAddressSpaceElementChildren


		/// <summary>
		/// Changes the cache value for the Address space elements provided
		/// </summary>
		/// <param name="anElementList">the namespace elements</param>
		/// <param name="aValueList">the corresponding values</param>
		/// <returns>
		/// E_INVALIDARG - Invalid valueQT was passed
		/// S_OK - Value changed
		/// OTS_E_EXCEPTION - Unexpected error occurred
		/// </returns>
		/// <include
		///		file='TBNS.doc.xml'
		///		path='//class[@name="DaAddressSpaceRoot"]/
		///		method[@name="ValuesChanged.array"]/doc/*'
		///	/>
		public int ValuesChanged(DaAddressSpaceElement[] anElementList, ValueQT[] aValueList)
		{
			if (anElementList.Length != aValueList.Length)
			{
				return (int) EnumResultCode.E_INVALIDARG;
			} //	end if

			int count = anElementList.Length;

			if (count == 0)
			{
				return (int) EnumResultCode.S_FALSE;
			} //	end if

			OTValueData[] aoValues = new OTValueData[count];
			uint[] ahObjects = new uint[count];

			for (int i = 0; i < count; i++)
			{
				ahObjects[i] = anElementList[i].ObjectHandle;
				aoValues[i] = new OTValueData();
				aoValues[i].m_quality = (ushort) aValueList[i].Quality;
				aoValues[i].m_timestamp = new OTDateTime(aValueList[i].TimeStamp);
				aoValues[i].m_value = Marshal.AllocCoTaskMem(ValueQT.VARIANT_SIZE);
				Marshal.GetNativeVariantForObject(aValueList[i].Data, aoValues[i].m_value);
			} //	end for

			int result = OTBFunctions.OTSValuesChanged(count, ahObjects, aoValues);

			for (int i = 0; i < count; i++)
			{
				OTBFunctions.OTVariantClear(aoValues[i].m_value);
				Marshal.FreeCoTaskMem(aoValues[i].m_value);
			} //	end for

			return result;
		} //	end ValuesChanged
		} //	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
Exemple #24
0
		} //	end MaximumBackups
		//-
		#endregion

		#region //	Internal Static Methods
		//------------------------

		/// <summary>
		/// Forwards to the OTB the trace settings call.
		/// </summary>
		/// <param name="aTraceDataMask">
		/// The trace settings mask to be changed within OTB.
		/// </param>
		internal static void SetTraceOptions(EnumTraceData aTraceDataMask)
		{
#if !NET20 && !NET35 && !NET40 && !NET45 && !NET46
			string osVersion = Environment.OSVersion.Version.ToString();
#else
			string osVersion = Environment.OSVersion.VersionString;
#endif

			string apiData = "TBN " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() +
				", built with .NET " + Environment.Version.ToString() + ", running on " + osVersion;

			if (IntPtr.Size == 8)
			{
				apiData += " x64";
			}
			else
			{
				apiData += " x86";
			}

			m_traceData.m_apiVersion = apiData;

			OTBFunctions.OTEnableTracing((uint)aTraceDataMask, m_traceData);
		} //	end SetTraceOptions
Exemple #25
0
		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
Exemple #26
0
		/// <summary>
		/// Completes a single request and removes it from the transaction
		/// </summary>
		/// <returns>
		/// S_OK - Everything was OK
		/// S_FALSE - Everything was OK
		/// The Result should be checked with ResultCode.SUCCEEDED
		/// or with ResultCode.FAILED
		/// </returns>
		/// <include
		///  file='TBNS.doc.xml'
		///  path='//class[@name="DaTransaction"]/
		///  method[@name="CompleteRequest"]/doc/*'
		/// />
		public int CompleteRequest(DaRequest aRequest)
		{
			int result = (int) EnumResultCode.E_FAIL;

			OTValueData[] values = new OTValueData[1];
			OTSRequestData[] requests = new OTSRequestData[1];
			int[] results = new int[1];

			try
			{
				DaRequest request = aRequest as DaRequest;

				if (request != null)
				{
					request.RequestState = EnumRequestState.COMPLETED;

					//	remove the request from the list
					RemoveRequest(request);

					requests[0].m_sessionHandle = request.SessionHandle;
					requests[0].m_propertyID = request.PropertyId;
					requests[0].m_requestHandle = request.RequestHandle;

					if (request.AddressSpaceElement != null)
					{
						requests[0].m_object.m_userData = (uint) request.AddressSpaceElement.UserData;
						requests[0].m_object.m_objectHandle = request.AddressSpaceElement.ObjectHandle;
					}
					else
					{
						requests[0].m_object.m_userData = 0;
						requests[0].m_object.m_objectHandle = 0;
					} //	end if ... else

					values[0] = new OTValueData();
					if (request.Value != null)
					{
						values[0].m_timestamp = new OTDateTime(request.Value.TimeStamp);
						values[0].m_quality = (ushort) request.Value.Quality;
						values[0].m_value = Marshal.AllocCoTaskMem(ValueQT.VARIANT_SIZE);
						Marshal.GetNativeVariantForObject(request.Value.Data, values[0].m_value);

						results[0] = (int) request.Result;
					}
					else
					{
						values[0].m_quality = (ushort) EnumQuality.BAD;
						values[0].m_value = Marshal.AllocCoTaskMem(ValueQT.VARIANT_SIZE);
						Marshal.GetNativeVariantForObject(null, values[0].m_value);
						results[0] = (int) EnumResultCode.E_UNEXPECTED;
					} //	end if ... else
				}
				else
				{
					requests[0].m_sessionHandle = 0;
					requests[0].m_propertyID = 0;
					requests[0].m_requestHandle = 0;
					requests[0].m_object.m_userData = 0;
					requests[0].m_object.m_objectHandle = 0;

					values[0] = new OTValueData();
					values[0].m_quality = (ushort) EnumQuality.BAD;
					values[0].m_value = Marshal.AllocCoTaskMem(ValueQT.VARIANT_SIZE);
					Marshal.GetNativeVariantForObject(null, values[0].m_value);
					results[0] = (int) EnumResultCode.E_UNEXPECTED;
				} //	end if ... else

				result = OTBFunctions.OTSCompleteRequests(1, requests, results, values);
			}
			catch (Exception e)
			{
				Application.Instance.Trace(
					EnumTraceLevel.ERR, EnumTraceGroup.OPCSERVER,
					"DaTransaction.CompleteRequest", "Exception caught: " + e.ToString());

				result = (int) EnumResultCode.E_FAIL;
			}
			finally
			{
				if (this.IsEmpty)
				{
					Application.Instance.ReleaseTransaction(m_key);
				}
				OTBFunctions.OTVariantClear(values[0].m_value);
				Marshal.FreeCoTaskMem(values[0].m_value);
			} //	end try ... catch ... finally

			return result;
		} //	end CompleteRequest
        //-
        #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 #28
0
		} //	end SetEUInfoAnalog


		/// <summary>
		///
		/// </summary>
		/// <param name="enumeratedValues"></param>
		/// <returns></returns>
		/// <include
		///		file='TBNS.doc.xml'
		///		path='//class[@name="DaAddressSpaceElement"]/
		///		method[@name="SetEUInfoEnumerated"]/doc/*'
		///	/>
		public int SetEUInfoEnumerated(string[] enumeratedValues)
		{
			return OTBFunctions.OTSSetEUInfo(m_objectHandle, true, enumeratedValues.Length, enumeratedValues, 0, 0);
		} //	end SetEUInfoEnumerated
Exemple #29
0
		} //	end Change


		/// <summary>
		/// Used to add the Engineering Units related properties as Analog EU type
		/// </summary>
		/// <param name="lowEULimit">Low value for the property 102</param>
		/// <param name="highEULimit">High value for the property 103</param>
		/// <returns>result code</returns>
		/// <include
		///		file='TBNS.doc.xml'
		///		path='//class[@name="DaAddressSpaceElement"]/
		///		method[@name="SetEUInfoAnalog"]/doc/*'
		///	/>
		public int SetEUInfoAnalog(double lowEULimit, double highEULimit)
		{
			return OTBFunctions.OTSSetEUInfo(m_objectHandle, false, 0, null, lowEULimit, highEULimit);
		} //	end SetEUInfoAnalog
Exemple #30
0
		} //	end CompleteRequest


		/// <summary>
		/// Changes the cache value for the Address space elements provided
		/// </summary>
		/// <returns>
		/// E_INVALIDARG - Invalid valueQT was passed
		/// S_OK - Value changed
		/// OTS_E_EXCEPTION - Unexpected error occurred
		/// The Result should be checked with ResultCode.SUCCEEDED
		/// or with ResultCode.FAILED
		/// </returns>
		/// <include
		///  file='TBNS.doc.xml'
		///  path='//class[@name="DaTransaction"]/
		///  method[@name="ValuesChanged"]/doc/*'
		/// />
		public int ValuesChanged()
		{
			int result;
			int count = 0;
			OTValueData[] values = null;
			uint[] handles = null;

			try
			{
				lock (m_requestListJanitor)
				{
					count = m_requestList.Count;

					values = new OTValueData[count];
					handles = new uint[count];

					for (int i = 0; i < count; i++)
					{
						OTValueData valueData = new OTValueData();
						DaRequest request = m_requestList[i] as DaRequest;

						if (request != null)
						{
							valueData.m_quality = (ushort) request.Value.Quality;
							valueData.m_timestamp = new OTDateTime(request.Value.TimeStamp);
							valueData.m_value = Marshal.AllocCoTaskMem(ValueQT.VARIANT_SIZE);

							Marshal.GetNativeVariantForObject(request.Value.Data, valueData.m_value);
							handles[i] = request.AddressSpaceElement.ObjectHandle;

							request.Result = EnumResultCode.S_OK;
						}
						else
						{
							valueData.m_quality = (ushort) EnumQuality.BAD;
							valueData.m_value = Marshal.AllocCoTaskMem(ValueQT.VARIANT_SIZE);
							Marshal.GetNativeVariantForObject(null, valueData.m_value);
							handles[i] = 0;
						} //	end if ... else

						values[i] = valueData;
					} //	end for
					result = OTBFunctions.OTSValuesChanged(count, handles, values);
				} //	end lock
			}
			catch (Exception e)
			{
				Application.Instance.Trace(
					EnumTraceLevel.ERR, EnumTraceGroup.OPCSERVER,
					"DaTransaction.ValuesChanged", "Exception caught: " + e.ToString());
				result = (int) EnumResultCode.E_FAIL;
			}
			finally
			{
				for (int i = 0; i < count; i++)
				{
					OTBFunctions.OTVariantClear(values[i].m_value);
					Marshal.FreeCoTaskMem(values[i].m_value);
				} //	end for
			} //	end try ... catch ... finally

			return result;
		} //	end ValuesChanged