public void Update(
ISystemContext context,
SimpleAttributeOperandCollection fields,
EventFieldList e)
{
for (int ii = 0; ii < fields.Count; ii++)
{
SimpleAttributeOperand field = fields[ii];
object value = e.EventFields[ii].Value;
// check if value provided.
if (value == null)
{
continue;
}
// extract the NodeId for the event.
if (field.BrowsePath.Count == 0)
{
if (field.AttributeId == Attributes.NodeId)
{
this.NodeId = value as NodeId;
continue;
}
}
// extract the type definition for the event.
if (field.BrowsePath.Count == 1)
{
if (field.AttributeId == Attributes.Value)
{
if (field.BrowsePath[0] == BrowseNames.EventType)
{
m_typeDefinitionId = value as NodeId;
continue;
}
}
}
// save value for child node.
NodeState parent = this;
for (int jj = 0; jj < field.BrowsePath.Count; jj++)
{
// find a predefined child identified by the browse name.
BaseInstanceState child = parent.CreateChild(context, field.BrowsePath[jj]);
// create a placeholder for unknown children.
if (child == null)
{
if (field.AttributeId == Attributes.Value)
{
child = new BaseDataVariableState(parent);
}
else
{
child = new BaseObjectState(parent);
}
parent.AddChild(child);
}
// ensure the browse name is set.
if (QualifiedName.IsNull(child.BrowseName))
{
child.BrowseName = field.BrowsePath[jj];
}
// ensure the display name is set.
if (LocalizedText.IsNullOrEmpty(child.DisplayName))
{
child.DisplayName = child.BrowseName.Name;
}
// process next element in path.
if (jj < field.BrowsePath.Count-1)
{
parent = child;
continue;
}
// save the variable value.
if (field.AttributeId == Attributes.Value)
{
BaseVariableState variable = child as BaseVariableState;
if (variable != null && field.AttributeId == Attributes.Value)
{
try
{
variable.WrappedValue = e.EventFields[ii];
}
catch (Exception)
{
variable.Value = null;
}
}
break;
}
// save the node id.
child.NodeId = value as NodeId;
}
}
}