//====================================================================== // 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 TsCHdaBrowseElement[] BrowseNext(int maxElements, ref IOpcBrowsePosition position) { // check arguments. if (position == null || position.GetType() != typeof(BrowsePosition)) { throw new ArgumentException("Not a valid browse position object.", nameof(position)); } // interpret invalid values as 'no limit'. if (maxElements <= 0) { maxElements = Int32.MaxValue; } lock (this) { BrowsePosition pos = (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((TsCHdaBrowseElement[])elements.ToArray(typeof(TsCHdaBrowseElement))); } // 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 Utilities.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((TsCHdaBrowseElement[])elements.ToArray(typeof(TsCHdaBrowseElement))); } // release position object. position.Dispose(); position = null; // return elements. return((TsCHdaBrowseElement[])elements.ToArray(typeof(TsCHdaBrowseElement))); } }
/// <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 TsCHdaBrowseElement[] Browse(OpcItem itemID, int maxElements, out IOpcBrowsePosition 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 Utilities.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((TsCHdaBrowseElement[])elements.ToArray(typeof(TsCHdaBrowseElement))); } // 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((TsCHdaBrowseElement[])elements.ToArray(typeof(TsCHdaBrowseElement))); } // release enumerator. enumerator.Dispose(); return((TsCHdaBrowseElement[])elements.ToArray(typeof(TsCHdaBrowseElement))); } }