Specifies the parameters used to create a DA group item.
Inheritance: IFormattable
        /// <summary>
        /// Moves the current browse position down.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="targetName">Name of the target.</param>
        public void BrowseDown(Session session, string targetName)
        {
            TraceState("BrowseDown", targetName);

            // find the id of the current element.
            string itemId = null;

            lock (m_lock)
            {
                if (m_browsePosition != null)
                {
                    itemId = m_browsePosition.ItemId;
                }
            }

            // try to fetch the child.
            ComDaBrowseElement child = m_cache.FindChild(session, itemId, targetName);

            if (child != null)
            {
                TraceState("child", child.ItemId, child.BrowseName, child.IsItem, child.HasChildren);
            }

            if (child == null || (!child.HasChildren && child.IsItem))
            {
                throw ComUtils.CreateComException(ResultIds.E_INVALIDARG);
            }

            // update the browse position.
            lock (m_lock)
            {
                m_browsePosition = child;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Recursively browses for items.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="parent">The parent.</param>
        /// <param name="hits">The hits.</param>
        private void BrowseForItems(Session session, ComDaBrowseElement parent, List <ComDaBrowseElement> hits)
        {
            string itemId            = String.Empty;
            string continuationPoint = null;

            if (parent != null)
            {
                itemId = parent.ItemId;
            }

            IList <ComDaBrowseElement> elements = m_browseManager.BrowseForElements(
                session,
                itemId,
                null,
                0,
                (int)BrowseElementFilter.All,
                null,
                out continuationPoint);

            for (int ii = 0; ii < elements.Count; ii++)
            {
                ComDaBrowseElement element = elements[ii];

                if (element.IsHistoricalItem)
                {
                    hits.Add(element);
                }

                if (element.HasChildren)
                {
                    BrowseForItems(session, element, hits);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Browses the current branch.
        /// </summary>
        /// <param name="browseType">Type of the browse.</param>
        /// <returns>
        /// The list of names that meet the criteria.
        /// </returns>
        public IList <string> Browse(int browseType)
        {
            Session session = m_server.Session;

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

            string itemId            = String.Empty;
            string continuationPoint = null;

            ComDaBrowseElement position = m_browseManager.GetBrowsePosition(session);

            if (position != null)
            {
                itemId = position.ItemId;
            }

            IList <ComDaBrowseElement> elements = m_browseManager.BrowseForElements(
                session,
                itemId,
                null,
                0,
                (int)BrowseElementFilter.All,
                null,
                out continuationPoint);

            return(ApplyFilters(elements, browseType));
        }
        /// <summary>
        /// Browses up.
        /// </summary>
        /// <param name="session">The session.</param>
        public void BrowseUp(Session session)
        {
            TraceState("BrowseUp");

            // find the id of the current node.
            string itemId = null;

            lock (m_lock)
            {
                // check if already at root.
                if (m_browsePosition == null || String.IsNullOrEmpty(m_browsePosition.ItemId))
                {
                    throw ComUtils.CreateComException(ResultIds.E_FAIL);
                }

                itemId = m_browsePosition.ItemId;
            }

            // find the parent - revert to root if parent does not exist.
            ComDaBrowseElement parent = m_cache.FindParent(session, itemId);

            lock (m_lock)
            {
                m_browsePosition = parent;
            }
        }
        /// <summary>
        /// Gets the item id for the specified browse element.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="browseName">The name of the browse element.</param>
        /// <returns>Null if the browseName is not valid for the current position.</returns>
        public string GetItemId(Session session, string browseName)
        {
            TraceState("GetItemId", browseName);

            // find the id of the current element.
            string itemId = null;

            lock (m_lock)
            {
                if (m_browsePosition != null)
                {
                    itemId = m_browsePosition.ItemId;
                }
            }

            // return the current element.
            if (String.IsNullOrEmpty(browseName))
            {
                return(itemId);
            }

            // try to fetch the child.
            ComDaBrowseElement child = m_cache.FindChild(session, itemId, browseName);

            if (child == null)
            {
                throw ComUtils.CreateComException(ResultIds.E_INVALIDARG);
            }

            // return child id.
            return(child.ItemId);
        }
Esempio n. 6
0
        /// <summary>
        /// Applies the filters to the list of names.
        /// </summary>
        /// <param name="elements">The elements.</param>
        /// <param name="browseType">Type of the browse.</param>
        /// <returns></returns>
        private IList <string> ApplyFilters(IList <ComDaBrowseElement> elements, int browseType)
        {
            List <string> names = new List <string>();

            for (int ii = 0; ii < elements.Count; ii++)
            {
                ComDaBrowseElement element = elements[ii];

                if (browseType == (int)OPCHDA_BROWSETYPE.OPCHDA_BRANCH)
                {
                    if (!element.HasChildren)
                    {
                        continue;
                    }
                }

                if (browseType == (int)OPCHDA_BROWSETYPE.OPCHDA_LEAF)
                {
                    if (!element.IsHistoricalItem || element.HasChildren)
                    {
                        continue;
                    }
                }

                if (browseType == (int)OPCHDA_BROWSETYPE.OPCHDA_ITEMS)
                {
                    if (!element.IsHistoricalItem)
                    {
                        continue;
                    }
                }

                if (m_filters != null)
                {
                    for (int jj = 0; jj < m_filters.Count; jj++)
                    {
                        if (!MatchFilter(element.BrowseName, m_filters[jj]))
                        {
                            continue;
                        }
                    }
                }

                if (browseType == (int)OPCHDA_BROWSETYPE.OPCHDA_ITEMS || browseType == (int)OPCHDA_BROWSETYPE.OPCHDA_FLAT)
                {
                    names.Add(element.ItemId);
                }
                else
                {
                    names.Add(element.BrowseName);
                }
            }

            return(names);
        }
Esempio n. 7
0
        /// <summary>
        /// Browse for all items below the current branch.
        /// </summary>
        /// <returns>
        /// The list of item ids that meet the criteria.
        /// </returns>
        public IList <string> BrowseForItems()
        {
            Session session = m_server.Session;

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

            ComDaBrowseElement position = m_browseManager.GetBrowsePosition(session);

            List <ComDaBrowseElement> elements = new List <ComDaBrowseElement>();

            BrowseForItems(session, position, elements);

            return(ApplyFilters(elements, (int)OPCHDA_BROWSETYPE.OPCHDA_FLAT));
        }
        /// <summary>
        /// Moves the current browse position to the specified item.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="itemId">The item id.</param>
        public void BrowseTo(Session session, string itemId)
        {
            TraceState("BrowseTo", itemId);

            // try to fetch the target.
            ComDaBrowseElement target = m_cache.FindElement(session, itemId);

            if (target == null)
            {
                BrowseDown(session, itemId);
                return;
            }

            if (!target.HasChildren)
            {
                throw ComUtils.CreateComException(ResultIds.E_INVALIDARG);
            }

            // update the browse position.
            lock (m_lock)
            {
                m_browsePosition = target;
            }
        }
        /// <summary>
        /// Browses for the children of the specified item.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="itemId">The item id.</param>
        /// <param name="continuationPoint">The continuation point.</param>
        /// <param name="maxElementsReturned">The max elements returned.</param>
        /// <param name="elementFilter">The element filter.</param>
        /// <param name="nameFilter">The name filter.</param>
        /// <param name="revisedContinuationPoint">The revised continuation point.</param>
        /// <returns>The list of elements that meet the criteria.</returns>
        public List <ComDaBrowseElement> BrowseForElements(
            Session session,
            string itemId,
            string continuationPoint,
            int maxElementsReturned,
            int elementFilter,
            string nameFilter,
            out string revisedContinuationPoint)
        {
            TraceState("BrowseForElements", itemId, continuationPoint, maxElementsReturned, elementFilter, nameFilter);

            revisedContinuationPoint = String.Empty;

            // look up continuation point.
            ContinuationPoint cp = null;

            if (!String.IsNullOrEmpty(continuationPoint))
            {
                if (!m_continuationPoints.TryGetValue(continuationPoint, out cp))
                {
                    throw ComUtils.CreateComException(ResultIds.E_INVALIDCONTINUATIONPOINT);
                }

                m_continuationPoints.Remove(continuationPoint);
            }

            // get the element queue.
            Queue <ComDaBrowseElement> elements = null;

            // get element from continuation point.
            if (cp != null)
            {
                elements = cp.Elements;
            }

            // get list from cache.
            else
            {
                elements = m_cache.BrowseForElements(session, itemId);

                // check if nothing found.
                if (elements == null)
                {
                    throw ComUtils.CreateComException(ResultIds.E_UNKNOWNITEMID);
                }
            }

            // apply filters.
            List <ComDaBrowseElement> hits = new List <ComDaBrowseElement>();

            while (elements.Count > 0)
            {
                ComDaBrowseElement hit = elements.Dequeue();

                // apply name filter.
                if (!String.IsNullOrEmpty(nameFilter))
                {
                    if (!ComUtils.Match(hit.BrowseName, nameFilter, true))
                    {
                        continue;
                    }
                }

                // apply element filter
                if (elementFilter == (int)OpcRcw.Da.OPCBROWSEFILTER.OPC_BROWSE_FILTER_BRANCHES)
                {
                    if (!hit.HasChildren)
                    {
                        continue;
                    }
                }

                if (elementFilter == (int)OpcRcw.Da.OPCBROWSEFILTER.OPC_BROWSE_FILTER_ITEMS)
                {
                    if (!hit.IsItem)
                    {
                        continue;
                    }
                }

                // check max reached.
                if (maxElementsReturned > 0 && hits.Count == maxElementsReturned)
                {
                    elements.Enqueue(hit);

                    cp          = new ContinuationPoint();
                    cp.Id       = Guid.NewGuid().ToString();
                    cp.Elements = elements;

                    m_continuationPoints.Add(cp.Id, cp);
                    revisedContinuationPoint = cp.Id;
                    break;
                }

                // add the result.
                hits.Add(hit);
            }

            // return results.
            return(hits);
        }
Esempio n. 10
0
        /// <summary>
        /// Recursively browses for items.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="parent">The parent.</param>
        /// <param name="hits">The hits.</param>
        private void BrowseForItems(Session session, ComDaBrowseElement parent, List<ComDaBrowseElement> hits)
        {
            string itemId = String.Empty;
            string continuationPoint = null;

            if (parent != null)
            {
                itemId = parent.ItemId;
            }

            IList<ComDaBrowseElement> elements = m_browseManager.BrowseForElements(
                session,
                itemId,
                null,
                0,
                (int)BrowseElementFilter.All,
                null,
                out continuationPoint);

            for (int ii = 0; ii < elements.Count; ii++)
            {
                ComDaBrowseElement element = elements[ii];

                if (element.IsHistoricalItem)
                {
                    hits.Add(element);
                }

                if (element.HasChildren)
                {
                    BrowseForItems(session, element, hits);
                }
            }
        }