Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
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
Exemplo n.º 5
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
Exemplo n.º 6
0
		} //	end Session


		//-
		#endregion

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

		/// <summary>
		/// Completes all requests must be called while or after "handling" requests
		/// </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="CompleteRequests"]/doc/*'
		/// />
		public int CompleteRequests()
		{
			int result = (int) EnumResultCode.E_FAIL;

			int count = 0;
			OTValueData[] values = null;
			OTSRequestData[] requests = null;
			int[] results = null;

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

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

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

					for (int i = 0; i < count; i++)
					{
						DaRequest request = m_requestList[i] as DaRequest;
						if (request != null)
						{
							requests[i].m_sessionHandle = request.SessionHandle;
							requests[i].m_propertyID = request.PropertyId;
							requests[i].m_requestHandle = request.RequestHandle;

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

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

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

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

						request.RequestState = EnumRequestState.COMPLETED;
					} //	end for

					m_requestList.Clear();
				} //	end lock

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

				result = (int) EnumResultCode.E_FAIL;
			}
			finally
			{
				Application.Instance.ReleaseTransaction(m_key);

				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 CompleteRequests
Exemplo n.º 7
0
		} //	end constructor


		internal ValueQT(ref OTValueData anOtValueData) : base(anOtValueData.m_value)
		{
			this.m_quality = (EnumQuality) anOtValueData.m_quality;
			this.m_timeStamp = anOtValueData.m_timestamp.ToDateTime();
		} //	end constructor