Exemple #1
0
 public BrowseElement[] BrowseNext(int maxElements, ref IBrowsePosition position)
 {
     if ((position == null) || (position.GetType() != typeof(OpcCom.Hda.BrowsePosition)))
     {
         throw new ArgumentException("Not a valid browse position object.", "position");
     }
     if (maxElements <= 0)
     {
         maxElements = 0x7fffffff;
     }
     lock (this)
     {
         OpcCom.Hda.BrowsePosition position2 = (OpcCom.Hda.BrowsePosition)position;
         ArrayList list = new ArrayList();
         if (!position2.FetchingItems)
         {
             list = this.FetchElements(position2.Enumerator, maxElements, true);
             if (list.Count >= maxElements)
             {
                 return((BrowseElement[])list.ToArray(typeof(BrowseElement)));
             }
             position2.Enumerator.Dispose();
             position2.Enumerator    = null;
             position2.FetchingItems = true;
             try
             {
                 this.m_browser.ChangeBrowsePosition(OPCHDA_BROWSEDIRECTION.OPCHDA_BROWSE_DIRECT, position2.BranchPath);
             }
             catch (Exception exception)
             {
                 throw OpcCom.Interop.CreateException("IOPCHDA_Browser.ChangeBrowsePosition", exception);
             }
             position2.Enumerator = this.GetEnumerator(false);
         }
         ArrayList c = this.FetchElements(position2.Enumerator, maxElements - list.Count, false);
         if (c != null)
         {
             list.AddRange(c);
         }
         if (list.Count < maxElements)
         {
             position.Dispose();
             position = null;
         }
         return((BrowseElement[])list.ToArray(typeof(BrowseElement)));
     }
 }
Exemple #2
0
 public BrowseElement[] Browse(ItemIdentifier itemID, int maxElements, out IBrowsePosition position)
 {
     position = null;
     if (maxElements <= 0)
     {
         maxElements = 0x7fffffff;
     }
     lock (this)
     {
         string szString = ((itemID != null) && (itemID.ItemName != null)) ? itemID.ItemName : "";
         try
         {
             this.m_browser.ChangeBrowsePosition(OPCHDA_BROWSEDIRECTION.OPCHDA_BROWSE_DIRECT, szString);
         }
         catch (Exception exception)
         {
             throw OpcCom.Interop.CreateException("IOPCHDA_Browser.ChangeBrowsePosition", exception);
         }
         EnumString enumerator = this.GetEnumerator(true);
         ArrayList  list       = this.FetchElements(enumerator, maxElements, true);
         if (list.Count >= maxElements)
         {
             position = new OpcCom.Hda.BrowsePosition(szString, enumerator, false);
             return((BrowseElement[])list.ToArray(typeof(BrowseElement)));
         }
         enumerator.Dispose();
         enumerator = this.GetEnumerator(false);
         ArrayList c = this.FetchElements(enumerator, maxElements - list.Count, false);
         if (c != null)
         {
             list.AddRange(c);
         }
         if (list.Count >= maxElements)
         {
             position = new OpcCom.Hda.BrowsePosition(szString, enumerator, true);
             return((BrowseElement[])list.ToArray(typeof(BrowseElement)));
         }
         enumerator.Dispose();
         return((BrowseElement[])list.ToArray(typeof(BrowseElement)));
     }
 }
        //======================================================================
        // BrowseNext

        /// <summary>
        /// Continues browsing the server's address space at the specified position.
        /// </summary>
        /// <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[] BrowseNext(int maxElements, ref IBrowsePosition position)
        {
            // check arguments.
            if (position == null || position.GetType() != typeof(OpcCom.Hda.BrowsePosition))
            {
                throw new ArgumentException("Not a valid browse position object.", "position");
            }

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

            lock (this)
            {
                OpcCom.Hda.BrowsePosition pos = (OpcCom.Hda.BrowsePosition)position;

                ArrayList elements = new ArrayList();

                if (!pos.FetchingItems)
                {
                    elements = FetchElements(pos.Enumerator, maxElements, true);

                    // check if max element count reached.
                    if (elements.Count >= maxElements)
                    {
                        return((BrowseElement[])elements.ToArray(typeof(BrowseElement)));
                    }

                    // release enumerator.
                    pos.Enumerator.Dispose();

                    pos.Enumerator    = null;
                    pos.FetchingItems = true;

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

                    // create enumerator for items.
                    pos.Enumerator = GetEnumerator(false);
                }

                // fetch next set of items.
                ArrayList items = FetchElements(pos.Enumerator, maxElements - elements.Count, false);

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

                // check if max element count reached.
                if (elements.Count >= maxElements)
                {
                    return((BrowseElement[])elements.ToArray(typeof(BrowseElement)));
                }

                // release position object.
                position.Dispose();
                position = null;

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