示例#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)));
            }
        }
示例#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[] 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));
            }
        }