public IList<string> BrowseForNames(
Session session,
string itemId,
BrowseElementFilter elementFilter,
string nameFilter,
short dataTypeFilter,
int accessRightsFilter)
{
TraceState("BrowseForNames", itemId, elementFilter, nameFilter, dataTypeFilter, accessRightsFilter);
// look up the parent.
BrowseElement parent = Lookup(session, itemId);
if (parent == null)
{
return null;
}
// fetch the children.
List<BrowseElement> children = LookupChildElements(session, parent);
// search the children.
List<string> hits = new List<string>();
for (int ii = 0; ii < children.Count; ii++)
{
BrowseElement child = children[ii];
// apply the name filter.
if (!String.IsNullOrEmpty(nameFilter))
{
if (!ComUtils.Match(child.BrowseName, nameFilter, false))
{
continue;
}
}
// branches must have children.
if (elementFilter == BrowseElementFilter.Branch)
{
if (child.NodeClass == NodeClass.Variable && child.ReferencesByName.Count == 0)
{
continue;
}
}
// items must be variables.
if (elementFilter == BrowseElementFilter.Item)
{
if (child.NodeClass != NodeClass.Variable)
{
continue;
}
}
if (child.NodeClass == NodeClass.Variable)
{
// apply data type filter.
if (dataTypeFilter != 0)
{
if (child.CanonicalDataType != dataTypeFilter)
{
continue;
}
}
// apply access rights filter.
if (accessRightsFilter != 0)
{
if ((child.AccessRights & accessRightsFilter) == 0)
{
continue;
}
}
}
// a match.
hits.Add(child.BrowseName);
}
// return all of the matching names.
return hits;
}