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))); } }
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))); } }
//====================================================================== // 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))); } }