Exemplo n.º 1
0
        public BrowseElement[] BrowseNext(int maxElements, ref IBrowsePosition position)
        {
            if (position == null || (object)position.GetType() != typeof(BrowsePosition))
            {
                throw new ArgumentException("Not a valid browse position object.", "position");
            }

            if (maxElements <= 0)
            {
                maxElements = int.MaxValue;
            }

            lock (this)
            {
                BrowsePosition browsePosition = (BrowsePosition)position;
                ArrayList      arrayList      = new ArrayList();
                if (!browsePosition.FetchingItems)
                {
                    arrayList = FetchElements(browsePosition.Enumerator, maxElements, isBranch: true);
                    if (arrayList.Count >= maxElements)
                    {
                        return((BrowseElement[])arrayList.ToArray(typeof(BrowseElement)));
                    }

                    browsePosition.Enumerator.Dispose();
                    browsePosition.Enumerator    = null;
                    browsePosition.FetchingItems = true;
                    try
                    {
                        m_browser.ChangeBrowsePosition(OPCHDA_BROWSEDIRECTION.OPCHDA_BROWSE_DIRECT, browsePosition.BranchPath);
                    }
                    catch (Exception e)
                    {
                        throw OpcCom.Interop.CreateException("IOPCHDA_Browser.ChangeBrowsePosition", e);
                    }

                    browsePosition.Enumerator = GetEnumerator(isBranch: false);
                }

                ArrayList arrayList2 = FetchElements(browsePosition.Enumerator, maxElements - arrayList.Count, isBranch: false);
                if (arrayList2 != null)
                {
                    arrayList.AddRange(arrayList2);
                }

                if (arrayList.Count >= maxElements)
                {
                    return((BrowseElement[])arrayList.ToArray(typeof(BrowseElement)));
                }

                position.Dispose();
                position = null;
                return((BrowseElement[])arrayList.ToArray(typeof(BrowseElement)));
            }
        }
Exemplo n.º 2
0
        public BrowseElement[] Browse(ItemIdentifier itemID, int maxElements, out IBrowsePosition position)
        {
            position = null;
            if (maxElements <= 0)
            {
                maxElements = int.MaxValue;
            }

            lock (this)
            {
                string text = (itemID != null && itemID.ItemName != null) ? itemID.ItemName : "";
                try
                {
                    m_browser.ChangeBrowsePosition(OPCHDA_BROWSEDIRECTION.OPCHDA_BROWSE_DIRECT, text);
                }
                catch (Exception e)
                {
                    throw OpcCom.Interop.CreateException("IOPCHDA_Browser.ChangeBrowsePosition", e);
                }

                EnumString enumerator = GetEnumerator(isBranch: true);
                ArrayList  arrayList  = FetchElements(enumerator, maxElements, isBranch: true);
                if (arrayList.Count >= maxElements)
                {
                    position = new BrowsePosition(text, enumerator, fetchingItems: false);
                    return((BrowseElement[])arrayList.ToArray(typeof(BrowseElement)));
                }

                enumerator.Dispose();
                enumerator = GetEnumerator(isBranch: false);
                ArrayList arrayList2 = FetchElements(enumerator, maxElements - arrayList.Count, isBranch: false);
                if (arrayList2 != null)
                {
                    arrayList.AddRange(arrayList2);
                }

                if (arrayList.Count >= maxElements)
                {
                    position = new BrowsePosition(text, enumerator, fetchingItems: true);
                    return((BrowseElement[])arrayList.ToArray(typeof(BrowseElement)));
                }

                enumerator.Dispose();
                return((BrowseElement[])arrayList.ToArray(typeof(BrowseElement)));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Begins a browsing the server's address space at the specified branch.
        /// </summary>
        /// <param name="itemID">The item id of the branch to search.</param>
        /// <param name="maxElements">The maximum number of elements to return.</param>
        /// <param name="position">The position object used to continue a browse operation.</param>
        /// <returns>The set of elements that meet the filter criteria.</returns>
        public BrowseElement[] Browse(ItemIdentifier itemID, int maxElements, out IBrowsePosition position)
        {
            position = null;

            // interpret invalid values as 'no limit'.
            if (maxElements <= 0)
            {
                maxElements = Int32.MaxValue;
            }

            lock (this)
            {
                string branchPath = (itemID != null && itemID.ItemName != null)?itemID.ItemName:"";

                // move to the correct position in the server's address space.
                try
                {
                    m_browser.ChangeBrowsePosition(OPCHDA_BROWSEDIRECTION.OPCHDA_BROWSE_DIRECT, branchPath);
                }
                catch (Exception e)
                {
                    throw OpcCom.Interop.CreateException("IOPCHDA_Browser.ChangeBrowsePosition", e);
                }

                // browse for branches
                EnumString enumerator = GetEnumerator(true);

                ArrayList elements = FetchElements(enumerator, maxElements, true);

                // check if max element count reached.
                if (elements.Count >= maxElements)
                {
                    position = new BrowsePosition(branchPath, enumerator, false);
                    return((BrowseElement[])elements.ToArray(typeof(BrowseElement)));
                }

                // release enumerator.
                enumerator.Dispose();

                // browse for items
                enumerator = GetEnumerator(false);

                ArrayList items = FetchElements(enumerator, maxElements - elements.Count, false);

                if (items != null)
                {
                    elements.AddRange(items);
                }

                // check if max element count reached.
                if (elements.Count >= maxElements)
                {
                    position = new BrowsePosition(branchPath, enumerator, true);
                    return((BrowseElement[])elements.ToArray(typeof(BrowseElement)));
                }

                // release enumerator.
                enumerator.Dispose();

                return((BrowseElement[])elements.ToArray(typeof(BrowseElement)));
            }
        }