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;
}