UA Bundle SDK .NET  2.2.1.258
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Groups Pages
Browse/Translate – Browse

Prerequisites

A session with the server must be established.

Description

The following dialog shows an example implementation of the Browse service, which can be used to read references from a node. Press the button “Show Code” to display the corresponding code, and the button “Help” to show this documentation page.

First, you have to specify some parameters to filter your results. Klick on the button “...” right of the field “Node ID” to open an adress space browser, select the desired node and confirm with “OK”. Now, the NodeId is shown at the corresponding field.

Pick a browse direction from the drop down menu.

On pressing the button “...” right of the field “Reference Type”, a browse window opens. This allows you to further restrain the results. Check the box in front of “Include Subtypes” to return subtypes of the reference type as well.

By specifiying “Max References” you can limit the maximum number of references in a single response. If specified, a continuation point is set and the method BrowseNext is called repeatedly until all references are returned. Select “0” to get all references in a single response.

After pressing the button “Browse” the reference types matching your request are shown in the table at “Browse Response”. Check the box in front of “Use Asynchronous Pattern” to call “BeginBrowse” instead of “Browse”.

Sample Code

The follwing code reads the references from a node matching the specified criteria.

try
{
// get the current session from the parent form.
Session session = m_parent.Session;
// nothing to do if no session.
if (session == null)
{
return;
}
// clear the existing references.
ReferencesLV.Items.Clear();
// set up the browse filters.
BrowseContext context = new BrowseContext();
context.BrowseDirection = (BrowseDirection)BrowseDirectionCB.SelectedItem;
context.ReferenceTypeId = (NodeId)ReferenceTypeTB.Tag;
context.IncludeSubtypes = IncludeSubtypesCK.Checked;
context.MaxReferencesToReturn = (uint)MaxReferencesUD.Value;
m_continueAutomatically = context.MaxReferencesToReturn <= 0;
// parse the node id.
NodeId nodeId = NodeId.Parse(NodeIdTB.Text);
// this is a blocking call so show the wait cursor.
Cursor = Cursors.WaitCursor;
byte[] continuationPoint = null;
// browse the references (setting a 10 second timeout).
List<ReferenceDescription> references = session.Browse(
nodeId,
context,
new RequestSettings() { OperationTimeout = 10000 },
out continuationPoint);
// add references to control.
foreach (ReferenceDescription reference in references)
{
AddReference(session, reference);
}
// process any continuation points.
while (!ByteString.IsNull(continuationPoint))
{
if (!m_continueAutomatically)
{
session.ReleaseBrowseContinuationPoint(continuationPoint);
break;
}
references = session.BrowseNext(new RequestSettings() { OperationTimeout = 10000 }, ref continuationPoint);
foreach (ReferenceDescription reference in references)
{
AddReference(session, reference);
}
}
// adjust the column widths.
foreach (ColumnHeader column in ReferencesLV.Columns)
{
column.Width = -2;
}
}
catch (Exception exception)
{
ExceptionDlg.Show(this.Text, exception);
}