Exemplo n.º 1
0
        private TestResult ValidateBrowsedElements(Softing.OPCToolbox.Client.DaAddressSpaceElement[] elements, int result)
        {
            if (ResultCode.SUCCEEDED(result))
            {
                if (!string.IsNullOrEmpty(Property))
                {
                    SetProperty(Property, elements);
                }

                if (ExpectedElements.Count != 0 && ExpectedElements.Count != elements.Length)
                {
                    return(new DaBrowseResult(result, elements, "Unexpected number of results"));
                }

                for (int i = 0; i < ExpectedElements.Count; i++)
                {
                    Softing.OPCToolbox.Client.DaAddressSpaceElement receivedElement = elements[i];
                    DaAddressSpaceElement expectedElement = ExpectedElements[i];

                    if ((expectedElement.ItemId != null && expectedElement.ItemId != receivedElement.ItemId) ||
                        (expectedElement.ItemPath != null && expectedElement.ItemPath != receivedElement.ItemPath) ||
                        (expectedElement.Name != null && expectedElement.Name != receivedElement.Name) ||
                        (expectedElement.IsItem.HasValue && expectedElement.IsItem.Value != receivedElement.IsItem) ||
                        (expectedElement.IsBranch.HasValue && expectedElement.IsBranch.Value != receivedElement.IsBranch) ||
                        (expectedElement.IsLeaf.HasValue && expectedElement.IsLeaf.Value != receivedElement.IsLeaf))
                    {
                        return(new DaBrowseResult(result, elements, string.Format("Unexpected result for item #{0}", i)));
                    }
                }

                return(new DaBrowseResult(result, elements));
            }
            else
            {
                EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());
                if (!string.IsNullOrEmpty(ExpectedServiceResult))
                {
                    EnumResultCode expectedResCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), ExpectedServiceResult.ToString());
                    if (expectedResCode != resCode)
                    {
                        return(TestResult.Failed(string.Format("Unexpected service result: expected {0}, actual {1}", resCode, expectedResCode)));
                    }
                    return(TestResult.Success());
                }

                return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
            }
        }
Exemplo n.º 2
0
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(SessionProperty))
            {
                return(TestResult.ParameterMissing("Session"));
            }

            DaSession session = GetProperty(SessionProperty) as DaSession;

            if (session == null)
            {
                return(TestResult.ParameterInvalid("Session"));
            }

            try
            {
                Softing.OPCToolbox.Client.DaAddressSpaceElement[] adElements;

                Softing.OPCToolbox.Client.DaAddressSpaceElement rootDaAddressSpaceElement = new Softing.OPCToolbox.Client.DaAddressSpaceElement(
                    EnumAddressSpaceElementType.BRANCH, String.Empty, string.Empty, string.Empty, 0, null);
                rootDaAddressSpaceElement.Session = session;

                int result = rootDaAddressSpaceElement.Browse(new Softing.OPCToolbox.Client.DaAddressSpaceElementBrowseOptions(), out adElements, new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, m_asyncExecutionContext));

                Softing.OPCToolbox.Client.DaAddressSpaceElement addressSpaceElement = null;
                if (ResultCode.SUCCEEDED(result))
                {
                    for (int i = 0; i < adElements.Length; i++)
                    {
                        if (adElements[i].ItemId == RootID)
                        {
                            addressSpaceElement = adElements[i];
                        }
                    }
                }
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                    return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                }

                if (addressSpaceElement == null)
                {
                    return(TestResult.Failed(string.Format("Address space element {0} not found!", RootID)));
                }

                Softing.OPCToolbox.Client.DaProperty[] elements;
                result = int.MaxValue;
                if (ExecutionType == EnumExecutionType.SYNCHRONOUS)
                {
                    result = addressSpaceElement.GetDaProperties(DaGetPropertiesOptions, out elements, new ExecutionOptions(ExecutionType, 0));
                }
                else
                {
                    m_asyncExecutionContext           = DaExecutionContext.Next;
                    session.GetDaPropertiesCompleted += session_GetDaPropertiesCompleted;
                    m_waitHandle = new System.Threading.AutoResetEvent(false);
                    result       = addressSpaceElement.GetDaProperties(DaGetPropertiesOptions, out elements, new ExecutionOptions(EnumExecutionType.ASYNCHRONOUS, m_asyncExecutionContext));

                    if (m_waitHandle.WaitOne(3000))
                    {
                        result   = m_browseAsyncResult;
                        elements = m_browseAsyncResults;
                    }
                    session.GetDaPropertiesCompleted -= session_GetDaPropertiesCompleted;
                }

                if (ResultCode.SUCCEEDED(result))
                {
                    if (!string.IsNullOrEmpty(Property))
                    {
                        SetProperty(Property, elements);
                    }

                    if (ExpectedElements.Count != 0 && ExpectedElements.Count != elements.Length)
                    {
                        return(TestResult.Failed(string.Format("Unexpected number of results, expected {0}, actual {1}", ExpectedElements.Count, elements.Length)));
                    }

                    for (int i = 0; i < ExpectedElements.Count; i++)
                    {
                        Softing.OPCToolbox.Client.DaProperty receivedElement = elements[i];
                        TestClientGui.Support.DaProperty     expectedElement = ExpectedElements[i];

                        if ((expectedElement.ItemId != null && expectedElement.ItemId != receivedElement.ItemId) ||
                            (expectedElement.ItemPath != null && expectedElement.ItemPath != receivedElement.ItemPath) ||
                            (!string.IsNullOrEmpty(expectedElement.Name) && expectedElement.Name != receivedElement.Name) ||
                            (expectedElement.DataType != null && expectedElement.DataType != receivedElement.DataType) ||
                            (!string.IsNullOrEmpty(expectedElement.Description) && expectedElement.Description != receivedElement.Description) ||
                            (expectedElement.ValueQT != null && !expectedElement.ValueQT.Data.Equals(receivedElement.ValueQT.Data)) ||
                            (expectedElement.ValueQT != null && expectedElement.ValueQT.Quality != receivedElement.ValueQT.Quality))
                        {
                            return(TestResult.Failed(string.Format("Unexpected result for item #{0}", i)));
                        }

                        if (DaGetPropertiesOptions.WhatPropertyData == EnumPropertyData.ITEMID || DaGetPropertiesOptions.WhatPropertyData == EnumPropertyData.NONE)
                        {
                            if (receivedElement.ValueQT.Data != null)
                            {
                                return(TestResult.Failed(string.Format("Value was not NULL for element #{0}", i)));
                            }
                        }
                        if (DaGetPropertiesOptions.WhatPropertyData == EnumPropertyData.VALUE)
                        {
                            if (!string.IsNullOrEmpty(receivedElement.ItemId))
                            {
                                return(TestResult.Failed(string.Format("ItemId was not NULL for element #{0}", i)));
                            }
                        }
                    }

                    return(TestResult.Success());
                }
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                    return(TestResult.Failed(string.Format("Call returned: {0}\t({1})", resCode.ToString(), result)));
                }
            }
            catch (Exception ex)
            {
                return(new TestResult(ex));
            }
        }
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(Session))
            {
                return(TestResult.ParameterMissing("Session"));
            }
            if (string.IsNullOrEmpty(RootID))
            {
                return(TestResult.ParameterMissing("RootID"));
            }
            //	if (string.IsNullOrEmpty(RootPath))
            //	return TestResult.ParameterMissing("RootPath");


            Softing.OPCToolbox.Client.DaSession session = GetProperty(Session) as DaSession;
            if (session == null)
            {
                return(TestResult.Failed("Session non existent"));
            }

            try
            {
                ExecutionOptions executionOptions = new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, 0);
                session.Connect(false, false, executionOptions);

                Softing.OPCToolbox.Client.DaAddressSpaceElement[] elements;

                Softing.OPCToolbox.Client.DaAddressSpaceElement rootDaAddressSpaceElement = new Softing.OPCToolbox.Client.DaAddressSpaceElement(
                    EnumAddressSpaceElementType.BRANCH, String.Empty, string.Empty, string.Empty, 0, null);
                rootDaAddressSpaceElement.Session = session;


                int result = rootDaAddressSpaceElement.Browse(new Softing.OPCToolbox.Client.DaAddressSpaceElementBrowseOptions(), out elements, new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, m_asyncExecutionContext));

                if (!ResultCode.SUCCEEDED(result))
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                    return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                }

                Softing.OPCToolbox.Client.DaAddressSpaceElement addressSpaceElement = null;
                for (int i = 0; i < elements.Length; i++)
                {
                    if (elements[i].ItemId == RootID)
                    {
                        addressSpaceElement = elements[i];
                        break;
                    }
                }

                if (addressSpaceElement == null)
                {
                    return(TestResult.Failed(string.Format("Address space element {0} not found!", RootID)));
                }

                if (BrowseOptions == null)
                {
                    BrowseOptions = new DaAddressSpaceElementBrowseOptions();
                }



                if (ResultCode.SUCCEEDED(addressSpaceElement.Browse(BrowseOptions.Wrapped, out elements, new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, 0))))
                {
                    //Softing.OPCToolbox.Client.DaAddressSpaceElement daElement;
                    Softing.OPCToolbox.Client.DaSubscription workerSubscription = new Softing.OPCToolbox.Client.DaSubscription(updateRate, session);

                    foreach (Softing.OPCToolbox.Client.DaAddressSpaceElement daElement in elements)
                    {
                        DaItem newItem = new DaItem(daElement.ItemId, workerSubscription);
                        //	result =  Connect(true, true, executionOptions);
                    }

                    result = workerSubscription.Connect(true, true, executionOptions);
                    if (ResultCode.FAILED(result))
                    {
                        EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                        return(TestResult.Failed(string.Format("Subscribe Call returned: {0}  ({1})", resCode.ToString(), result)));
                    }

                    SetProperty(Property, workerSubscription);
                }//end if
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                    return(TestResult.Failed(string.Format(" Browse Call returned: {0}  ({1})", resCode.ToString(), result)));
                }
            }
            catch (Exception ex)
            {
                if (ExpectedSuccess)
                {
                    return(new TestResult(ex));
                }
            }

            return(TestResult.Success());
        }
Exemplo n.º 4
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;
		}
Exemplo n.º 5
0
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(SessionProperty))
            {
                return(TestResult.ParameterMissing("Session"));
            }

            DaSession session = GetProperty(SessionProperty) as DaSession;

            if (session == null)
            {
                return(TestResult.ParameterInvalid("Session"));
            }

            try
            {
                Softing.OPCToolbox.Client.DaAddressSpaceElement[] elements;

                Softing.OPCToolbox.Client.DaAddressSpaceElement rootDaAddressSpaceElement = new Softing.OPCToolbox.Client.DaAddressSpaceElement(
                    EnumAddressSpaceElementType.BRANCH, String.Empty, string.Empty, string.Empty, 0, null);
                rootDaAddressSpaceElement.Session = session;

                int result = rootDaAddressSpaceElement.Browse(new Softing.OPCToolbox.Client.DaAddressSpaceElementBrowseOptions(), out elements, new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, m_asyncExecutionContext));

                if (!ResultCode.SUCCEEDED(result))
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                    return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                }

                Softing.OPCToolbox.Client.DaAddressSpaceElement addressSpaceElement = null;
                for (int i = 0; i < elements.Length; i++)
                {
                    if (elements[i].ItemId == RootID)
                    {
                        addressSpaceElement = elements[i];
                        break;
                    }
                }

                if (addressSpaceElement == null)
                {
                    return(TestResult.Failed(string.Format("Address space element {0} not found!", RootID)));
                }

                if (BrowseOptions == null)
                {
                    BrowseOptions = new DaAddressSpaceElementBrowseOptions();
                }

                if (ExecutionType == EnumExecutionType.SYNCHRONOUS)
                {
                    //browse again => this time the specified item id
                    result = addressSpaceElement.Browse(BrowseOptions.Wrapped, out elements, new ExecutionOptions(ExecutionType, 0));
                }
                else
                {
                    m_asyncExecutionContext  = DaExecutionContext.Next;
                    session.BrowseCompleted += session_BrowseCompleted;
                    m_waitHandle             = new System.Threading.AutoResetEvent(false);
                    result = addressSpaceElement.Browse(BrowseOptions.Wrapped, out elements, new ExecutionOptions(EnumExecutionType.ASYNCHRONOUS, m_asyncExecutionContext));

                    if (m_waitHandle.WaitOne(3000))
                    {
                        result   = m_browseAsyncResult;
                        elements = m_browseAsyncResults;
                    }
                    session.BrowseCompleted -= session_BrowseCompleted;
                }

                if (ResultCode.SUCCEEDED(result))
                {
                    if (!string.IsNullOrEmpty(Property))
                    {
                        SetProperty(Property, elements);
                    }

                    if (ExpectedElements.Count != 0 && ExpectedElements.Count != elements.Length)
                    {
                        return(new DaBrowseResult(result, elements, "Unexpected number of results"));
                    }

                    for (int i = 0; i < ExpectedElements.Count; i++)
                    {
                        Softing.OPCToolbox.Client.DaAddressSpaceElement receivedElement = elements[i];
                        DaAddressSpaceElement expectedElement = ExpectedElements[i];

                        if ((expectedElement.ItemId != null && expectedElement.ItemId != receivedElement.ItemId) ||
                            (expectedElement.ItemPath != null && expectedElement.ItemPath != receivedElement.ItemPath) ||
                            (expectedElement.Name != null && expectedElement.Name != receivedElement.Name) ||
                            (expectedElement.IsItem.HasValue && expectedElement.IsItem.Value != receivedElement.IsItem) ||
                            (expectedElement.IsBranch.HasValue && expectedElement.IsBranch.Value != receivedElement.IsBranch) ||
                            (expectedElement.IsLeaf.HasValue && expectedElement.IsLeaf.Value != receivedElement.IsLeaf))
                        {
                            return(new DaBrowseResult(result, elements, string.Format("Unexpected result for item #{0}", i)));
                        }
                    }

                    return(new DaBrowseResult(result, elements));
                }
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                    return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                }
            }
            catch (Exception ex)
            {
                return(new TestResult(ex));
            }
        }