예제 #1
0
        /// <summary>
        /// Changes the browse position.
        /// </summary>
        /// <param name="direction">The direction.</param>
        /// <param name="qualifiedName">The qualified area name.</param>
        private bool ChangeBrowsePosition(OPCAEBROWSEDIRECTION direction, string qualifiedName)
        {
            string methodName = "IOPCEventAreaBrowser.CreateAreaBrowser";

            try
            {
                IOPCEventAreaBrowser server = BeginComCall <IOPCEventAreaBrowser>(methodName, true);
                server.ChangeBrowsePosition(direction, qualifiedName);
                return(true);
            }
            catch (Exception e)
            {
                if (ComUtils.IsUnknownError(e, ResultIds.E_FAIL))
                {
                    ComCallError(methodName, e);
                }

                return(false);
            }
            finally
            {
                EndComCall(methodName);
            }
        }
예제 #2
0
        /// <summary>
        /// Provides a way to move �up� or �down� in a hierarchical space from the current position, or a way to move to a specific position in the area space tree. The target szString must represent an area, rather than a source.
        /// </summary>
        /// <param name="dwBrowseDirection">OPCAE_BROWSE_UP, OPCAE_BROWSE_DOWN, or OPCAE_BROWSE_TO</param>
        /// <param name="szString">
        /// For DOWN, the partial area name of the area to move into. This would be one of the strings returned from BrowseOPCAreas.
        /// For UP this parameter is ignored and should point to a NULL string.
        /// For BROWSE_TO, the fully qualified area name (as obtained from GetQualifiedAreaName method) or a pointer to a NUL string to go to the root.
        /// </param>
        public void ChangeBrowsePosition(OPCAEBROWSEDIRECTION dwBrowseDirection, string szString)
        {
            lock (m_lock)
            {
				try
                {
                    switch (dwBrowseDirection)
                    {
                        // move to a specified position or root.
                        case OPCAEBROWSEDIRECTION.OPCAE_BROWSE_TO:
                        {
                            try
                            {
                                // move to root.
                                if (String.IsNullOrEmpty(szString))
                                {
                                    m_browseStack.Clear();
                                    m_browseStack.Push(m_session.NodeCache.Find(Objects.Server));
                                    break;
                                }

                                // Translate the fully qualified area name to NodeId
                                List<string> szAreas = new List<string>();
                                szAreas.Add(szString);
                                BrowsePathResultCollection results = m_server.GetBrowseTargets(szAreas);
                                if (StatusCode.IsBad(results[0].StatusCode))
                                {
                                    throw ComUtils.CreateComException(ResultIds.E_INVALIDBRANCHNAME);
                                }

                                BrowsePathTarget target = results[0].Targets[0];
                                INode node = m_session.NodeCache.Find(target.TargetId);
                                if (node == null)
                                {
                                    throw ComUtils.CreateComException(ResultIds.E_INVALIDBRANCHNAME);
                                }

                                // build a new browse stack.
                                Stack<INode> browseStack = new Stack<INode>();

                                if (!FindPathToNode(node, browseStack))
                                {
                                    throw ComUtils.CreateComException(ResultIds.E_INVALIDBRANCHNAME);
                                }

                                // push target node onto stack.
                                browseStack.Push(node);

                                m_browseStack = browseStack;
                            }
                            catch
                            {
                                throw ComUtils.CreateComException(ResultIds.E_INVALIDBRANCHNAME);
                            }
                            break;
                        }

                        // move to a child branch.
                    case OPCAEBROWSEDIRECTION.OPCAE_BROWSE_DOWN:
                        {
                            // check for invalid name.
                            if (String.IsNullOrEmpty(szString))
                            {
                                throw ComUtils.CreateComException(ResultIds.E_INVALIDBRANCHNAME);
                            }

                            // find the current node.
                            INode parent = m_browseStack.Peek();

                            if (parent == null)
                            {
                                throw ComUtils.CreateComException(ResultIds.E_FAIL);
                            }

                            // find the child.
                            INode child = FindChildByName(parent.NodeId, szString);
                            
                            if (child == null)
                            {
                                throw ComUtils.CreateComException(ResultIds.E_INVALIDBRANCHNAME);
                            }
                            // save the new position.
                            m_browseStack.Push(child);
                            break;
                        }

                        // move to a parent branch.
                    case OPCAEBROWSEDIRECTION.OPCAE_BROWSE_UP:
                        {
                            // check for invalid name.
                            if (!String.IsNullOrEmpty(szString))
                            {
                                throw ComUtils.CreateComException(ResultIds.E_FAIL);
                            }

                            // can't move up from root.
                            if (m_browseStack.Count <= 1)
                            {
                                throw ComUtils.CreateComException(ResultIds.E_FAIL);
                            }

                            // move up the stack.
                            m_browseStack.Pop();
                            break;
                        }

                        default:
                        {
                            throw ComUtils.CreateComException(ResultIds.E_INVALIDARG);
                        }
                    }
                }
                catch (COMException e)
                {
                    throw ComUtils.CreateComException(e);
                }
                catch (Exception e)
				{
                    Utils.Trace(e, "Unexpected error in ChangeBrowsePosition");
					throw ComUtils.CreateComException(e);
				}
            }
        }
예제 #3
0
        /// <summary>
        /// Provides a way to move �up� or �down� in a hierarchical space from the current position, or a way to move to a specific position in the area space tree. The target szString must represent an area, rather than a source.
        /// </summary>
        /// <param name="dwBrowseDirection">OPCAE_BROWSE_UP, OPCAE_BROWSE_DOWN, or OPCAE_BROWSE_TO</param>
        /// <param name="szString">
        /// For DOWN, the partial area name of the area to move into. This would be one of the strings returned from BrowseOPCAreas.
        /// For UP this parameter is ignored and should point to a NULL string.
        /// For BROWSE_TO, the fully qualified area name (as obtained from GetQualifiedAreaName method) or a pointer to a NUL string to go to the root.
        /// </param>
        public void ChangeBrowsePosition(OPCAEBROWSEDIRECTION dwBrowseDirection, string szString)
        {
            lock (m_lock)
            {
                try
                {
                    switch (dwBrowseDirection)
                    {
                    // move to a specified position or root.
                    case OPCAEBROWSEDIRECTION.OPCAE_BROWSE_TO:
                    {
                        try
                        {
                            // move to root.
                            if (String.IsNullOrEmpty(szString))
                            {
                                m_browseStack.Clear();
                                m_browseStack.Push(m_session.NodeCache.Find(Objects.Server));
                                break;
                            }

                            // Translate the fully qualified area name to NodeId
                            List <string> szAreas = new List <string>();
                            szAreas.Add(szString);
                            BrowsePathResultCollection results = m_server.GetBrowseTargets(szAreas);
                            if (StatusCode.IsBad(results[0].StatusCode))
                            {
                                throw ComUtils.CreateComException(ResultIds.E_INVALIDBRANCHNAME);
                            }

                            BrowsePathTarget target = results[0].Targets[0];
                            INode            node   = m_session.NodeCache.Find(target.TargetId);
                            if (node == null)
                            {
                                throw ComUtils.CreateComException(ResultIds.E_INVALIDBRANCHNAME);
                            }

                            // build a new browse stack.
                            Stack <INode> browseStack = new Stack <INode>();

                            if (!FindPathToNode(node, browseStack))
                            {
                                throw ComUtils.CreateComException(ResultIds.E_INVALIDBRANCHNAME);
                            }

                            // push target node onto stack.
                            browseStack.Push(node);

                            m_browseStack = browseStack;
                        }
                        catch
                        {
                            throw ComUtils.CreateComException(ResultIds.E_INVALIDBRANCHNAME);
                        }
                        break;
                    }

                    // move to a child branch.
                    case OPCAEBROWSEDIRECTION.OPCAE_BROWSE_DOWN:
                    {
                        // check for invalid name.
                        if (String.IsNullOrEmpty(szString))
                        {
                            throw ComUtils.CreateComException(ResultIds.E_INVALIDBRANCHNAME);
                        }

                        // find the current node.
                        INode parent = m_browseStack.Peek();

                        if (parent == null)
                        {
                            throw ComUtils.CreateComException(ResultIds.E_FAIL);
                        }

                        // find the child.
                        INode child = FindChildByName(parent.NodeId, szString);

                        if (child == null)
                        {
                            throw ComUtils.CreateComException(ResultIds.E_INVALIDBRANCHNAME);
                        }
                        // save the new position.
                        m_browseStack.Push(child);
                        break;
                    }

                    // move to a parent branch.
                    case OPCAEBROWSEDIRECTION.OPCAE_BROWSE_UP:
                    {
                        // check for invalid name.
                        if (!String.IsNullOrEmpty(szString))
                        {
                            throw ComUtils.CreateComException(ResultIds.E_FAIL);
                        }

                        // can't move up from root.
                        if (m_browseStack.Count <= 1)
                        {
                            throw ComUtils.CreateComException(ResultIds.E_FAIL);
                        }

                        // move up the stack.
                        m_browseStack.Pop();
                        break;
                    }

                    default:
                    {
                        throw ComUtils.CreateComException(ResultIds.E_INVALIDARG);
                    }
                    }
                }
                catch (COMException e)
                {
                    throw ComUtils.CreateComException(e);
                }
                catch (Exception e)
                {
                    Utils.Trace(e, "Unexpected error in ChangeBrowsePosition");
                    throw ComUtils.CreateComException(e);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Changes the browse position.
        /// </summary>
        /// <param name="direction">The direction.</param>
        /// <param name="qualifiedName">The qualified area name.</param>
        private bool ChangeBrowsePosition(OPCAEBROWSEDIRECTION direction, string qualifiedName)
        {
            string methodName = "IOPCEventAreaBrowser.CreateAreaBrowser";

            try
            {
                IOPCEventAreaBrowser server = BeginComCall<IOPCEventAreaBrowser>(methodName, true);
                server.ChangeBrowsePosition(direction, qualifiedName);
                return true;
            }
            catch (Exception e)
            {
                if (ComUtils.IsUnknownError(e, ResultIds.E_FAIL))
                {
                    ComCallError(methodName, e);
                }

                return false;
            }
            finally
            {
                EndComCall(methodName);
            }
        }